]> git.sur5r.net Git - openldap/blob - libraries/libldap_r/thr_nt.c
Fixed typo in
[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 #include <process.h>
18
19 int
20 ldap_pvt_thread_initialize( void )
21 {
22         return 0;
23 }
24
25 int 
26 ldap_pvt_thread_create( ldap_pvt_thread_t * thread, 
27         int detach,
28         void *(*start_routine)( void *),
29         void *arg)
30 {
31         *thread = (ldap_pvt_thread_t)_beginthread( (void *) start_routine, 
32                                                 0, arg );
33          return ( (unsigned long)*thread == -1 ? -1 : 0 );
34 }
35         
36 void 
37 ldap_pvt_thread_exit( void *retval )
38 {
39         _endthread( );
40 }
41
42 int 
43 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
44 {
45         DWORD status;
46         status = WaitForSingleObject( thread, INFINITE );
47         if (status == WAIT_FAILED) {
48                 return -1;
49         }
50         return 0;
51 }
52
53 int 
54 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
55 {
56         return 0;
57 }
58
59 int 
60 ldap_pvt_thread_yield( void )
61 {
62         return 0;
63 }
64
65 int 
66 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
67 {
68         *cond = CreateEvent( NULL, FALSE, FALSE, NULL );
69         return( 0 );
70 }
71
72 int
73 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cv )
74 {
75         CloseHandle( *cv );
76         return( 0 );
77 }
78
79 int 
80 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
81 {
82         SetEvent( *cond );
83         return( 0 );
84 }
85
86 int 
87 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond, 
88                           ldap_pvt_thread_mutex_t *mutex )
89 {
90         ReleaseMutex( *mutex );
91         WaitForSingleObject( *cond, INFINITE );
92         WaitForSingleObject( *mutex, INFINITE );
93         return( 0 );
94 }
95
96 int
97 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cv )
98 {
99         SetEvent( *cv );
100         return( 0 );
101 }
102
103 int 
104 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
105 {
106         *mutex = CreateMutex( NULL, 0, NULL );
107         return ( 0 );
108 }
109
110 int 
111 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
112 {
113         CloseHandle( *mutex );
114         return ( 0 );   
115 }
116
117 int 
118 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
119 {
120         WaitForSingleObject( *mutex, INFINITE );
121         return ( 0 );
122 }
123
124 int 
125 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
126 {
127         ReleaseMutex( *mutex );
128         return ( 0 );
129 }
130
131 int
132 ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mp )
133 {
134         DWORD status;
135
136         status = WaitForSingleObject( *mp, 0 );
137         if ( (status == WAIT_FAILED) || (status == WAIT_TIMEOUT) )
138                 return 0;
139         else
140                 return 1;
141 }
142
143 #endif