3 * Copyright 1998-2002 The OpenLDAP Foundation, Redwood City, California, USA
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.
12 /* thr_nt.c - wrapper around NT threads */
16 #if defined( HAVE_NT_THREADS )
18 #include "ldap_pvt_thread.h"
20 /* mingw compiler very sensitive about getting prototypes right */
21 typedef unsigned __stdcall thrfunc_t(void *);
24 ldap_int_thread_initialize( void )
30 ldap_int_thread_destroy( void )
36 ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
38 void *(*start_routine)( void *),
44 thd = (HANDLE) _beginthreadex(NULL, 0, (thrfunc_t *) start_routine,
47 *thread = (ldap_pvt_thread_t) thd;
49 return thd == NULL ? -1 : 0;
53 ldap_pvt_thread_exit( void *retval )
59 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
62 status = WaitForSingleObject( (HANDLE) thread, INFINITE );
63 return status == WAIT_FAILED ? -1 : 0;
67 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
73 ldap_pvt_thread_yield( void )
80 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
82 *cond = CreateEvent( NULL, FALSE, FALSE, NULL );
87 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cv )
94 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
101 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond,
102 ldap_pvt_thread_mutex_t *mutex )
104 SignalObjectAndWait( *mutex, *cond, INFINITE, FALSE );
105 WaitForSingleObject( *mutex, INFINITE );
110 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
117 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
119 *mutex = CreateMutex( NULL, 0, NULL );
124 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
126 CloseHandle( *mutex );
131 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
134 status = WaitForSingleObject( *mutex, INFINITE );
135 return status == WAIT_FAILED ? -1 : 0;
139 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
141 ReleaseMutex( *mutex );
146 ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mp )
149 status = WaitForSingleObject( *mp, 0 );
150 return status == WAIT_FAILED || status == WAIT_TIMEOUT