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