MCPcopy Create free account
hub / github.com/OpenKinect/libfreenect2 / try_lock

Function try_lock

src/tinythread/tinythread.h:206–219  ·  view source on GitHub ↗

Try to lock the mutex. The method will try to lock the mutex. If it fails, the function will return immediately (non-blocking). @return @c true if the lock was acquired, or @c false if the lock could not be acquired.

Source from the content-addressed store, hash-verified

204 /// @return @c true if the lock was acquired, or @c false if the lock could
205 /// not be acquired.
206 inline bool try_lock()
207 {
208#if defined(_TTHREAD_WIN32_)
209 bool ret = (TryEnterCriticalSection(&mHandle) ? true : false);
210 if(ret && mAlreadyLocked)
211 {
212 LeaveCriticalSection(&mHandle);
213 ret = false;
214 }
215 return ret;
216#else
217 return (pthread_mutex_trylock(&mHandle) == 0) ? true : false;
218#endif
219 }
220
221 /// Unlock the mutex.
222 /// If any threads are waiting for the lock on this mutex, one of them will

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected