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