xref: /illumos-gate/usr/src/head/thread.h (revision ab618543)
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 /*
23ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24ba3594baSGarrett D'Amore  *
25cb620785Sraf  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
27*ab618543SJohn Levon  *
28*ab618543SJohn Levon  * Copyright 2018 Joyent, Inc.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifndef	_THREAD_H
327c478bd9Sstevel@tonic-gate #define	_THREAD_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * thread.h:
367c478bd9Sstevel@tonic-gate  * definitions needed to use the thread interface except synchronization.
377c478bd9Sstevel@tonic-gate  * use <synch.h> for thread synchronization.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifndef _ASM
417c478bd9Sstevel@tonic-gate #include <sys/signal.h>
427c478bd9Sstevel@tonic-gate #include <sys/time.h>
437c478bd9Sstevel@tonic-gate #include <synch.h>
447c478bd9Sstevel@tonic-gate #endif	/* _ASM */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #ifdef __cplusplus
477c478bd9Sstevel@tonic-gate extern "C" {
487c478bd9Sstevel@tonic-gate #endif
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #ifndef _ASM
517c478bd9Sstevel@tonic-gate typedef unsigned int thread_t;
527c478bd9Sstevel@tonic-gate typedef unsigned int thread_key_t;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate extern int thr_create(void *, size_t, void *(*)(void *), void *, long,
557c478bd9Sstevel@tonic-gate 			thread_t *);
567c478bd9Sstevel@tonic-gate extern int thr_join(thread_t, thread_t *, void **);
577c478bd9Sstevel@tonic-gate extern int thr_setconcurrency(int);
587c478bd9Sstevel@tonic-gate extern int thr_getconcurrency(void);
597c478bd9Sstevel@tonic-gate extern void thr_exit(void *) __NORETURN;
607c478bd9Sstevel@tonic-gate extern thread_t thr_self(void);
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * the definition of thr_sigsetmask() is not strict ansi-c since sigset_t is
647c478bd9Sstevel@tonic-gate  * not in the strict ansi-c name space. Hence, include the prototype for
657c478bd9Sstevel@tonic-gate  * thr_sigsetmask() only if strict ansi-c conformance is not turned on.
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate #if !defined(_STRICT_STDC) || defined(__EXTENSIONS__)
687c478bd9Sstevel@tonic-gate extern int thr_sigsetmask(int, const sigset_t *, sigset_t *);
697c478bd9Sstevel@tonic-gate #endif
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * the definition of thr_stksegment() is not strict ansi-c since stack_t is
737c478bd9Sstevel@tonic-gate  * not in the strict ansi-c name space. Hence, include the prototype for
747c478bd9Sstevel@tonic-gate  * thr_stksegment() only if strict ansi-c conformance is not turned on.
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate #if !defined(_STRICT_STDC) || defined(__EXTENSIONS__)
777c478bd9Sstevel@tonic-gate extern int thr_stksegment(stack_t *);
787c478bd9Sstevel@tonic-gate #endif
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate extern int thr_main(void);
817c478bd9Sstevel@tonic-gate extern int thr_kill(thread_t, int);
827c478bd9Sstevel@tonic-gate extern int thr_suspend(thread_t);
837c478bd9Sstevel@tonic-gate extern int thr_continue(thread_t);
847c478bd9Sstevel@tonic-gate extern void thr_yield(void);
857c478bd9Sstevel@tonic-gate extern int thr_setprio(thread_t, int);
867c478bd9Sstevel@tonic-gate extern int thr_getprio(thread_t, int *);
877c478bd9Sstevel@tonic-gate extern int thr_keycreate(thread_key_t *, void(*)(void *));
88cb620785Sraf extern int thr_keycreate_once(thread_key_t *, void(*)(void *));
897c478bd9Sstevel@tonic-gate extern int thr_setspecific(thread_key_t, void *);
907c478bd9Sstevel@tonic-gate extern int thr_getspecific(thread_key_t, void **);
917c478bd9Sstevel@tonic-gate extern size_t thr_min_stack(void);
92*ab618543SJohn Levon extern int thr_getname(thread_t, char *, size_t);
93*ab618543SJohn Levon extern int thr_setname(thread_t, const char *);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #endif /* _ASM */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #define	THR_MIN_STACK	thr_min_stack()
987c478bd9Sstevel@tonic-gate /*
997c478bd9Sstevel@tonic-gate  * thread flags (one word bit mask)
1007c478bd9Sstevel@tonic-gate  */
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  * POSIX.1c Note:
1037c478bd9Sstevel@tonic-gate  * THR_BOUND is defined same as PTHREAD_SCOPE_SYSTEM in <pthread.h>
1047c478bd9Sstevel@tonic-gate  * THR_DETACHED is defined same as PTHREAD_CREATE_DETACHED in <pthread.h>
1057c478bd9Sstevel@tonic-gate  * Any changes in these definitions should be reflected in <pthread.h>
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate #define	THR_BOUND		0x00000001	/* = PTHREAD_SCOPE_SYSTEM */
1087c478bd9Sstevel@tonic-gate #define	THR_NEW_LWP		0x00000002
1097c478bd9Sstevel@tonic-gate #define	THR_DETACHED		0x00000040	/* = PTHREAD_CREATE_DETACHED */
1107c478bd9Sstevel@tonic-gate #define	THR_SUSPENDED		0x00000080
1117c478bd9Sstevel@tonic-gate #define	THR_DAEMON		0x00000100
1127c478bd9Sstevel@tonic-gate 
113cb620785Sraf /*
114cb620785Sraf  * The key to be created by thr_keycreate_once()
115cb620785Sraf  * must be statically initialized with THR_ONCE_KEY.
116cb620785Sraf  * This must be the same as PTHREAD_ONCE_KEY_NP in <pthread.h>
117cb620785Sraf  */
118cb620785Sraf #define	THR_ONCE_KEY	(thread_key_t)(-1)
119cb620785Sraf 
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate  * The available register states returned by thr_getstate().
1227c478bd9Sstevel@tonic-gate  */
1237c478bd9Sstevel@tonic-gate #define	TRS_VALID	0
1247c478bd9Sstevel@tonic-gate #define	TRS_NONVOLATILE	1
1257c478bd9Sstevel@tonic-gate #define	TRS_LWPID	2
1267c478bd9Sstevel@tonic-gate #define	TRS_INVALID	3
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate #endif
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate #endif	/* _THREAD_H */
133