Status LinuxThread::Create() { CHECK_ERROR(!m_threadId); BEFORE_CHECK_RESULT(); if(m_cond) CHECK_RESULT(_destroyCond(m_cond)); CHECK_RESULT(_initCond(m_cond)); if(m_runMutex) CHECK_RESULT(_destroyMutex(m_runMutex)); CHECK_RESULT(_initMutex(m_runMutex)); if(m_terminateMutex) CHECK_RESULT(_destroyMutex(m_terminateMutex)); CHECK_RESULT(_initMutex(m_terminateMutex)); m_bRun = true; m_bTerminate = false; m_threadId = new pthread_t; int ret = pthread_create(m_threadId,NULL,_ThreadProc,(void*)this); if(ret){ delete m_threadId; m_threadId = NULL; } return ret == 0 ? OK : ER; }
static void _mf_cover(long *p) { unsigned long z,i,w; if(p && (w=*(p-1))==(*(p-2))) { int rc; unsigned long ww=(*(p-2))+2*sizeof(long *); #if defined(linux) if(initMutex) initMutex=_initMutex(); #endif if(memTrack && ww>=memTrackThreshold) printf("0x%x freeing %lu bytes\n",p,ww); for (z = ww >> 1, i = 1; z != 0; z >>= 1, i++); if( i >= MD ) i=MD-1; if(0!=(rc=pthread_mutex_lock(&memStats_lock))) { perror("si() pthread_mutex_lock"); } if(totalObjs[i]) totalObjs[i]--; if(totalSize[i]) totalSize[i] -= ww; if(rc==0 && pthread_mutex_unlock(&memStats_lock)) { perror("si() pthread_mutex_unlock"); } }
char * _mab_cover(unsigned long w) { unsigned long z,i; char *p=_mab(w); if(p) { int rc; unsigned long ww=w+2*sizeof(long *); #if defined(linux) if(initMutex) initMutex=_initMutex(); #endif /* Test for 8bit alignment */ if(!QA(p) ) printf("!! pointer not 8bit aligned 0x%x\n",p); if(memTrack && ww>=memTrackThreshold) printf("0x%x malloc %lu bytes\n",p,ww); for (z = ww >> 1, i = 1; z != 0; z >>= 1, i++); if( i >= MD ) i=MD-1; if(0!=(rc=pthread_mutex_lock(&memStats_lock))) { perror("si() pthread_mutex_lock"); } totalObjs[i]++; totalSize[i] += ww; if(totalObjs[i]>totalObjsMax[i]) totalObjsMax[i]=totalObjs[i]; if(totalSize[i]>totalSizeMax[i]) totalSizeMax[i]=totalSize[i]; if(rc==0 && pthread_mutex_unlock(&memStats_lock)) { perror("si() pthread_mutex_unlock"); } } return p; }
S si(const C *n) { S s,a=(S)(((S *)(SymHashTable->b))+((SymHashTable->nb-1)&HA(n))); for(;(s=a->s)&&strneq(n,s->n);a=s) ; if(s==0) { int rc; #if defined(linux) static int initMutex=1; if(initMutex) initMutex=_initMutex(); #endif if(0!=(rc=pthread_mutex_lock(&newSymbol_lock))) { perror("si() pthread_mutex_lock"); } { /* Need to re-check for Symbol after getting lock */ S a=(S)(((S *)(SymHashTable->b))+((SymHashTable->nb-1)&HA(n))); for(;(s=a->s)&&strneq(n,s->n);a=s) ; if(s==0) { s=newSymbol(n,a); } } if(rc==0 && pthread_mutex_unlock(&newSymbol_lock)) { perror("si() pthread_mutex_unlock"); } } R s; }