Lines Matching full:mutex
11 #include <xnnpack/mutex.h>
24 enum xnn_status xnn_mutex_init(struct xnn_mutex* mutex) { in xnn_mutex_init() argument
26 mutex->handle = CreateMutexW( in xnn_mutex_init()
30 if (mutex->handle == NULL) { in xnn_mutex_init()
31 xnn_log_error("failed to initialize mutex, error code: %" PRIu32, (uint32_t) GetLastError()); in xnn_mutex_init()
35 mutex->semaphore = dispatch_semaphore_create(1); in xnn_mutex_init()
36 if (mutex->semaphore == NULL) { in xnn_mutex_init()
37 xnn_log_error("failed to initialize mutex"); in xnn_mutex_init()
41 const int ret = pthread_mutex_init(&mutex->mutex, NULL); in xnn_mutex_init()
43 xnn_log_error("failed to initialize mutex, error code: %d", ret); in xnn_mutex_init()
50 enum xnn_status xnn_mutex_lock(struct xnn_mutex* mutex) { in xnn_mutex_lock() argument
52 const DWORD wait_result = WaitForSingleObject(mutex->handle, INFINITE); in xnn_mutex_lock()
54 xnn_log_error("failed to lock mutex, error code: %" PRIu32, (uint32_t) wait_result); in xnn_mutex_lock()
58 const int wait_result = dispatch_semaphore_wait(mutex->semaphore, DISPATCH_TIME_FOREVER); in xnn_mutex_lock()
60 xnn_log_error("failed to lock mutex, error code: %d", wait_result); in xnn_mutex_lock()
64 const int ret = pthread_mutex_lock(&mutex->mutex); in xnn_mutex_lock()
66 xnn_log_error("failed to lock mutex, error code: %d", ret); in xnn_mutex_lock()
73 enum xnn_status xnn_mutex_unlock(struct xnn_mutex* mutex) { in xnn_mutex_unlock() argument
75 if (ReleaseMutex(mutex->handle) == 0) { in xnn_mutex_unlock()
76 xnn_log_error("failed to unlock mutex, error code: %" PRIu32, (uint32_t) GetLastError()); in xnn_mutex_unlock()
80 dispatch_semaphore_signal(mutex->semaphore); in xnn_mutex_unlock()
82 const int ret = pthread_mutex_unlock(&mutex->mutex); in xnn_mutex_unlock()
84 xnn_log_error("failed to unlock mutex, error code: %d", ret); in xnn_mutex_unlock()
91 enum xnn_status xnn_mutex_destroy(struct xnn_mutex* mutex) { in xnn_mutex_destroy() argument
93 if (CloseHandle(mutex->handle) == 0) { in xnn_mutex_destroy()
94 xnn_log_error("failed to destroy mutex, error code: %" PRIu32, (uint32_t) GetLastError()); in xnn_mutex_destroy()
98 dispatch_release(mutex->semaphore); in xnn_mutex_destroy()
100 const int ret = pthread_mutex_destroy(&mutex->mutex); in xnn_mutex_destroy()
102 xnn_log_error("failed to destroy mutex, error code: %d", ret); in xnn_mutex_destroy()
106 memset(mutex, 0, sizeof(struct xnn_mutex)); in xnn_mutex_destroy()