1/* $NetBSD: thr_cthreads.c,v 1.1.1.3 2010/12/12 15:21:42 adam Exp $ */ 2 3/* thr_cthreads.c - wrapper for mach cthreads */ 4/* OpenLDAP: pkg/ldap/libraries/libldap_r/thr_cthreads.c,v 1.20.2.6 2010/04/13 20:23:02 kurt Exp */ 5/* This work is part of OpenLDAP Software <http://www.openldap.org/>. 6 * 7 * Copyright 1998-2010 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/* This work was initially developed by Luke Howard for inclusion 19 * in U-MICH LDAP 3.3. 20 */ 21 22#include "portable.h" 23 24#if defined( HAVE_MACH_CTHREADS ) 25#include "ldap_pvt_thread.h" /* Get the thread interface */ 26#define LDAP_THREAD_IMPLEMENTATION 27#include "ldap_thr_debug.h" /* May rename the symbols defined below */ 28 29int 30ldap_int_thread_initialize( void ) 31{ 32 return 0; 33} 34 35int 36ldap_int_thread_destroy( void ) 37{ 38 return 0; 39} 40 41int 42ldap_pvt_thread_create( ldap_pvt_thread_t * thread, 43 int detach, 44 void *(*start_routine)( void *), void *arg) 45{ 46 *thread = cthread_fork( (cthread_fn_t) start_routine, arg); 47 return ( *thread == NULL ? -1 : 0 ); 48} 49 50void 51ldap_pvt_thread_exit( void *retval ) 52{ 53 cthread_exit( (any_t) retval ); 54} 55 56int 57ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return ) 58{ 59 void *status; 60 status = (void *) cthread_join ( thread ); 61 if (thread_return != NULL) 62 { 63 *thread_return = status; 64 } 65 return 0; 66} 67 68int 69ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo ) 70{ 71 return 0; 72} 73 74int 75ldap_pvt_thread_yield( void ) 76{ 77 cthread_yield(); 78 return 0; 79} 80 81int 82ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond ) 83{ 84 condition_init( cond ); 85 return( 0 ); 86} 87 88int 89ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cond ) 90{ 91 condition_clear( cond ); 92 return( 0 ); 93} 94 95int 96ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond ) 97{ 98 condition_signal( cond ); 99 return( 0 ); 100} 101 102int 103ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond ) 104{ 105 condition_broadcast( cond ); 106 return( 0 ); 107} 108 109int 110ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond, 111 ldap_pvt_thread_mutex_t *mutex ) 112{ 113 condition_wait( cond, mutex ); 114 return( 0 ); 115} 116 117int 118ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex ) 119{ 120 mutex_init( mutex ); 121 mutex->name = NULL; 122 return ( 0 ); 123} 124 125int 126ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex ) 127{ 128 mutex_clear( mutex ); 129 return ( 0 ); 130} 131 132int 133ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex ) 134{ 135 mutex_lock( mutex ); 136 return ( 0 ); 137} 138 139int 140ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex ) 141{ 142 mutex_unlock( mutex ); 143 return ( 0 ); 144} 145 146int 147ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mutex ) 148{ 149 return mutex_try_lock( mutex ); 150} 151 152ldap_pvt_thread_t 153ldap_pvt_thread_self( void ) 154{ 155 return cthread_self(); 156} 157 158int 159ldap_pvt_thread_key_create( ldap_pvt_thread_key_t *key ) 160{ 161 return cthread_keycreate( key ); 162} 163 164int 165ldap_pvt_thread_key_destroy( ldap_pvt_thread_key_t key ) 166{ 167 return( 0 ); 168} 169 170int 171ldap_pvt_thread_key_setdata( ldap_pvt_thread_key_t key, void *data ) 172{ 173 return cthread_setspecific( key, data ); 174} 175 176int 177ldap_pvt_thread_key_getdata( ldap_pvt_thread_key_t key, void **data ) 178{ 179 return cthread_getspecific( key, data ); 180} 181 182#endif /* HAVE_MACH_CTHREADS */ 183