REGISTER_TESTS_END // LeakRegression //------------------------------------------------------------------------------ void TestSystemMutex::LeakRegression() const { const uint32_t testCount( 1024 * 20 ); // Create a unique name based on architecture/config to avoid // collisions when tests can run in parallel AStackString<> mutexName( "SysMutexName_" ); mutexName += (sizeof(void*) == 8) ? "64_" : "32_"; #if defined( DEBUG ) mutexName += "Debug"; #elif defined( RELEASE ) #if defined( PROFILING_ENABLED ) mutexName += "Profile"; #else mutexName += "Release"; #endif #endif SystemMutex m( mutexName.Get() ); for ( uint32_t i=0; i<testCount; ++i ) { TEST_ASSERT( m.TryLock() ); m.Unlock(); } }
CONDITION THR_ObtainMutex(int fac) { #ifdef CTN_USE_THREADS #ifdef _MSC_VER char name[32]; HANDLE hTmpMutex; mutexName(fac, name); hTmpMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, name); WaitForSingleObject(hMutex[fac], INFINITE); /* From JCS, close temp handle to get eliminate resource leak. */ CloseHandle(hTmpMutex); return THR_NORMAL; #else int cond; if (!initialized) { fprintf(stderr, "Threads not initialized in call to THR_ObtainMutex: exiting\n"); exit(1); } cond = mutex_lock(&mutex[fac]); if (cond != 0) { fprintf(stderr, "Failed on call to mutex_lock in THR_ObtainMutex\n"); return THR_GENERICFAILURE; } return THR_NORMAL; #endif #else return THR_NORMAL; #endif }
CodeCache::CodeCache(const std::string& path, bool shared): _path(path) { if (shared) _pMutex = new Poco::NamedMutex(mutexName(path)); _path.makeDirectory(); File dir(path); dir.createDirectories(); }
// _Init void RWLocker::_Init(const char* name) { // init the mutex benaphore BString mutexName(name); mutexName += "_RWLocker_mutex"; fMutex.semaphore = create_sem(0, mutexName.String()); fMutex.counter = 0; // init the queueing benaphore BString queueName(name); queueName += "_RWLocker_queue"; fQueue.semaphore = create_sem(0, queueName.String()); fQueue.counter = 0; }
CONDITION THR_Init() { #ifdef CTN_USE_THREADS #ifdef _MSC_VER int i; if (initialized) return THR_NORMAL; for (i = 0; i < (int) DIM_OF(hMutex); i++) { char name[32]; mutexName(i, name); hMutex[i] = CreateMutex(NULL, FALSE, name); } initialized = TRUE; return THR_NORMAL; #else int cond; int i; if (initialized) return; for (i = 0; i < (int) DIM_OF(mutex); i++) { cond = mutex_init(&mutex[i], USYNC_THREAD, NULL); if (cond != 0) { fprintf(stderr, "Fatal error in THR_Init; could not initialize mutex\n"); exit(1); } } initialized = TRUE; return THR_NORMAL; #endif #else return THR_NORMAL; #endif }