]> git.sur5r.net Git - openldap/blob - libraries/libldap_r/thr_nt.c
8592ce6633265a5b88e57891aa250085f208bede
[openldap] / libraries / libldap_r / thr_nt.c
1 /* thrnt.c - wrapper around NT threads */
2
3 #include "portable.h"
4 #include "ldap_pvt_thread.h"
5
6 #if defined( HAVE_NT_THREADS )
7
8 int 
9 openldap_thread_create( openldap_thread_t * thread, 
10                        openldap_thread_attr_t *attr,
11                        void *(*start_routine)( void *), void *arg)
12 {
13         *thread = (openldap_thread_t)_beginthread( (void *) start_routine, 
14                                                 0, arg );
15          return ( (unsigned long)*thread == -1 ? -1 : 0 );
16 }
17         
18 void 
19 openldap_thread_exit( void *retval )
20 {
21         _endthread( );
22 }
23
24 int 
25 openldap_thread_join( openldap_thread_t thread, void **thread_return )
26 {
27         DWORD status;
28         status = WaitForSingleObject( thread, INFINITE );
29         if (status == WAIT_FAILED) {
30                 return -1;
31         }
32         return 0;
33 }
34
35 int 
36 openldap_thread_kill( openldap_thread_t thread, int signo )
37 {
38         return 0;
39 }
40
41 int 
42 openldap_thread_yield( void )
43 {
44         return 0;
45 }
46
47 int 
48 openldap_thread_attr_init( openldap_thread_attr_t *attr )
49 {
50         *attr = 0;
51         return( 0 );
52 }
53
54 int 
55 openldap_thread_attr_destroy( openldap_thread_attr_t *attr )
56 {
57         return( 0 );
58 }
59
60 int 
61 openldap_thread_attr_setdetachstate( openldap_thread_attr_t *attr, int dstate )
62 {
63         *attr = dstate;
64         return( 0 );
65 }
66
67 int
68 openldap_thread_attr_getdetachstate( openldap_thread_attr_t *attr, 
69                                      int *detachstate )
70 {
71         *detachstate = *attr;
72         return( 0 );
73 }
74
75 int 
76 openldap_thread_cond_init( openldap_thread_cond_t *cond, 
77                           openldap_thread_condattr_t *attr )
78 {
79         *cond = CreateEvent( NULL, FALSE, FALSE, NULL );
80         return( 0 );
81 }
82
83 int
84 openldap_thread_cond_destroy( openldap_thread_cond_t *cv )
85 {
86         CloseHandle( *cv );
87         return( 0 );
88 }
89
90 int 
91 openldap_thread_cond_signal( openldap_thread_cond_t *cond )
92 {
93         SetEvent( *cond );
94         return( 0 );
95 }
96
97 int 
98 openldap_thread_cond_wait( openldap_thread_cond_t *cond, 
99                           openldap_thread_mutex_t *mutex )
100 {
101         ReleaseMutex( *mutex );
102         WaitForSingleObject( *cond, INFINITE );
103         WaitForSingleObject( *mutex, INFINITE );
104         return( 0 );
105 }
106
107 int
108 openldap_thread_cond_broadcast( openldap_thread_cond_t *cv )
109 {
110         SetEvent( *cv );
111         return( 0 );
112 }
113
114 int 
115 openldap_thread_mutex_init( openldap_thread_mutex_t *mutex,
116                            openldap_thread_mutexattr_t *attr )
117 {
118         *mutex = CreateMutex( NULL, 0, NULL );
119         return ( 0 );
120 }
121
122 int 
123 openldap_thread_mutex_destroy( openldap_thread_mutex_t *mutex )
124 {
125         CloseHandle( *mutex );
126         return ( 0 );   
127 }
128
129 int 
130 openldap_thread_mutex_lock( openldap_thread_mutex_t *mutex )
131 {
132         WaitForSingleObject( *mutex, INFINITE );
133         return ( 0 );
134 }
135
136 int 
137 openldap_thread_mutex_unlock( openldap_thread_mutex_t *mutex )
138 {
139         ReleaseMutex( *mutex );
140         return ( 0 );
141 }
142
143 int
144 openldap_thread_mutex_trylock( openldap_thread_mutex_t *mp )
145 {
146         DWORD status;
147
148         status = WaitForSingleObject( *mp, 0 );
149         if ( (status == WAIT_FAILED) || (status == WAIT_TIMEOUT) )
150                 return 0;
151         else
152                 return 1;
153 }
154
155 #endif