home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ldapsdk.zip / libraries / libldap_r / thr_nt.c < prev    next >
C/C++ Source or Header  |  2001-05-17  |  3KB  |  153 lines

  1. /* $OpenLDAP: pkg/ldap/libraries/libldap_r/thr_nt.c,v 1.8.2.5 2001/05/16 17:51:47 kurt Exp $ */
  2. /*
  3.  * Copyright 1998-2000 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. int
  21. ldap_int_thread_initialize( void )
  22. {
  23.     return 0;
  24. }
  25.  
  26. int
  27. ldap_int_thread_destroy( void )
  28. {
  29.     return 0;
  30. }
  31.  
  32. int 
  33. ldap_pvt_thread_create( ldap_pvt_thread_t * thread, 
  34.     int detach,
  35.     void *(*start_routine)( void *),
  36.     void *arg)
  37. {
  38.     unsigned long tid;
  39.     HANDLE thd;
  40.  
  41.     thd = _beginthreadex( NULL, 0,
  42.         (LPTHREAD_START_ROUTINE) start_routine, arg,
  43.         0, &tid );
  44.  
  45.     *thread = (ldap_pvt_thread_t) thd;
  46.  
  47.      return thd == NULL ? -1 : 0;
  48. }
  49.     
  50. void 
  51. ldap_pvt_thread_exit( void *retval )
  52. {
  53.     _endthread( );
  54. }
  55.  
  56. int 
  57. ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
  58. {
  59.     DWORD status;
  60.     status = WaitForSingleObject( (HANDLE) thread, INFINITE );
  61.     return status == WAIT_FAILED ? -1 : 0;
  62. }
  63.  
  64. int 
  65. ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
  66. {
  67.     return 0;
  68. }
  69.  
  70. int 
  71. ldap_pvt_thread_yield( void )
  72. {
  73.     Sleep( 0 );
  74.     return 0;
  75. }
  76.  
  77. int 
  78. ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
  79. {
  80.     *cond = CreateEvent( NULL, FALSE, FALSE, NULL );
  81.     return( 0 );
  82. }
  83.  
  84. int
  85. ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cv )
  86. {
  87.     CloseHandle( *cv );
  88.     return( 0 );
  89. }
  90.  
  91. int 
  92. ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
  93. {
  94.     SetEvent( *cond );
  95.     return( 0 );
  96. }
  97.  
  98. int 
  99. ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond, 
  100.     ldap_pvt_thread_mutex_t *mutex )
  101. {
  102.     SignalObjectAndWait( *mutex, *cond, INFINITE, FALSE );
  103.     WaitForSingleObject( *mutex, INFINITE );
  104.     return( 0 );
  105. }
  106.  
  107. int
  108. ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
  109. {
  110.     SetEvent( *cond );
  111.     return( 0 );
  112. }
  113.  
  114. int 
  115. ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
  116. {
  117.     *mutex = CreateMutex( NULL, 0, NULL );
  118.     return ( 0 );
  119. }
  120.  
  121. int 
  122. ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
  123. {
  124.     CloseHandle( *mutex );
  125.     return ( 0 );    
  126. }
  127.  
  128. int 
  129. ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
  130. {
  131.     DWORD status;
  132.     status = WaitForSingleObject( *mutex, INFINITE );
  133.     return status == WAIT_FAILED ? -1 : 0;
  134. }
  135.  
  136. int 
  137. ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
  138. {
  139.     ReleaseMutex( *mutex );
  140.     return ( 0 );
  141. }
  142.  
  143. int
  144. ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mp )
  145. {
  146.     DWORD status;
  147.     status = WaitForSingleObject( *mp, 0 );
  148.     return status == WAIT_FAILED || status == WAIT_TIMEOUT
  149.         ? -1 : 0;
  150. }
  151.  
  152. #endif
  153.