Fixing mutex-unlock! on a condition variable to both unlock and block.

This commit is contained in:
Alex Shinn 2012-05-12 22:43:46 +09:00
parent 1ab1008f20
commit 1aff449a48

View file

@ -218,8 +218,7 @@ sexp sexp_mutex_lock (sexp ctx, sexp self, sexp_sint_t n, sexp mutex, sexp timeo
sexp sexp_mutex_unlock (sexp ctx, sexp self, sexp_sint_t n, sexp mutex, sexp condvar, sexp timeout) { sexp sexp_mutex_unlock (sexp ctx, sexp self, sexp_sint_t n, sexp mutex, sexp condvar, sexp timeout) {
sexp ls1, ls2; sexp ls1, ls2;
if (sexp_not(condvar)) { /* first unlock and unblock threads */
/* normal unlock - always succeeds, just need to unblock threads */
if (sexp_truep(sexp_mutex_lockp(mutex))) { if (sexp_truep(sexp_mutex_lockp(mutex))) {
sexp_mutex_lockp(mutex) = SEXP_FALSE; sexp_mutex_lockp(mutex) = SEXP_FALSE;
sexp_mutex_thread(mutex) = ctx; sexp_mutex_thread(mutex) = ctx;
@ -240,14 +239,14 @@ sexp sexp_mutex_unlock (sexp ctx, sexp self, sexp_sint_t n, sexp mutex, sexp con
break; break;
} }
} }
return SEXP_TRUE; if (sexp_truep(condvar)) {
} else { /* wait on condition var if specified */
/* wait on condition var */
sexp_context_waitp(ctx) = 1; sexp_context_waitp(ctx) = 1;
sexp_context_event(ctx) = condvar; sexp_context_event(ctx) = condvar;
sexp_insert_timed(ctx, ctx, timeout); sexp_insert_timed(ctx, ctx, timeout);
return SEXP_FALSE; return SEXP_FALSE;
} }
return SEXP_TRUE;
} }
/**************************** condition variables *************************/ /**************************** condition variables *************************/