add 'zpl_semaphore_trywait'
Bluelet opened this issue · comments
Sometimes, a semaphore trywait is needed, just like following:
ZPL_DEF bool zpl_semaphore_trywait (zpl_semaphore *s);
#if defined(ZPL_SYSTEM_WINDOWS)
bool zpl_semaphore_trywait (zpl_semaphore *s) { int r = WaitForSingleObject(s->win32_handle, 0); return (r==0); }
#elif defined(ZPL_SYSTEM_MACOS)
bool zpl_semaphore_trywait (zpl_semaphore *s) { mach_timespec_t t; t.tv_sec = t.tv_nsec = 0; kern_return_t r = semaphore_timedwait(s->osx_handle, t); return (r==0); }
#elif defined(ZPL_SYSTEM_UNIX)
bool zpl_semaphore_trywait (zpl_semaphore *s) { int r = sem_trywait(&s->unix_handle); return (r==0); }
#else
#error
#endif