Debian Codegraph @

mysys/my_wincond.c

raw symbols SCIP
1 /* Copyright (c) 2000, 2014, Oracle and/or its affiliates.
2 Copyright (c) 2011, 2016, MariaDB
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
16
17 /*****************************************************************************
18 ** The following is a simple implementation of posix conditions
19 *****************************************************************************/
20 #if defined(_WIN32)
21
22 #undef SAFE_MUTEX /* Avoid safe_mutex redefinitions */
23 #include "mysys_priv.h"
24 #include <m_string.h>
25 #include <process.h>
26 #include <sys/timeb.h>
27
28
29 /**
30 Convert abstime to milliseconds
31 */
32
33 static DWORD get_milliseconds(const struct timespec *abstime)
34 {
35 struct timespec current_time;
36 long long ms;
37
38 if (abstime == NULL)
39 return INFINITE;
40
41 set_timespec_nsec(current_time, 0);
42 ms= (abstime->tv_sec - current_time.tv_sec)*1000LL +
43 (abstime->tv_nsec - current_time.tv_nsec)/1000000LL;
44 if(ms < 0 )
45 ms= 0;
46 if(ms > UINT_MAX)
47 ms= INFINITE;
48 return (DWORD)ms;
49 }
50
51 int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
52 {
53 InitializeConditionVariable(cond);
54 return 0;
55 }
56
57
58 int pthread_cond_destroy(pthread_cond_t *cond)
59 {
60 return 0;
61 }
62
63
64 int pthread_cond_broadcast(pthread_cond_t *cond)
65 {
66 WakeAllConditionVariable(cond);
67 return 0;
68 }
69
70
71 int pthread_cond_signal(pthread_cond_t *cond)
72 {
73 WakeConditionVariable(cond);
74 return 0;
75 }
76
77
78 int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
79 const struct timespec *abstime)
80 {
81 DWORD timeout= get_milliseconds(abstime);
82 if (!SleepConditionVariableCS(cond, mutex, timeout))
83 return ETIMEDOUT;
84 return 0;
85 }
86
87
88 int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
89 {
90 return pthread_cond_timedwait(cond, mutex, NULL);
91 }
92
93
94 int pthread_attr_init(pthread_attr_t *connect_att)
95 {
96 connect_att->dwStackSize = 0;
97 connect_att->dwCreatingFlag = 0;
98 return 0;
99 }
100
101 int pthread_attr_setstacksize(pthread_attr_t *connect_att,size_t stack)
102 {
103 DBUG_ASSERT(stack < UINT_MAX);
104 connect_att->dwStackSize=(DWORD)stack;
105 return 0;
106 }
107
108 int pthread_attr_destroy(pthread_attr_t *connect_att)
109 {
110 bzero((uchar*) connect_att,sizeof(*connect_att));
111 return 0;
112 }
113
114 #endif /* _WIN32 */