2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2006 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/stdarg.h>
21 #include <ac/stdlib.h>
22 #include <ac/string.h>
23 #include <ac/unistd.h>
25 #include "ldap_pvt_thread.h" /* Get the thread interface */
26 #include "ldap_thr_debug.h" /* May redirect thread initialize/destroy calls */
30 * Common LDAP thread routines
31 * see thr_*.c for implementation specific routines
32 * see rdwr.c for generic reader/writer lock implementation
33 * see tpool.c for generic thread pool implementation
37 int ldap_pvt_thread_initialize( void )
41 ldap_pvt_thread_rmutex_t rm;
43 /* we only get one shot at this */
44 if( init++ ) return -1;
46 rc = ldap_int_thread_initialize();
49 #ifndef LDAP_THREAD_HAVE_TPOOL
50 rc = ldap_int_thread_pool_startup();
54 /* kludge to pull symbol definitions in */
55 ldap_pvt_thread_rmutex_init( &rm );
56 ldap_pvt_thread_rmutex_lock( &rm );
57 ldap_pvt_thread_rmutex_trylock( &rm );
58 ldap_pvt_thread_rmutex_unlock( &rm );
59 ldap_pvt_thread_rmutex_unlock( &rm );
60 ldap_pvt_thread_rmutex_destroy( &rm );
65 int ldap_pvt_thread_destroy( void )
67 #ifndef LDAP_THREAD_HAVE_TPOOL
68 (void) ldap_int_thread_pool_shutdown();
70 return ldap_int_thread_destroy();
75 * Default implementations of some LDAP thread routines
78 #define LDAP_THREAD_IMPLEMENTATION
79 #include "ldap_thr_debug.h" /* May rename the symbols defined below */
82 #ifndef LDAP_THREAD_HAVE_GETCONCURRENCY
84 ldap_pvt_thread_get_concurrency ( void )
90 #ifndef LDAP_THREAD_HAVE_SETCONCURRENCY
92 ldap_pvt_thread_set_concurrency ( int concurrency )
98 #ifndef LDAP_THREAD_HAVE_SLEEP
100 * Here we assume we have fully preemptive threads and that sleep()
101 * does the right thing.
104 ldap_pvt_thread_sleep(
105 unsigned int interval