// lock or unlock the mutex inline status_t lock() { if (mLockThreadId != getThreadId()) { mLock.lock(); mLockThreadId = getThreadId(); mlocked = 0; } return mlocked++; }
LargeMemoryBlock *ExtMemoryPool::mallocLargeObject(size_t allocationSize) { #if __TBB_MALLOC_LOCACHE_STAT AtomicIncrement(mallocCalls); AtomicAdd(memAllocKB, allocationSize/1024); #endif LargeMemoryBlock* lmb = loc.get(allocationSize); if (!lmb) { BackRefIdx backRefIdx = BackRefIdx::newBackRef(/*largeObj=*/true); if (backRefIdx.isInvalid()) return NULL; // unalignedSize is set in getLargeBlock lmb = backend.getLargeBlock(allocationSize); if (!lmb) { removeBackRef(backRefIdx); loc.rollbackCacheState(allocationSize); return NULL; } lmb->backRefIdx = backRefIdx; STAT_increment(getThreadId(), ThreadCommonCounters, allocNewLargeObj); } else { #if __TBB_MALLOC_LOCACHE_STAT AtomicIncrement(cacheHits); AtomicAdd(memHitKB, allocationSize/1024); #endif } return lmb; }
status_t MediaPlayer::start() { ALOGV("start"); status_t ret = NO_ERROR; Mutex::Autolock _l(mLock); mLockThreadId = getThreadId(); if (mCurrentState & MEDIA_PLAYER_STARTED) { ret = NO_ERROR; } else if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_PLAYBACK_COMPLETE | MEDIA_PLAYER_PAUSED ) ) ) { mPlayer->setLooping(mLoop); mPlayer->setVolume(mLeftVolume, mRightVolume); mPlayer->setAuxEffectSendLevel(mSendLevel); mCurrentState = MEDIA_PLAYER_STARTED; ret = mPlayer->start(); if (ret != NO_ERROR) { mCurrentState = MEDIA_PLAYER_STATE_ERROR; } else { if (mCurrentState == MEDIA_PLAYER_PLAYBACK_COMPLETE) { ALOGV("playback completed immediately following start()"); } } } else { ALOGE("start called in state %d", mCurrentState); ret = INVALID_OPERATION; } mLockThreadId = 0; return ret; }
TLS_SOCKET_CLASS::~TLS_SOCKET_CLASS() // DESCRIPTION : Destructor. // PRECONDITIONS : // POSTCONDITIONS : // EXCEPTIONS : // NOTES : //<<=========================================================================== { // set this thread to the owner so the memory will get freed ownerThreadIdM = getThreadId(); // close the socket close(); // free any saved sessions if (savedClientSessionM_ptr != NULL) { SSL_SESSION_free(savedClientSessionM_ptr); } // free the CTX if (ctxM_ptr != NULL) { if (ctxM_ptr->references == 1) { // the ctx structure will be freed, delete the password memory delete [] (char*)ctxM_ptr->default_passwd_callback_userdata; } SSL_CTX_free(ctxM_ptr); // this will decrement the reference count and delete the structure if 0 } }
//============================================================================= // METHOD: SPELLipcIncomingRequest:run //============================================================================= void SPELLipcIncomingRequest::run() { std::string senderId = m_message->getSender(); std::string receiverId = m_message->getReceiver(); // If the request has been canceled beforehand if (m_cancel) return; SPELLipcMessage* response = m_listener->processRequest(m_message); if (response && !m_cancel) { response->setSender(receiverId); response->setReceiver(senderId); // Do not set sequence number if it is already set. // This happens when forwarding requests. if (response->getSequence() == -1) { response->setSequence( m_message->getSequence() ); } try { if (m_interface->isConnected()) { SPELLipcOutput& writer = m_interface->getWriter(m_message->getKey()); writer.send(response); m_interface->endRequest( getThreadId() ); } } catch(...) {}; delete response; } finish(); delete m_message; }
//----------------------------------------------------------------------------------------- // Constructors //----------------------------------------------------------------------------------------- ClientThread::ClientThread(SocketClient* client, int threadId, float interval) { setThreadId(threadId); socketClient = client; flag = false; timer = new FdTimer(getThreadId(), interval); }
void HooksUpdateDetector::execute() { m_log->info(_T("Hooks update detector thread id = %d"), getThreadId()); if (!isTerminating() && m_targetWin != 0) { m_targetWin->createWindow(); m_log->info(_T("Hooks target window has been created (hwnd = %d)"), m_targetWin->getHWND()); } try { UipiControl uipiControl(m_log); uipiControl.allowMessage(HookDefinitions::SPEC_IPC_CODE, m_targetWin->getHWND()); } catch (Exception &e) { terminate(); m_log->error(e.getMessage()); } bool hookInstalled = false; while (!isTerminating() && !hookInstalled) { try { m_hookInstaller->install(m_targetWin->getHWND()); hookInstalled = true; } catch (Exception &e) { m_log->error(_T("Hooks installing failed, wait for the next trying: %s"), e.getMessage()); m_initWaiter.waitForEvent(5000); try { m_hookInstaller->uninstall(); } catch (Exception &e) { m_log->error(_T("Hooks uninstalling failed: %s"), e.getMessage()); } } } start32Loader(); if (!isTerminating()) { m_log->info(_T("Hooks update detector has been successfully initialized")); } MSG msg; while (!isTerminating()) { if (PeekMessage(&msg, m_targetWin->getHWND(), 0, 0, PM_REMOVE) != 0) { if (msg.message == HookDefinitions::SPEC_IPC_CODE) { Rect rect((INT16)(msg.wParam >> 16), (INT16)(msg.wParam & 0xffff), (INT16)(msg.lParam >> 16), (INT16)(msg.lParam & 0xffff)); if (!rect.isEmpty()) { m_updateKeeper->addChangedRect(&rect); m_updateTimer.sear(); } } else { DispatchMessage(&msg); } } else {
status_t MediaPlayer::seekTo(int msec) { mLockThreadId = getThreadId(); Mutex::Autolock _l(mLock); status_t result = seekTo_l(msec); mLockThreadId = 0; return result; }
Nd4jLong SessionLocalStorage::getSessionId() { auto tid = getThreadId(); _mutex.lock(); auto ntid = _threadSession[tid]; _mutex.unlock(); return ntid; }
void CMutex::Lock(){ long int tid = getThreadId(); //return Lock(4294967295); //printf("%s:%d Mutex: %s thread %ld lockCount %d waiting", __FILE__, __LINE__, name,tid,lockCount); mutex.lock(); owner = tid; lockCount++; //printf(" %s lockCount %d \n","Success",lockCount); }
Thread::ThreadPtr IoServiceCore::createNamedThread(const char* name) { auto thread = Thread::create(); thread->run(); LOGT("Create named thread [ %s -- %s ]", name, thread->getThreadId()); _namedThread.insert(make_pair(name, thread)); return thread; }
static void fillThreadInfo( HWND hwnd, ProcStats *info ) { HWND lb; int index; char buf[100]; DWORD threadid; ThreadStats thdinfo; #ifndef CHICAGO char *str1; #endif lb = GetDlgItem( hwnd, THREAD_LIST ); index = (int)SendMessage( lb, LB_GETCURSEL, 0, 0L ); if( index == LB_ERR ) { SetDlgItemText( hwnd, THREAD_TID, "" ); SetDlgItemText( hwnd, THREAD_SUSPEND_CNT, "" ); SetDlgItemText( hwnd, THREAD_PRIORITY, "" ); } else { enableChoices( hwnd, TRUE ); SendMessage( lb, LB_GETTEXT, index, (LPARAM)(LPSTR)buf ); threadid = getThreadId( buf ); sprintf( buf, "tid = %08lX", threadid ); SetDlgItemText( hwnd, THREAD_TID, buf ); if( GetThreadInfo( info->pid, threadid, &thdinfo ) ) { #ifndef CHICAGO if( thdinfo.state == 5 ) { /* the thread is in a wait state */ str1 = SrchMsg( thdinfo.wait_reason, ThreadWaitMsgs, NULL ); if( str1 == NULL ) { str1 = AllocRCString( STR_WAIT_4_UNKNOWN ); RCsprintf( buf, STR_STATE, str1 ); FreeRCString( str1 ); } else { RCsprintf( buf, STR_STATE, str1 ); } } else { str1 = SrchMsg( thdinfo.state, ThreadStateMsgs, NULL ); if( str1 == NULL ) { str1 = AllocRCString( STR_BRACED_UNKNOWN ); RCsprintf( buf, STR_STATE, str1 ); FreeRCString( str1 ); } else { RCsprintf( buf, STR_STATE, str1 ); } } SetDlgItemText( hwnd, THREAD_SUSPEND_CNT, buf ); #endif /* get priority */ RCsprintf( buf, STR_PRIORITY_X, thdinfo.cur_pri, thdinfo.base_pri ); SetDlgItemText( hwnd, THREAD_PRIORITY, buf ); } } }
void CMutex::Unlock(){ long int tid = getThreadId(); if(owner == tid && lockCount > 0){ //printf("%s:%d Mutex: %s thread %ld lockCount %d unlock.....", __FILE__, __LINE__, name, tid,lockCount); lockCount--; mutex.unlock(); //printf("unlocked\n"); } }
void ExtMemoryPool::freeLargeObject(void *object) { LargeObjectHdr *header = (LargeObjectHdr*)object - 1; // overwrite backRefIdx to simplify double free detection header->backRefIdx = BackRefIdx(); if (!loc.put(this, header->memoryBlock)) { removeBackRef(header->memoryBlock->backRefIdx); backend.putLargeBlock(header->memoryBlock); STAT_increment(getThreadId(), ThreadCommonCounters, freeLargeObj); } }
void ConfigStorage::release() { fb_assert(m_recursive > 0); fb_assert(m_mutexTID == getThreadId()); if (--m_recursive == 0) { checkDirty(); m_mutexTID = 0; m_sharedMemory->mutexUnlock(); } }
void SessionLocalStorage::endSession() { auto tid = getThreadId(); _mutex.lock(); auto ntid = _threadSession[tid]; _threadSession.erase(tid); _mutex.unlock(); endSession(ntid); }
inline void unlock() { if ((mlocked >0) && (mLockThreadId == getThreadId())) { mlocked --; if( mlocked <=0 ) { mlocked = 0; mLockThreadId = 0; mLock.unlock(); } } }
__global__ void entry(int * handles, int * exceptions, int numBlocks, int usingKernelTemplates){ int loop_control = getThreadId(); if(loop_control < numBlocks){ int exception = 0; int handle; if(usingKernelTemplates){ handle = handles[0]; } else { handle = handles[loop_control]; } %%invoke_run%%(handle, &exception);
bool LargeObjectCache::put(ExtMemoryPool *extMemPool, LargeMemoryBlock *largeBlock) { size_t idx = sizeToIdx(largeBlock->unalignedSize); if (idx<numLargeBlockBins) { MALLOC_ITT_SYNC_RELEASING(bin+idx); if (bin[idx].put(extMemPool, largeBlock)) { STAT_increment(getThreadId(), ThreadCommonCounters, cacheLargeBlk); return true; } else return false; } return false; }
void grid::NumaDistStaticGrid::getAt(void* buf, types::Type::converter_t converter, unsigned long x, unsigned long y, unsigned long z) { unsigned long block = getBlockByCoords(x, y, z); int remoteMPIRank = getBlockRank(block); unsigned long remoteThreadId = getThreadId(block); if (remoteMPIRank == getMPIRank() && pthread_equal(remoteThreadId, pthread_self())) { // Nice, this is a block where we are the master NumaLocalStaticGrid::getAt(buf, converter, x, y, z); return; } // This function will call getBlock, if we need to transfer the block NumaLocalCacheGrid::getAt(buf, converter, x, y, z); }
LargeMemoryBlock *LargeObjectCache::get(ExtMemoryPool *extMemPool, size_t size) { MALLOC_ASSERT( size%largeBlockCacheStep==0, ASSERT_TEXT ); LargeMemoryBlock *lmb = NULL; size_t idx = sizeToIdx(size); if (idx<numLargeBlockBins) { lmb = bin[idx].get(extMemPool, size); if (lmb) { MALLOC_ITT_SYNC_ACQUIRED(bin+idx); STAT_increment(getThreadId(), ThreadCommonCounters, allocCachedLargeBlk); } } return lmb; }
Nd4jLong nd4j::graph::SessionLocalStorage::startSession() { auto tid = getThreadId(); nd4j_debug("Adding ThreadId: %i;\n", (int) tid); Nd4jLong ntid = _sessionCounter++; _mutex.lock(); _threadSession[tid] = ntid; _threadVariableSpace[ntid] = _variableSpace->clone(); _mutex.unlock(); return ntid; }
void EMULATOR_SESSION_CLASS::registerEmulateSCPThread(BASE_SCP_EMULATOR_CLASS *emulator_ptr) // DESCRIPTION : Register the emulator thread. // PRECONDITIONS : // POSTCONDITIONS : // EXCEPTIONS : // NOTES : //<<=========================================================================== { // add the thead to the list scpEmulatorThreadM.add(emulator_ptr); // set the owner thread ID of the socket to this thread emulator_ptr->setSocketOwnerThreadId(getThreadId()); }
//============================================================================== bool Thread::setPriority (const int newPriority) { // NB: deadlock possible if you try to set the thread prio from the thread itself, // so using setCurrentThreadPriority instead in that case. if (getCurrentThreadId() == getThreadId()) return setCurrentThreadPriority (newPriority); const RecursiveMutex::ScopedLockType sl (startStopLock); if (setThreadPriority (threadHandle, newPriority)) { threadPriority = newPriority; return true; } return false; }
bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const { // Doh! So how exactly do you expect this thread to wait for itself to stop?? bassert (getThreadId() != getCurrentThreadId() || getCurrentThreadId() == 0); const std::uint32_t timeoutEnd = Time::getMillisecondCounter() + (std::uint32_t) timeOutMilliseconds; while (isThreadRunning()) { if (timeOutMilliseconds >= 0 && Time::getMillisecondCounter() > timeoutEnd) return false; sleep (2); } return true; }
void MouseShapeDetector::execute() { Log::info(_T("mouse shape detector thread id = %d"), getThreadId()); while (!isTerminating()) { bool isCursorShapeChanged; { AutoLock al(m_mouseGrabLocMut); isCursorShapeChanged = m_mouseGrabber->isCursorShapeChanged(); } if (isCursorShapeChanged) { m_updateKeeper->setCursorShapeChanged(); doUpdate(); } Sleep(SLEEP_TIME); } }
LargeMemoryBlock *LargeObjectCacheImpl<Props>::get(uintptr_t currTime, size_t size) { MALLOC_ASSERT( size%Props::CacheStep==0, ASSERT_TEXT ); int idx = sizeToIdx(size); bool setNonEmpty = false; LargeMemoryBlock *lmb = bin[idx].get(size, currTime, &setNonEmpty); // Setting to true is possible out of lock. As bitmask is used only for cleanup, // the lack of consistency is not violating correctness here. if (setNonEmpty) bitMask.set(idx, true); if (lmb) { MALLOC_ITT_SYNC_ACQUIRED(bin+idx); STAT_increment(getThreadId(), ThreadCommonCounters, allocCachedLargeObj); } return lmb; }
status_t Thread::join() { Mutex::Autolock _l(mLock); if (mThread == getThreadId()) { ALOGW( "Thread (this=%p): don't call join() from this " "Thread object's thread. It's a guaranteed deadlock!", this); return WOULD_BLOCK; } while (mRunning == true) { mThreadExitedCondition.wait(mLock); } return mStatus; }
//Specifies the amount of time to wait for the synchronization object to be available (signaled). //If INFINITE, Lock will wait until the object is signaled before returning. //DWORD TimeOut_ms = INFINITE = 4294967295 int CMutex::Lock(int TimeOut_ms/* = 4294967295*/){ //std::condition_variable_any; // printf("Thread %.8x %.8x: Waiting to get lock \n", t); long int tid = getThreadId(); //printf("%s:%d Mutex: %s waiting max timout %d thread %ld lockCount %d", __FILE__, __LINE__, name,TimeOut_ms,tid,lockCount); using Ms = std::chrono::milliseconds; bool success = mutex.try_lock_for(Ms(TimeOut_ms)); if(success){ owner = tid; lockCount++; } //printf(" %s\n",success?"Success":"Failed"); //printf(" %s lockCount %d \n",success?"Success":"Failed",lockCount); return success?1:0; }
void ConfigStorage::acquire() { fb_assert(m_recursive >= 0); const ThreadId currTID = getThreadId(); if (m_mutexTID == currTID) m_recursive++; else { m_sharedMemory->mutexLock(); fb_assert(m_recursive == 0); m_recursive = 1; fb_assert(m_mutexTID == 0); m_mutexTID = currTID; } }