void freelock(Lock *l) { assert(l != nil); destroylock(l); free(l); }
/* * pthread_create takes its fn parameter as void *(*)(void*), so * Thread->fn itself cannot be passed to it. This has the proper signature * and wraps Thread->fn. It also initialises thread-local storage and * waits for the Thread structure to be completely filled out before * finally starting the thread's main procedure. */ static void* run(void *arg) { Thread *t; t = (Thread*)arg; dprintf("thread %p spawn\n", t); pthread_once(&tlsonce, construct); pthread_setspecific(tlskey, t); initrand(&t->r); lock(&t->runwait, 1); unlock(&t->runwait); destroylock(&t->runwait); dprintf("thread %p run\n", t); t->fn(t->arg); return nil; }
EventManager<T>::~EventManager() { if (mEventCV && mEventLock) { boost::mutex *lock = (boost::mutex *)mEventLock; boost::condition_variable *cv = (boost::condition_variable *)mEventCV; boost::mutex destroyMutex; boost::condition_variable destroyCV; { boost::unique_lock<boost::mutex> destroylock(destroyMutex); mEventCV = &destroyCV; mEventLock = &destroyMutex; { boost::unique_lock<boost::mutex> templock(*lock); mCleanup = true; cv->notify_one(); } destroyCV.wait(destroylock); } delete lock; delete cv; } typename PrimaryListenerMap::iterator iter; typename SecondaryListenerMap::iterator secIter; for (iter = mListeners.begin(); iter != mListeners.end(); ++iter) { SecondaryListenerMap *secMap = &((*iter).second->second); for (secIter = secMap->begin(); secIter != secMap->end(); ++secIter) { delete (*secIter).second; } delete (*iter).second; } mListeners.clear(); }