コード例 #1
0
ファイル: rwlock.c プロジェクト: gefla/empserver
void
lwp_rwlock_unlock(struct lwp_rwlock *rwlock)
{
    struct lwpProc *p;
    int maxpri;

    lwpStatus(LwpCurrent, "unlocking rwlock %s", rwlock->name);
    if (CANT_HAPPEN(rwlock->count == 0))
	return;
    if (rwlock->count < 0)
	rwlock->count = 0;
    else
	rwlock->count--;

    if (rwlock->count == 0 && rwlock->wq.head) {
	p = lwpGetFirst(&rwlock->wq);
	lwpStatus(p, "wake up next writer of rwlock %s", rwlock->name);
	maxpri = p->pri;
	lwpReady(p);
    } else if (rwlock->count >= 0 && rwlock->rq.head && !rwlock->wq.head) {
	maxpri = 0;
	while ((p = lwpGetFirst(&rwlock->rq))) {
	    lwpStatus(p, "wake up next reader of rwlock %s", rwlock->name);
	    maxpri = MAX(maxpri, p->pri);
	    lwpReady(p);
	}
    } else
	return;

    if (LwpCurrent->pri < maxpri) {
	lwpStatus(LwpCurrent, "yielding to thread with higher priority");
	lwpYield();
    }
}
コード例 #2
0
/*
 * Wake up threads in LwpDelayq whose time has come.
 */
void
lwpWakeupSleep(void)
{
    time_t now;
    struct lwpQueue save;
    struct lwpProc *proc;

    if (LwpDelayq.head) {
	now = time(NULL);
	save.tail = save.head = NULL;
	while (NULL != (proc = lwpGetFirst(&LwpDelayq))) {
	    if (now >= proc->runtime) {
		lwpStatus(proc, "sleep done");
		if (proc->runtime != 0)
		    proc->runtime = (time_t)-1;
		if (proc->fd >= 0)
		    lwpWakeupFd(proc);
		else
		    lwpReady(proc);
	    } else {
		lwpAddTail(&save, proc);
	    }
	}
	LwpDelayq = save;
    }
}