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