Path: blob/main/cddl/contrib/opensolaris/head/thread.h
39488 views
/*1* CDDL HEADER START2*3* The contents of this file are subject to the terms of the4* Common Development and Distribution License (the "License").5* You may not use this file except in compliance with the License.6*7* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE8* or http://www.opensolaris.org/os/licensing.9* See the License for the specific language governing permissions10* and limitations under the License.11*12* When distributing Covered Code, include this CDDL HEADER in each13* file and include the License file at usr/src/OPENSOLARIS.LICENSE.14* If applicable, add the following below this CDDL HEADER, with the15* fields enclosed by brackets "[]" replaced with your own identifying16* information: Portions Copyright [yyyy] [name of copyright owner]17*18* CDDL HEADER END19*/2021/*22* Copyright 2014 Garrett D'Amore <[email protected]>23*24* Copyright 2007 Sun Microsystems, Inc. All rights reserved.25* Use is subject to license terms.26*/2728#ifndef _THREAD_H29#define _THREAD_H3031#include <pthread.h>32#include <pthread_np.h>33#include <assert.h>3435/*36* Compatibility thread stuff needed for Solaris -> Linux port37*/3839typedef pthread_t thread_t;40typedef pthread_mutex_t mutex_t;41typedef pthread_cond_t cond_t;42typedef pthread_rwlock_t rwlock_t;4344#define USYNC_THREAD 04546#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)6768#define THR_BOUND 0x00000001 /* = PTHREAD_SCOPE_SYSTEM */69#define THR_NEW_LWP 0x0000000270#define THR_DETACHED 0x00000040 /* = PTHREAD_CREATE_DETACHED */71#define THR_SUSPENDED 0x0000008072#define THR_DAEMON 0x000001007374static __inline int75thr_create(void *stack_base, size_t stack_size, void *(*start_func) (void*),76void *arg, long flags, thread_t *new_thread_ID)77{78pthread_t dummy;79int ret;8081assert(stack_base == NULL);82assert(stack_size == 0);83assert((flags & ~THR_BOUND & ~THR_DETACHED) == 0);8485pthread_attr_t attr;86pthread_attr_init(&attr);8788if (flags & THR_DETACHED)89pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);9091if (new_thread_ID == NULL)92new_thread_ID = &dummy;9394/* This function ignores the THR_BOUND flag, since NPTL doesn't seem to support PTHREAD_SCOPE_PROCESS */9596ret = pthread_create(new_thread_ID, &attr, start_func, arg);9798pthread_attr_destroy(&attr);99100return (ret);101}102103#endif /* _THREAD_H */104105106