39 if (!c)
throw LogicException(
"Adding NULL command to a command list");
45 c->prev = lastCommand;
48 lastCommand->next = c;
62 for (
Command *i = lastCommand; i; )
81 for (
Command *i = lastCommand; i; i = i->prev)
89 for (
Command *i = firstCommand; i;)
106 for (
Command* c = firstCommand; c; c = c->next)
115 logger <<
"Warning: Deleting a command list with commands that have"
116 <<
" not been committed or rolled back" << endl;
130 lastBookmark->nextBookmark = n;
131 n->prevBookmark = lastBookmark;
143 for (; i && i != b; i = i->prevBookmark)
152 currentBookmark = b->parent;
160 for (
Bookmark* i = b; i; i = i->nextBookmark)
162 if (i->isChildOf(b) && !i->active)
176 if (b == &firstBookmark)
187 i->prevBookmark->nextBookmark = i->nextBookmark;
189 i->nextBookmark->prevBookmark = i->prevBookmark;
191 lastBookmark = i->prevBookmark;
193 if (currentBookmark == i)
210 if (firstBookmark.active) firstBookmark.
commit();
211 for (
Bookmark* i = firstBookmark.nextBookmark; i; )
213 if (i->active) i->commit();
218 firstBookmark.nextBookmark = NULL;
219 currentBookmark = &firstBookmark;
220 lastBookmark = &firstBookmark;
226 for (
Bookmark* i = lastBookmark; i != &firstBookmark;)
234 firstBookmark.nextBookmark = NULL;
235 currentBookmark = &firstBookmark;
236 lastBookmark = &firstBookmark;
253 if (maxParallel<=1 || countCallables<=1)
260 int numthreads = countCallables;
262 if (numthreads > maxParallel) numthreads = maxParallel;
264 #ifdef HAVE_PTHREAD_H
267 pthread_t threads[numthreads];
271 for (; worker<numthreads; ++worker)
273 if ((errcode=pthread_create(&threads[worker],
281 ch <<
"Can't create any threads, error " << errcode;
286 logger <<
"Warning: Could create only " << worker
287 <<
" threads, error " << errcode << endl;
292 for (--worker; worker>=0; --worker)
296 if ((errcode=pthread_join(threads[worker],NULL)))
299 ch <<
"Can't join with thread " << worker <<
", error " << errcode;
305 HANDLE* threads =
new HANDLE[numthreads];
306 unsigned int* m_id =
new unsigned int[numthreads];
309 for (; worker<numthreads; ++worker)
311 threads[worker] =
reinterpret_cast<HANDLE
>(
318 if (!threads[worker])
329 logger <<
"Warning: Could create only " << worker
330 <<
" threads, error " << errno << endl;
336 int res = WaitForMultipleObjects(worker, threads,
true, INFINITE);
337 if (res == WAIT_FAILED)
341 FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
354 for (--worker; worker>=0; --worker)
355 CloseHandle(threads[worker]);
358 #endif // End of #ifdef ifHAVE_PTHREAD_H
359 #endif // End of #ifndef MT
363 DECLARE_EXPORT ThreadGroup::callableWithArgument ThreadGroup::selectNextCallable()
366 if (callables.empty())
369 assert( countCallables == 0 );
370 return callableWithArgument(static_cast<callable>(NULL),static_cast<void*>(NULL));
372 callableWithArgument c = callables.top();
379 #if defined(HAVE_PTHREAD_H) || !defined(MT)
380 void* ThreadGroup::wrapper(
void *arg)
382 unsigned __stdcall ThreadGroup::wrapper(
void *arg)
386 ThreadGroup *l =
static_cast<ThreadGroup*
>(arg);
387 bool threaded = l->maxParallel > 1 && l->countCallables > 1;
390 for (callableWithArgument nextfunc = l->selectNextCallable();
392 nextfunc = l->selectNextCallable())
394 #if defined(HAVE_PTHREAD_H) && defined(MT)
396 pthread_testcancel();
398 try {nextfunc.first(nextfunc.second);}
402 logger <<
"Error: Caught an exception while executing command:" << endl;
404 catch (
const exception& e) {
logger <<
" " << e.what() << endl;}
405 catch (...) {
logger <<
" Unknown type" << endl;}
421 (PyObject*
self, PyObject* args, PyObject* kwds)
426 int ok = PyArg_ParseTuple(args,
"s:loadmodule", &data);
427 if (!ok)
return NULL;
433 PyObject *key, *value;
435 while (PyDict_Next(kwds, &pos, &key, &value))
442 Py_BEGIN_ALLOW_THREADS
455 return Py_BuildValue(
"");
461 logger <<
"Loaded modules:" << endl;
462 for (set<string>::const_iterator i=moduleRegistry.begin(); i!=moduleRegistry.end(); ++i)
463 logger <<
" " << *i << endl;