Beispiel #1
0
static void begin_thread_helper( void *the_arg )
{
    thread_fn           *start_addr;
    void                *arglist;
    void                *stack_bottom;

    thread_data         *tdata;
    int                 newtid;
    begin_thread_data   *data = the_arg;

    tdata = alloca( __ThreadDataSize );
    newtid = gettid( NULL );
    if( newtid != 0 ) {
        data->tid = newtid;
        start_addr = data->start_addr;
        arglist = data->arglist;
        stack_bottom = data->stack_bottom;
        SignalLocalSemaphore( data->semaphore );
        __ThreadIDs[ newtid ] = GetThreadID();
        __ThreadData[ newtid ].data = tdata;
        __ThreadData[ newtid ].allocated_entry = 0;
        memset( tdata, 0, __ThreadDataSize );
        // tdata->__allocated = 0;
        tdata->__data_size = __ThreadDataSize;
        tdata->__randnext = 1;
        _RWD_stacklow = FP_OFF( stack_bottom );
        (*start_addr)( arglist );
        _endthread();
    } else {
        data->tid = -1;
        SignalLocalSemaphore( data->semaphore );
    }
}
Beispiel #2
0
BOOL fnRemoveThreadCtx(long lTLSIndex)
{
        ThreadContext* tip = NULL;
        ThreadContext* prevt = NULL;

        if (g_tCtxSem)
        {
                #ifdef MPK_ON
                        kSemaphoreWait(g_tCtxSem);
                #else
                        WaitOnLocalSemaphore(g_tCtxSem);
                #endif	//MPK_ON
        }

        #ifdef MPK_ON
                lTLSIndex = labs(kCurrentThread());
        #else
                lTLSIndex = GetThreadID();
        #endif	//MPK_ON

        tip = g_ThreadCtx;
        while(tip) {
                if (tip->tid == lTLSIndex) {
                        if (prevt == NULL)
                                g_ThreadCtx = tip->next;
                        else
                                prevt->next = tip->next;

                        free(tip);
                        tip=NULL;
                        if (g_tCtxSem)
                        {
                                #ifdef MPK_ON
                                        kSemaphoreSignal(g_tCtxSem);
                                #else
                                        SignalLocalSemaphore(g_tCtxSem);
                                #endif	//MPK_ON
                        }
                        return TRUE;
                }
                prevt = tip;
                tip = tip->next;
        }

        if (g_tCtxSem)
        {
                #ifdef MPK_ON
                        kSemaphoreSignal(g_tCtxSem);
                #else
                        SignalLocalSemaphore(g_tCtxSem);
                #endif	//MPK_ON
        }

        return FALSE;       // entry not found
}
Beispiel #3
0
BOOL fnGetHashListAddrs(void **addrs, BOOL *dontTouchHashList)
{
        ThreadInfo*  tip;   
        int index,tid;   

        if (g_tinfoSem) 
        {
                #ifdef MPK_ON
                        kSemaphoreWait(g_tinfoSem);
                #else
                        WaitOnLocalSemaphore(g_tinfoSem);
                #endif	//MPK_ON
        }

        #ifdef MPK_ON
                tid=index = abs(kCurrentThread());
        #else
                tid=index = GetThreadID();
        #endif	//MPK_ON

        index = INDEXOF(index);     // just take the bottom five bits 

        // see if this is already in the table at the index'th offset
        //
        for (tip = g_ThreadInfo[index]; tip != NULL; tip = tip->next)
        {
                if (tip->tid == tid)
                {
                        if (g_tinfoSem)
                        {
                                #ifdef MPK_ON
                                        kSemaphoreSignal(g_tinfoSem);
                                #else
                                        SignalLocalSemaphore(g_tinfoSem);
                                #endif	//MPK_ON
                        }
                        *addrs = tip->m_allocList;
                        *dontTouchHashList = tip->m_dontTouchHashLists;
                        return TRUE;
                }
        }

        if (g_tinfoSem)
        {
                #ifdef MPK_ON
                        kSemaphoreSignal(g_tinfoSem);
                #else
                        SignalLocalSemaphore(g_tinfoSem);
                #endif	//MPK_ON
        }

        return FALSE;
}
Beispiel #4
0
BOOL fnRemoveThreadInfo(int tid)
{
        ThreadInfo* tip = NULL;
        ThreadInfo* prevt = NULL;
        int index = INDEXOF(tid);     // just take the bottom five bits

        if (g_tinfoSem)
        {
                #ifdef MPK_ON
                        kSemaphoreWait(g_tinfoSem);
                #else
                        WaitOnLocalSemaphore(g_tinfoSem);
                #endif	//MPK_ON
        }

        for (tip = g_ThreadInfo[index]; tip != NULL; tip = tip->next)
        {
                if (tip->tid == tid)
                {
                        if (prevt == NULL)
                                g_ThreadInfo[index] = tip->next;
                        else
                                prevt->next = tip->next;

                        free(tip);
                        tip=NULL;
                        if (g_tinfoSem)
                        {
                                #ifdef MPK_ON
                                        kSemaphoreSignal(g_tinfoSem);
                                #else
                                        SignalLocalSemaphore(g_tinfoSem);
                                #endif	//MPK_ON
                        }

                        return TRUE;
                }
                prevt = tip;
        }

        if (g_tinfoSem)
        {
                #ifdef MPK_ON
                        kSemaphoreSignal(g_tinfoSem);
                #else
                        SignalLocalSemaphore(g_tinfoSem);
                #endif	//MPK_ON
        }

        return FALSE;       // entry not found
}
Beispiel #5
0
BOOL fnTerminateThreadInfo(void)
{
        int index = 0;

        if (g_tinfoSem)
        {
                #ifdef MPK_ON
                        kSemaphoreWait(g_tinfoSem);
                #else
                        WaitOnLocalSemaphore(g_tinfoSem);
                #endif	//MPK_ON
                for (index = 0; index < NUM_ENTRIES; index++)
                {
                        if (g_ThreadInfo[index] != NULL)
                        {
                                #ifdef MPK_ON
                                        kSemaphoreSignal(g_tinfoSem);
                                #else
                                        SignalLocalSemaphore(g_tinfoSem);
                                #endif	//MPK_ON
                                return FALSE;
                        }
                }
                #ifdef MPK_ON
                        kSemaphoreFree(g_tinfoSem);
                        g_tinfoSem = NULL;
                #else
                        CloseLocalSemaphore(g_tinfoSem);
                        g_tinfoSem = 0;
                #endif	//MPK_ON
        }

        return TRUE;
}
Beispiel #6
0
int sdbm_fd_unlock(int fd)
{
    int rc;

#ifdef USE_FCNTL
    unlock_it.l_whence = SEEK_SET; /* from current point */
    unlock_it.l_start  = 0;        /* -"- */
    unlock_it.l_len    = 0;        /* until end of file */
    unlock_it.l_type   = F_UNLCK;  /* unlock */
    unlock_it.l_pid    = 0;        /* pid not actually interesting */

    rc = fcntl(fd, F_SETLKW, &unlock_it);
#endif
#ifdef USE_FLOCK
    rc = flock(fd, LOCK_UN);
#endif
#ifdef USE_LOCKING
    lseek(fd, 0, SEEK_SET);
    rc = _locking(fd, _LK_UNLCK, 1);
#endif
#ifdef USE_SEM_LOCKING
	if (locking_sem)
		SignalLocalSemaphore (locking_sem);
	rc = 1;
#endif

    return rc;
}
Beispiel #7
0
ThreadInfo* fnAddThreadInfo(int tid)
{
        ThreadInfo* tip = NULL;
        int index = 0;

        if (g_tinfoSem)
        {
                #ifdef MPK_ON
                        kSemaphoreWait(g_tinfoSem);
                #else
                        WaitOnLocalSemaphore(g_tinfoSem);
                #endif	//MPK_ON
        }

        // Add a new one to the beginning of the hash entry
        //
        tip = (ThreadInfo *) malloc(sizeof(ThreadInfo));
        if (tip == NULL)
        {  
                if (g_tinfoSem)
                {
                        #ifdef MPK_ON
                                kSemaphoreSignal(g_tinfoSem);
                        #else
                                SignalLocalSemaphore(g_tinfoSem);
                        #endif	//MPK_ON
                }
                return NULL;
        }
        index = INDEXOF(tid);     // just take the bottom five bits
        tip->next            =  g_ThreadInfo[index];
        tip->tid             =  tid;
        tip->m_dontTouchHashLists = FALSE;
        tip->m_allocList = NULL;

        g_ThreadInfo [index] =  tip;
        if (g_tinfoSem)
        {
                #ifdef MPK_ON
                        kSemaphoreSignal(g_tinfoSem);
                #else
                        SignalLocalSemaphore(g_tinfoSem);
                #endif	//MPK_ON
        }

        return tip;
}
Beispiel #8
0
void* fnGetThreadCtx(long lTLSIndex)
{
        ThreadContext*  tip;   

        if (g_tCtxSem) 
        {
                #ifdef MPK_ON
                        kSemaphoreWait(g_tCtxSem);
                #else
                        WaitOnLocalSemaphore(g_tCtxSem);
                #endif	//MPK_ON
        }

        #ifdef MPK_ON
                lTLSIndex = labs(kCurrentThread());
        #else
                lTLSIndex = GetThreadID();
        #endif	//MPK_ON

        tip = g_ThreadCtx;
        while(tip) {
                if (tip->tid == lTLSIndex) {
                        if (g_tCtxSem)
                        {
                                #ifdef MPK_ON
                                        kSemaphoreSignal(g_tCtxSem);
                                #else
                                        SignalLocalSemaphore(g_tCtxSem);
                                #endif	//MPK_ON
                        }
                        return (tip->tInfo);
                }
                tip=tip->next;
        }

        if (g_tCtxSem)
        {
                #ifdef MPK_ON
                        kSemaphoreSignal(g_tCtxSem);
                #else
                        SignalLocalSemaphore(g_tCtxSem);
                #endif	//MPK_ON
        }

        return NULL;
}
Beispiel #9
0
ThreadInfo* fnGetThreadInfo(int tid)
{
        ThreadInfo*  tip;   
        int index = INDEXOF(tid);     // just take the bottom five bits

        if (g_tinfoSem) {
                #ifdef MPK_ON
                        kSemaphoreWait(g_tinfoSem);
                #else
                        WaitOnLocalSemaphore(g_tinfoSem);
                #endif	//MPK_ON
        }

        // see if this is already in the table at the index'th offset
        //
        for (tip = g_ThreadInfo[index]; tip != NULL; tip = tip->next)
        {
                if (tip->tid == tid)
                {
                        if (g_tinfoSem)
                        {
                                #ifdef MPK_ON
                                        kSemaphoreSignal(g_tinfoSem);
                                #else
                                        SignalLocalSemaphore(g_tinfoSem);
                                #endif	//MPK_ON
                        }
                        return tip;
                }
        }

        if (g_tinfoSem)
        {
                #ifdef MPK_ON
                        kSemaphoreSignal(g_tinfoSem);
                #else
                        SignalLocalSemaphore(g_tinfoSem);
                #endif	//MPK_ON
        }

        return NULL;
}
Beispiel #10
0
		void Leave()
		{
			SignalLocalSemaphore( m_sem );
		};
Beispiel #11
0
ThreadContext* fnAddThreadCtx(long lTLSIndex, void *t)
{
        ThreadContext* tip = NULL;
        ThreadContext* temp = NULL;

        if (g_tCtxSem)
        {
                #ifdef MPK_ON
                        kSemaphoreWait(g_tCtxSem);
                #else
                        WaitOnLocalSemaphore(g_tCtxSem);
                #endif	//MPK_ON
        }

        // add a new one to the beginning of the list
        //
        tip = (ThreadContext *) malloc(sizeof(ThreadContext));
        if (tip == NULL)
        {  
                if (g_tCtxSem)
                {
                        #ifdef MPK_ON
                                kSemaphoreSignal(g_tCtxSem);
                        #else
                                SignalLocalSemaphore(g_tCtxSem);
                        #endif	//MPK_ON
                }
                return NULL;
        }

        #ifdef MPK_ON
                lTLSIndex = labs(kCurrentThread());
        #else
                lTLSIndex = GetThreadID();
        #endif	//MPK_ON

        tip->next            =  NULL;
        tip->tid             =  lTLSIndex;
        tip->tInfo			 =  t;

        if(g_ThreadCtx==NULL) {
                g_ThreadCtx = tip;
        } else {
                int count=0;
                //Traverse to the end
                temp = g_ThreadCtx;
                while(temp->next != NULL)
                {
                        temp = temp->next;
                        count++;
                }
                temp->next = tip;
        }

        if (g_tCtxSem)
        {
                #ifdef MPK_ON
                        kSemaphoreSignal(g_tCtxSem);
                #else
                        SignalLocalSemaphore(g_tCtxSem);
                #endif	//MPK_ON
        }
        return tip;
}