- Pretty-indenting code

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@674 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-06-29 08:44:30 +00:00
parent 7aecc910ba
commit 6b27a8461b
94 changed files with 3073 additions and 3066 deletions

View file

@ -31,19 +31,19 @@ using namespace std;
// *strong* exception checking / handling!
PythonPolicy::PythonPolicy(const char* name)
: _upolicy_dict(NULL), _adapter(NULL), _name(name)
: _upolicy_dict(NULL), _adapter(NULL), _name(name)
{
PyObject* pLoadmeStr = PyString_FromString(name);
PyObject* pUserPolicyModule = PyImport_Import(pLoadmeStr);
Py_DECREF(pLoadmeStr);
if( !pUserPolicyModule )
if( !pUserPolicyModule )
{
PyErr_Print(); // Error in import
// FIXME : don't exit abruptly, but fall back gracefully
exit(-1);
}
// Dictionary with defined ``symbols'' for .pyc file
_upolicy_dict = PyModule_GetDict(pUserPolicyModule);
assert(_upolicy_dict);
@ -55,11 +55,11 @@ PythonPolicy::PythonPolicy(const char* name)
assert(pScriptAdapterModule);
PyObject* pAdapterDict = PyModule_GetDict(pScriptAdapterModule);
assert(pAdapterDict);
// Now takes the user-defined policy class from pUserPolicyDict
PyObject* pPolicyClass = PyDict_GetItemString(_upolicy_dict, name);
assert(pPolicyClass); // FIXME needs stricter checking and exception throwing
// Creates a new object of type ScriptAdapter :
// takes init function from ScriptAdapter class
PyObject* pAdapterClass = PyDict_GetItemString(pAdapterDict, "ScriptAdapter");
@ -80,10 +80,10 @@ PythonPolicy::~PythonPolicy()
{
if(_adapter) Py_DECREF(_adapter);
// We keep this alive until dtor time, because
// the user may have defined some static global-space
// variables and they make use of them.
if(_upolicy_dict) Py_DECREF(_upolicy_dict);
// We keep this alive until dtor time, because
// the user may have defined some static global-space
// variables and they make use of them.
if(_upolicy_dict) Py_DECREF(_upolicy_dict);
}
@ -102,19 +102,19 @@ PythonPolicy::sort_queue() const throw(UserInterruptException)
{
PyObject* pMethodName = PyString_FromString("async_sort_queue");
PyObject* retval = PyObject_CallMethodObjArgs(_adapter, pMethodName, NULL, NULL);
// Do minimal debugging
if(!retval) PyErr_Print();
else Py_DECREF(retval);
Py_DECREF(pMethodName);
wait_unlock();
}
Glib::ustring
PythonPolicy::get_description() const
PythonPolicy::get_description() const
{
return _name;
}
@ -127,13 +127,13 @@ PythonPolicy::get_name() const
}
bool
PythonPolicy::is_pre_emptive() const throw(UserInterruptException)
PythonPolicy::is_pre_emptive() const throw(UserInterruptException)
{
PyObject* retval = PyObject_CallMethod(_adapter, "async_is_preemptive", NULL);
Py_DECREF(retval);
wait_unlock();
// Parse return value stored in global Python object
retval = PyObject_CallMethod(_adapter, "get_return_value", NULL);
assert(retval);
@ -144,13 +144,13 @@ PythonPolicy::is_pre_emptive() const throw(UserInterruptException)
int
PythonPolicy::get_time_slice() const throw(UserInterruptException)
PythonPolicy::get_time_slice() const throw(UserInterruptException)
{
PyObject* retval = PyObject_CallMethod(_adapter, "async_get_time_slice", NULL);
Py_DECREF(retval);
wait_unlock();
// Parse return value stored in global Python object
retval = PyObject_CallMethod(_adapter, "get_return_value", NULL);
assert(retval);
@ -161,13 +161,13 @@ PythonPolicy::get_time_slice() const throw(UserInterruptException)
}
policy_sorts_type
PythonPolicy::wants() const throw(UserInterruptException)
PythonPolicy::wants() const throw(UserInterruptException)
{
PyObject* retval = PyObject_CallMethod(_adapter, "async_wants", NULL);
Py_DECREF(retval);
wait_unlock();
// Parse return value stored in global Python object
retval = PyObject_CallMethod(_adapter, "get_return_value", NULL);
assert(retval);
@ -181,39 +181,39 @@ PythonPolicy::wants() const throw(UserInterruptException)
else
return policy_sorts_processes;
}
void
PythonPolicy::wait_unlock() const throw(UserInterruptException)
{
PyThreadState* _save;
int i = 0; // We give the sort_queue() three seconds max time, then...
// we shot it stone dead! Bang.
// we shot it stone dead! Bang.
bool still_locked;
do
do
{
Py_UNBLOCK_THREADS;
usleep(WAIT_FOR); // hack'a'ton! magggggiccc nummmbeeerrrrrs!!
Py_BLOCK_THREADS;
PyObject* retval = PyObject_CallMethod(_adapter, "mutex_test_lock", NULL);
assert(retval);
still_locked = PyObject_IsTrue(retval);
Py_DECREF(retval);
if(i++ > 12) /* waits for WAIT_FOR * 12 microseconds == 3 secs */
{
PyThreadState_Clear(_save);
// As the API documentation says, the caller of PyEval_RestoreThread
// should NOT possess the interpreter lock
Py_UNBLOCK_THREADS;
usleep(WAIT_FOR); // hack'a'ton! magggggiccc nummmbeeerrrrrs!!
Py_BLOCK_THREADS;
PyObject* retval = PyObject_CallMethod(_adapter, "mutex_test_lock", NULL);
assert(retval);
still_locked = PyObject_IsTrue(retval);
Py_DECREF(retval);
PyEval_RestoreThread(_save);
if(i++ > 12) /* waits for WAIT_FOR * 12 microseconds == 3 secs */
{
PyThreadState_Clear(_save);
// As the API documentation says, the caller of PyEval_RestoreThread
// should NOT possess the interpreter lock
Py_UNBLOCK_THREADS;
PyEval_RestoreThread(_save);
throw UserInterruptException("User-defined policy is "
"taking too long to terminate.");
}
}
throw UserInterruptException("User-defined policy is "
"taking too long to terminate.");
}
}
while(still_locked);
// What we should really do here:
@ -226,9 +226,9 @@ PythonPolicy::wait_unlock() const throw(UserInterruptException)
...if he has, break
...else:
if the global lock is set:
stay in this loop
else:
all's went okay, can exit loop
stay in this loop
else:
all's went okay, can exit loop
} */
}