1 /* $OpenLDAP$ */ 2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 3 * 4 * Copyright 1998-2021 The OpenLDAP Foundation. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted only as authorized by the OpenLDAP 9 * Public License. 10 * 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>. 14 */ 15 16 #include "portable.h" 17 18 #include <stdio.h> 19 20 #include <ac/stdarg.h> 21 #include <ac/stdlib.h> 22 #include <ac/string.h> 23 #include <ac/unistd.h> 24 25 #include "ldap-int.h" 26 27 #ifdef LDAP_R_COMPILE 28 29 #include "ldap_pvt_thread.h" /* Get the thread interface */ 30 #include "ldap_thr_debug.h" /* May redirect thread initialize/destroy calls */ 31 32 33 /* 34 * Common LDAP thread routines 35 * see thr_*.c for implementation specific routines 36 * see rdwr.c for generic reader/writer lock implementation 37 * see tpool.c for generic thread pool implementation 38 */ 39 40 ldap_pvt_thread_initialize(void)41int ldap_pvt_thread_initialize( void ) 42 { 43 int rc; 44 static int init = 0; 45 ldap_pvt_thread_t tid; 46 47 /* we only get one shot at this */ 48 if( init++ ) return -1; 49 50 rc = ldap_int_thread_initialize(); 51 if( rc ) return rc; 52 53 #ifndef LDAP_THREAD_HAVE_TPOOL 54 rc = ldap_int_thread_pool_startup(); 55 if( rc ) return rc; 56 #endif 57 58 /* kludge to pull symbol definitions in */ 59 tid = ldap_pvt_thread_self(); 60 return 0; 61 } 62 ldap_pvt_thread_destroy(void)63int ldap_pvt_thread_destroy( void ) 64 { 65 #ifndef LDAP_THREAD_HAVE_TPOOL 66 (void) ldap_int_thread_pool_shutdown(); 67 #endif 68 return ldap_int_thread_destroy(); 69 } 70 71 72 /* 73 * Default implementations of some LDAP thread routines 74 */ 75 76 #define LDAP_THREAD_IMPLEMENTATION 77 #include "ldap_thr_debug.h" /* May rename the symbols defined below */ 78 79 80 #ifndef LDAP_THREAD_HAVE_GETCONCURRENCY 81 int ldap_pvt_thread_get_concurrency(void)82ldap_pvt_thread_get_concurrency ( void ) 83 { 84 return 1; 85 } 86 #endif 87 88 #ifndef LDAP_THREAD_HAVE_SETCONCURRENCY 89 int ldap_pvt_thread_set_concurrency(int concurrency)90ldap_pvt_thread_set_concurrency ( int concurrency ) 91 { 92 return 1; 93 } 94 #endif 95 96 #ifndef LDAP_THREAD_HAVE_SLEEP 97 /* 98 * Here we assume we have fully preemptive threads and that sleep() 99 * does the right thing. 100 */ 101 unsigned int ldap_pvt_thread_sleep(unsigned int interval)102ldap_pvt_thread_sleep( 103 unsigned int interval 104 ) 105 { 106 sleep( interval ); 107 return 0; 108 } 109 #endif 110 111 #endif /* LDAP_R_COMPILE */ 112