1 /* $NetBSD: thr_thr.c,v 1.2 2021/08/14 16:14:56 christos Exp $ */ 2 3 /* thr_thr.c - wrappers around solaris threads */ 4 /* $OpenLDAP$ */ 5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 6 * 7 * Copyright 1998-2021 The OpenLDAP Foundation. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted only as authorized by the OpenLDAP 12 * Public License. 13 * 14 * A copy of this license is available in file LICENSE in the 15 * top-level directory of the distribution or, alternatively, at 16 * <http://www.OpenLDAP.org/license.html>. 17 */ 18 19 #include <sys/cdefs.h> 20 __RCSID("$NetBSD: thr_thr.c,v 1.2 2021/08/14 16:14:56 christos Exp $"); 21 22 #include "portable.h" 23 24 #if defined( HAVE_THR ) 25 26 #include "ldap_pvt_thread.h" /* Get the thread interface */ 27 #define LDAP_THREAD_IMPLEMENTATION 28 #include "ldap_thr_debug.h" /* May rename the symbols defined below */ 29 30 /******************* 31 * * 32 * Solaris Threads * 33 * * 34 *******************/ 35 36 int 37 ldap_int_thread_initialize( void ) 38 { 39 return 0; 40 } 41 42 int 43 ldap_int_thread_destroy( void ) 44 { 45 return 0; 46 } 47 48 #ifdef LDAP_THREAD_HAVE_SETCONCURRENCY 49 int 50 ldap_pvt_thread_set_concurrency(int n) 51 { 52 return thr_setconcurrency( n ); 53 } 54 #endif 55 56 #ifdef LDAP_THREAD_HAVE_GETCONCURRENCY 57 int 58 ldap_pvt_thread_get_concurrency(void) 59 { 60 return thr_getconcurrency(); 61 } 62 #endif 63 64 int 65 ldap_pvt_thread_create( ldap_pvt_thread_t * thread, 66 int detach, 67 void *(*start_routine)( void *), 68 void *arg) 69 { 70 return( thr_create( NULL, LDAP_PVT_THREAD_STACK_SIZE, start_routine, 71 arg, detach ? THR_DETACHED : 0, thread ) ); 72 } 73 74 void 75 ldap_pvt_thread_exit( void *retval ) 76 { 77 thr_exit( NULL ); 78 } 79 80 int ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return ) 81 { 82 thr_join( thread, NULL, thread_return ); 83 return 0; 84 } 85 86 int 87 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo ) 88 { 89 thr_kill( thread, signo ); 90 return 0; 91 } 92 93 int 94 ldap_pvt_thread_yield( void ) 95 { 96 thr_yield(); 97 return 0; 98 } 99 100 int 101 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond ) 102 { 103 return( cond_init( cond, USYNC_THREAD, NULL ) ); 104 } 105 106 int 107 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond ) 108 { 109 return( cond_signal( cond ) ); 110 } 111 112 int 113 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cv ) 114 { 115 return( cond_broadcast( cv ) ); 116 } 117 118 int 119 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond, 120 ldap_pvt_thread_mutex_t *mutex ) 121 { 122 return( cond_wait( cond, mutex ) ); 123 } 124 125 int 126 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cv ) 127 { 128 return( cond_destroy( cv ) ); 129 } 130 131 int 132 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex ) 133 { 134 return( mutex_init( mutex, USYNC_THREAD, NULL ) ); 135 } 136 137 int 138 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex ) 139 { 140 return( mutex_destroy( mutex ) ); 141 } 142 143 int 144 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex ) 145 { 146 return( mutex_lock( mutex ) ); 147 } 148 149 int 150 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex ) 151 { 152 return( mutex_unlock( mutex ) ); 153 } 154 155 int 156 ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mp ) 157 { 158 return( mutex_trylock( mp ) ); 159 } 160 161 int 162 ldap_pvt_thread_mutex_recursive_init( ldap_pvt_thread_mutex_t *mutex ) 163 { 164 return( mutex_init( mutex, USYNC_THREAD | LOCK_RECURSIVE, NULL ) ); 165 } 166 167 ldap_pvt_thread_t 168 ldap_pvt_thread_self( void ) 169 { 170 return thr_self(); 171 } 172 173 int 174 ldap_pvt_thread_key_create( ldap_pvt_thread_key_t *key ) 175 { 176 return thr_keycreate( key, NULL ); 177 } 178 179 int 180 ldap_pvt_thread_key_destroy( ldap_pvt_thread_key_t key ) 181 { 182 return( 0 ); 183 } 184 185 int 186 ldap_pvt_thread_key_setdata( ldap_pvt_thread_key_t key, void *data ) 187 { 188 return thr_setspecific( key, data ); 189 } 190 191 int 192 ldap_pvt_thread_key_getdata( ldap_pvt_thread_key_t key, void **data ) 193 { 194 return thr_getspecific( key, data ); 195 } 196 197 #endif /* HAVE_THR */ 198