// Thread-safe allocation of a semaphore. // Psema points at a kernel semaphore key. // It starts out zero, meaning no semaphore. // Fill it in, being careful of others calling initsema // simultaneously. static void initsema(uint32 *psema) { uint32 sema; if(*psema != 0) // already have one return; sema = mach_semcreate(); if(!cas(psema, 0, sema)){ // Someone else filled it in. Use theirs. mach_semdestroy(sema); return; } }
uintptr runtime·semacreate(void) { return runtime·mach_semcreate(); }