コード例 #1
0
ファイル: mthread.c プロジェクト: bombardellif/microthread
int mjoin(int thr) {
    Tcb *threadToWaitFor;
    boolean successBlocking;
    
    initialize();
    
    setYielding(TRUE);
    
    // search thread by id, if found, then block the current and schedule.
    if ((threadToWaitFor = getThreadById(thr))) {
        
        successBlocking = changeStateToWaiting(threadToWaitFor);
        
        if (successBlocking) {
            saveContext();

            // When the thread will be unblocked, it will continue executing HERE
            // but the scheduler won't schedule, hence this following call will do nothing
            schedule();
            
            return 0;
        }
    }
    
    // return 0 in case of success, or -1 otherwise
    return -1;
}
コード例 #2
0
ファイル: mthread.c プロジェクト: bombardellif/microthread
int munlock (mmutex_t *mutex) {
    Tcb *targetThread;
    int *waitingThreadId;
    
    initialize();
    
    if (mutex
    && (mutex->flag == Locked)
    && (mutex->ownerThread == getExecutingThread()->id)) {
        
        setFlag(mutex, Free);
        
        waitingThreadId = getFromWaitingQueue(mutex);
        if (waitingThreadId) {
            targetThread = getThreadById(*waitingThreadId);

            if (targetThread) {

                changeStateToReady(targetThread);
                return 0;
            }
        } else {
            return 0;
        }
    }
    
    return -1;
}
コード例 #3
0
ファイル: gethreads.c プロジェクト: drewet/libge
void geThreadExit(int code){
	ge_Thread* thread = NULL;
	thread = getThreadById(pthread_self());

	if(thread)thread->exit_code=code;

	int ret = 0;
	pthread_exit(&ret);
	if(thread)thread->returned=ret;
}