]> git.sur5r.net Git - openldap/blob - libraries/libldap_r/thr_nt.c
Use ldap_pvt_strtok directly and unconditionally.
[openldap] / libraries / libldap_r / thr_nt.c
1 /*
2  * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted only
6  * as authorized by the OpenLDAP Public License.  A copy of this
7  * license is available at http://www.OpenLDAP.org/license.html or
8  * in file LICENSE in the top-level directory of the distribution.
9  */
10
11 /* thr_nt.c - wrapper around NT threads */
12
13 #include "portable.h"
14 #include "ldap_pvt_thread.h"
15
16 #if defined( HAVE_NT_THREADS )
17
18 int
19 ldap_pvt_thread_initialize( void )
20 {
21         return 0;
22 }
23
24 int 
25 ldap_pvt_thread_create( ldap_pvt_thread_t * thread, 
26         int detach,
27         void *(*start_routine)( void *),
28         void *arg)
29 {
30         *thread = (ldap_pvt_thread_t)_beginthread( (void *) start_routine, 
31                                                 0, arg );
32          return ( (unsigned long)*thread == -1 ? -1 : 0 );
33 }
34         
35 void 
36 ldap_pvt_thread_exit( void *retval )
37 {
38         _endthread( );
39 }
40
41 int 
42 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
43 {
44         DWORD status;
45         status = WaitForSingleObject( thread, INFINITE );
46         if (status == WAIT_FAILED) {
47                 return -1;
48         }
49         return 0;
50 }
51
52 int 
53 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
54 {
55         return 0;
56 }
57
58 int 
59 ldap_pvt_thread_yield( void )
60 {
61         return 0;
62 }
63
64 int 
65 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
66 {
67         *cond = CreateEvent( NULL, FALSE, FALSE, NULL );
68         return( 0 );
69 }
70
71 int
72 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cv )
73 {
74         CloseHandle( *cv );
75         return( 0 );
76 }
77
78 int 
79 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
80 {
81         SetEvent( *cond );
82         return( 0 );
83 }
84
85 int 
86 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond, 
87                           ldap_pvt_thread_mutex_t *mutex )
88 {
89         ReleaseMutex( *mutex );
90         WaitForSingleObject( *cond, INFINITE );
91         WaitForSingleObject( *mutex, INFINITE );
92         return( 0 );
93 }
94
95 int
96 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cv )
97 {
98         SetEvent( *cv );
99         return( 0 );
100 }
101
102 int 
103 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
104 {
105         *mutex = CreateMutex( NULL, 0, NULL );
106         return ( 0 );
107 }
108
109 int 
110 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
111 {
112         CloseHandle( *mutex );
113         return ( 0 );   
114 }
115
116 int 
117 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
118 {
119         WaitForSingleObject( *mutex, INFINITE );
120         return ( 0 );
121 }
122
123 int 
124 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
125 {
126         ReleaseMutex( *mutex );
127         return ( 0 );
128 }
129
130 int
131 ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mp )
132 {
133         DWORD status;
134
135         status = WaitForSingleObject( *mp, 0 );
136         if ( (status == WAIT_FAILED) || (status == WAIT_TIMEOUT) )
137                 return 0;
138         else
139                 return 1;
140 }
141
142 #endif