17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5cb620785Sraf * Common Development and Distribution License (the "License"). 6cb620785Sraf * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21cb620785Sraf 227c478bd9Sstevel@tonic-gate /* 23*ba3594baSGarrett D'Amore * Copyright 2014 Garrett D'Amore <garrett@damore.org> 24*ba3594baSGarrett D'Amore * 25cb620785Sraf * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 267c478bd9Sstevel@tonic-gate * Use is subject to license terms. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #ifndef _THREAD_H 307c478bd9Sstevel@tonic-gate #define _THREAD_H 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate /* 337c478bd9Sstevel@tonic-gate * thread.h: 347c478bd9Sstevel@tonic-gate * definitions needed to use the thread interface except synchronization. 357c478bd9Sstevel@tonic-gate * use <synch.h> for thread synchronization. 367c478bd9Sstevel@tonic-gate */ 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #ifndef _ASM 397c478bd9Sstevel@tonic-gate #include <sys/signal.h> 407c478bd9Sstevel@tonic-gate #include <sys/time.h> 417c478bd9Sstevel@tonic-gate #include <synch.h> 427c478bd9Sstevel@tonic-gate #endif /* _ASM */ 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #ifdef __cplusplus 457c478bd9Sstevel@tonic-gate extern "C" { 467c478bd9Sstevel@tonic-gate #endif 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #ifndef _ASM 497c478bd9Sstevel@tonic-gate typedef unsigned int thread_t; 507c478bd9Sstevel@tonic-gate typedef unsigned int thread_key_t; 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate extern int thr_create(void *, size_t, void *(*)(void *), void *, long, 537c478bd9Sstevel@tonic-gate thread_t *); 547c478bd9Sstevel@tonic-gate extern int thr_join(thread_t, thread_t *, void **); 557c478bd9Sstevel@tonic-gate extern int thr_setconcurrency(int); 567c478bd9Sstevel@tonic-gate extern int thr_getconcurrency(void); 577c478bd9Sstevel@tonic-gate extern void thr_exit(void *) __NORETURN; 587c478bd9Sstevel@tonic-gate extern thread_t thr_self(void); 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate /* 617c478bd9Sstevel@tonic-gate * the definition of thr_sigsetmask() is not strict ansi-c since sigset_t is 627c478bd9Sstevel@tonic-gate * not in the strict ansi-c name space. Hence, include the prototype for 637c478bd9Sstevel@tonic-gate * thr_sigsetmask() only if strict ansi-c conformance is not turned on. 647c478bd9Sstevel@tonic-gate */ 657c478bd9Sstevel@tonic-gate #if !defined(_STRICT_STDC) || defined(__EXTENSIONS__) 667c478bd9Sstevel@tonic-gate extern int thr_sigsetmask(int, const sigset_t *, sigset_t *); 677c478bd9Sstevel@tonic-gate #endif 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate /* 707c478bd9Sstevel@tonic-gate * the definition of thr_stksegment() is not strict ansi-c since stack_t is 717c478bd9Sstevel@tonic-gate * not in the strict ansi-c name space. Hence, include the prototype for 727c478bd9Sstevel@tonic-gate * thr_stksegment() only if strict ansi-c conformance is not turned on. 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate #if !defined(_STRICT_STDC) || defined(__EXTENSIONS__) 757c478bd9Sstevel@tonic-gate extern int thr_stksegment(stack_t *); 767c478bd9Sstevel@tonic-gate #endif 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate extern int thr_main(void); 797c478bd9Sstevel@tonic-gate extern int thr_kill(thread_t, int); 807c478bd9Sstevel@tonic-gate extern int thr_suspend(thread_t); 817c478bd9Sstevel@tonic-gate extern int thr_continue(thread_t); 827c478bd9Sstevel@tonic-gate extern void thr_yield(void); 837c478bd9Sstevel@tonic-gate extern int thr_setprio(thread_t, int); 847c478bd9Sstevel@tonic-gate extern int thr_getprio(thread_t, int *); 857c478bd9Sstevel@tonic-gate extern int thr_keycreate(thread_key_t *, void(*)(void *)); 86cb620785Sraf extern int thr_keycreate_once(thread_key_t *, void(*)(void *)); 877c478bd9Sstevel@tonic-gate extern int thr_setspecific(thread_key_t, void *); 887c478bd9Sstevel@tonic-gate extern int thr_getspecific(thread_key_t, void **); 897c478bd9Sstevel@tonic-gate extern size_t thr_min_stack(void); 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate #endif /* _ASM */ 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate #define THR_MIN_STACK thr_min_stack() 947c478bd9Sstevel@tonic-gate /* 957c478bd9Sstevel@tonic-gate * thread flags (one word bit mask) 967c478bd9Sstevel@tonic-gate */ 977c478bd9Sstevel@tonic-gate /* 987c478bd9Sstevel@tonic-gate * POSIX.1c Note: 997c478bd9Sstevel@tonic-gate * THR_BOUND is defined same as PTHREAD_SCOPE_SYSTEM in <pthread.h> 1007c478bd9Sstevel@tonic-gate * THR_DETACHED is defined same as PTHREAD_CREATE_DETACHED in <pthread.h> 1017c478bd9Sstevel@tonic-gate * Any changes in these definitions should be reflected in <pthread.h> 1027c478bd9Sstevel@tonic-gate */ 1037c478bd9Sstevel@tonic-gate #define THR_BOUND 0x00000001 /* = PTHREAD_SCOPE_SYSTEM */ 1047c478bd9Sstevel@tonic-gate #define THR_NEW_LWP 0x00000002 1057c478bd9Sstevel@tonic-gate #define THR_DETACHED 0x00000040 /* = PTHREAD_CREATE_DETACHED */ 1067c478bd9Sstevel@tonic-gate #define THR_SUSPENDED 0x00000080 1077c478bd9Sstevel@tonic-gate #define THR_DAEMON 0x00000100 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate /* 110cb620785Sraf * The key to be created by thr_keycreate_once() 111cb620785Sraf * must be statically initialized with THR_ONCE_KEY. 112cb620785Sraf * This must be the same as PTHREAD_ONCE_KEY_NP in <pthread.h> 113cb620785Sraf */ 114cb620785Sraf #define THR_ONCE_KEY (thread_key_t)(-1) 115cb620785Sraf 116cb620785Sraf /* 1177c478bd9Sstevel@tonic-gate * The available register states returned by thr_getstate(). 1187c478bd9Sstevel@tonic-gate */ 1197c478bd9Sstevel@tonic-gate #define TRS_VALID 0 1207c478bd9Sstevel@tonic-gate #define TRS_NONVOLATILE 1 1217c478bd9Sstevel@tonic-gate #define TRS_LWPID 2 1227c478bd9Sstevel@tonic-gate #define TRS_INVALID 3 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1257c478bd9Sstevel@tonic-gate } 1267c478bd9Sstevel@tonic-gate #endif 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate #endif /* _THREAD_H */ 129