3 * Copyright 1998-2000 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"
21 ldap_int_thread_initialize( void )
27 ldap_int_thread_destroy( void )
33 ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
35 void *(*start_routine)( void *),
38 *thread = (ldap_pvt_thread_t)_beginthread( (void *) start_routine,
40 return ( (unsigned long)*thread == -1 ? -1 : 0 );
44 ldap_pvt_thread_exit( void *retval )
50 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
53 status = WaitForSingleObject( (HANDLE) thread, INFINITE );
54 return status == WAIT_FAILED ? -1 : 0;
58 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
64 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 SignalObjectAndWait( *mutex, *cond, INFINITE, FALSE );
96 WaitForSingleObject( *mutex, INFINITE );
101 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
108 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
110 *mutex = CreateMutex( NULL, 0, NULL );
115 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
117 CloseHandle( *mutex );
122 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
125 status = WaitForSingleObject( *mutex, INFINITE );
126 return status == WAIT_FAILED ? -1 : 0;
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 )
140 status = WaitForSingleObject( *mp, 0 );
141 return status == WAIT_FAILED || status == WAIT_TIMEOUT