2 * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
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.
11 /* thr_nt.c - wrapper around NT threads */
14 #include "ldap_pvt_thread.h"
16 #if defined( HAVE_NT_THREADS )
19 ldap_pvt_thread_initialize( void )
25 ldap_pvt_thread_destroy( void )
31 ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
33 void *(*start_routine)( void *),
36 *thread = (ldap_pvt_thread_t)_beginthread( (void *) start_routine,
38 return ( (unsigned long)*thread == -1 ? -1 : 0 );
42 ldap_pvt_thread_exit( void *retval )
48 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
51 status = WaitForSingleObject( (HANDLE) thread, INFINITE );
52 if (status == WAIT_FAILED) {
59 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
65 ldap_pvt_thread_yield( void )
71 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
73 *cond = CreateEvent( NULL, FALSE, FALSE, NULL );
78 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cv )
85 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
92 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond,
93 ldap_pvt_thread_mutex_t *mutex )
95 ReleaseMutex( *mutex );
96 WaitForSingleObject( *cond, INFINITE );
97 WaitForSingleObject( *mutex, INFINITE );
102 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cv )
109 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
111 *mutex = CreateMutex( NULL, 0, NULL );
116 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
118 CloseHandle( *mutex );
123 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
125 WaitForSingleObject( *mutex, INFINITE );
130 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
132 ReleaseMutex( *mutex );
137 ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mp )
141 status = WaitForSingleObject( *mp, 0 );
142 if ( (status == WAIT_FAILED) || (status == WAIT_TIMEOUT) )