MCPcopy Create free account
hub / github.com/crownengine/crown / try_wait

Method try_wait

src/core/thread/semaphore.cpp:106–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106bool Semaphore::try_wait()
107{
108#if CROWN_PLATFORM_WINDOWS
109 DWORD err = WaitForSingleObject(_priv->handle, 0u);
110 if (err == WAIT_OBJECT_0)
111 return true;
112 else if (err == WAIT_TIMEOUT)
113 return false;
114 CE_FATAL("WaitForSingleObject: GetLastError = %d", GetLastError());
115 return false;
116#else
117 pthread_mutex_lock(&_priv->mutex);
118 if (_priv->count == 0) {
119 pthread_mutex_unlock(&_priv->mutex);
120 return false;
121 }
122
123 while (_priv->count <= 0) {
124 int err = pthread_cond_wait(&_priv->cond, &_priv->mutex);
125 CE_ASSERT(err == 0, "pthread_cond_wait: errno = %d", err);
126 CE_UNUSED(err);
127 }
128 _priv->count--;
129 pthread_mutex_unlock(&_priv->mutex);
130 return true;
131#endif // if CROWN_PLATFORM_WINDOWS
132}
133
134} // namespace crown

Callers 1

Calls 2

pthread_mutex_lockFunction · 0.85
pthread_mutex_unlockFunction · 0.85

Tested by

no test coverage detected