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