static int gcry_requiem_mutex_init(void **retval) { int ret; gl_lock_t *lock; *retval = lock = malloc(sizeof(*lock)); if ( ! lock ) return ENOMEM; ret = glthread_lock_init(lock); if ( ret < 0 ) free(lock); return ret; }
void glthread_lock_lock (gl_lock_t *lock) { if (!lock->guard.done) { if (InterlockedIncrement (&lock->guard.started) == 0) /* This thread is the first one to need this lock. Initialize it. */ glthread_lock_init (lock); else /* Yield the CPU while waiting for another thread to finish initializing this lock. */ while (!lock->guard.done) Sleep (0); } EnterCriticalSection (&lock->lock); }