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