a9e09c4f7db7d1751f66687ffe08308b1dd071a5
[platform/upstream/dldt.git] / inference-engine / thirdparty / movidius / XLink / pc / Win / src / win_synchapi.c
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #include "win_synchapi.h"
6
7 int pthread_cond_init(pthread_cond_t* __cond, const pthread_condattr_t* __cond_attr)
8 {
9     if (__cond == NULL) {
10         return ERROR_INVALID_HANDLE;
11     }
12
13     (void)__cond_attr;
14     InitializeConditionVariable(&__cond->_cv);
15     return 0;
16 }
17
18 int pthread_cond_destroy(pthread_cond_t* __cond)
19 {
20     (void)__cond;
21     return 0;
22 }
23
24 int pthread_cond_timedwait(pthread_cond_t* __cond,
25     pthread_mutex_t* __mutex,
26     const struct timespec* __abstime) 
27 {
28     if (__cond == NULL) {
29         return ERROR_INVALID_HANDLE;
30     }
31
32     long long msec = INFINITE;
33     if (__abstime != NULL) {
34         msec = __abstime->tv_sec * 1000 + __abstime->tv_nsec / 1000000;
35     }
36
37     // SleepConditionVariableCS returns bool=true on success.
38     if (SleepConditionVariableCS(&__cond->_cv, __mutex, (DWORD)msec))
39         return 0;
40
41     const int rc = (int)GetLastError();
42     return rc == ERROR_TIMEOUT ? ETIMEDOUT : rc;
43 }
44
45 int pthread_cond_broadcast(pthread_cond_t *__cond)
46 {
47     if (__cond == NULL) {
48         return ERROR_INVALID_HANDLE;
49     }
50
51     WakeConditionVariable(&__cond->_cv);
52     return 0;
53 }