4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
36 * Compatibility thread stuff needed for Solaris -> Linux port
39 typedef pthread_t thread_t;
40 typedef pthread_mutex_t mutex_t;
41 typedef pthread_cond_t cond_t;
42 typedef pthread_rwlock_t rwlock_t;
44 #define USYNC_THREAD 0
46 #define thr_self() (unsigned long)pthread_self()
47 #define thr_equal(a,b) pthread_equal(a,b)
48 #define thr_join(t,d,s) pthread_join(t,s)
49 #define thr_exit(r) pthread_exit(r)
50 #define _mutex_init(l,f,a) pthread_mutex_init(l,NULL)
51 #define _mutex_destroy(l) pthread_mutex_destroy(l)
52 #define mutex_lock(l) pthread_mutex_lock(l)
53 #define mutex_trylock(l) pthread_mutex_trylock(l)
54 #define mutex_unlock(l) pthread_mutex_unlock(l)
55 #define rwlock_init(l,f,a) pthread_rwlock_init(l,NULL)
56 #define rwlock_destroy(l) pthread_rwlock_destroy(l)
57 #define rw_rdlock(l) pthread_rwlock_rdlock(l)
58 #define rw_wrlock(l) pthread_rwlock_wrlock(l)
59 #define rw_tryrdlock(l) pthread_rwlock_tryrdlock(l)
60 #define rw_trywrlock(l) pthread_rwlock_trywrlock(l)
61 #define rw_unlock(l) pthread_rwlock_unlock(l)
62 #define cond_init(l,f,a) pthread_cond_init(l,NULL)
63 #define cond_destroy(l) pthread_cond_destroy(l)
64 #define cond_wait(l,m) pthread_cond_wait(l,m)
65 #define cond_signal(l) pthread_cond_signal(l)
66 #define cond_broadcast(l) pthread_cond_broadcast(l)
68 #define THR_BOUND 0x00000001 /* = PTHREAD_SCOPE_SYSTEM */
69 #define THR_NEW_LWP 0x00000002
70 #define THR_DETACHED 0x00000040 /* = PTHREAD_CREATE_DETACHED */
71 #define THR_SUSPENDED 0x00000080
72 #define THR_DAEMON 0x00000100
75 thr_create(void *stack_base, size_t stack_size, void *(*start_func) (void*),
76 void *arg, long flags, thread_t *new_thread_ID)
80 assert(stack_base == NULL);
81 assert(stack_size == 0);
82 assert((flags & ~THR_BOUND & ~THR_DETACHED) == 0);
85 pthread_attr_init(&attr);
87 if(flags & THR_DETACHED)
88 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
90 /* This function ignores the THR_BOUND flag, since NPTL doesn't seem to support PTHREAD_SCOPE_PROCESS */
92 ret = pthread_create(new_thread_ID, &attr, start_func, arg);
94 pthread_attr_destroy(&attr);
99 #endif /* _THREAD_H */