2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2012 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;
42 ldap_pvt_thread_t tid;
44 /* we only get one shot at this */
45 if( init++ ) return -1;
47 rc = ldap_int_thread_initialize();
50 #ifndef LDAP_THREAD_HAVE_TPOOL
51 rc = ldap_int_thread_pool_startup();
55 /* kludge to pull symbol definitions in */
56 ldap_pvt_thread_rmutex_init( &rm );
57 tid = ldap_pvt_thread_self();
58 ldap_pvt_thread_rmutex_lock( &rm, tid );
59 ldap_pvt_thread_rmutex_trylock( &rm, tid );
60 ldap_pvt_thread_rmutex_unlock( &rm, tid );
61 ldap_pvt_thread_rmutex_unlock( &rm, tid );
62 ldap_pvt_thread_rmutex_destroy( &rm );
67 int ldap_pvt_thread_destroy( void )
69 #ifndef LDAP_THREAD_HAVE_TPOOL
70 (void) ldap_int_thread_pool_shutdown();
72 return ldap_int_thread_destroy();
77 * Default implementations of some LDAP thread routines
80 #define LDAP_THREAD_IMPLEMENTATION
81 #include "ldap_thr_debug.h" /* May rename the symbols defined below */
84 #ifndef LDAP_THREAD_HAVE_GETCONCURRENCY
86 ldap_pvt_thread_get_concurrency ( void )
92 #ifndef LDAP_THREAD_HAVE_SETCONCURRENCY
94 ldap_pvt_thread_set_concurrency ( int concurrency )
100 #ifndef LDAP_THREAD_HAVE_SLEEP
102 * Here we assume we have fully preemptive threads and that sleep()
103 * does the right thing.
106 ldap_pvt_thread_sleep(
107 unsigned int interval