blob: 704174d4117971e8f69c0ec19d491b4efa94d8de [file] [log] [blame]
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -07001/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
rafcb620782007-03-20 17:29:57 -07005 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -07007 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
rafcb620782007-03-20 17:29:57 -070021
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070022/*
Garrett D'Amoreba3594b2014-08-02 18:23:32 -070023 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 *
rafcb620782007-03-20 17:29:57 -070025 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070026 * Use is subject to license terms.
John Levonab618542018-10-08 15:34:11 +010027 *
28 * Copyright 2018 Joyent, Inc.
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070029 */
30
31#ifndef _THREAD_H
32#define _THREAD_H
33
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070034/*
35 * thread.h:
36 * definitions needed to use the thread interface except synchronization.
37 * use <synch.h> for thread synchronization.
38 */
39
40#ifndef _ASM
41#include <sys/signal.h>
42#include <sys/time.h>
43#include <synch.h>
44#endif /* _ASM */
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50#ifndef _ASM
51typedef unsigned int thread_t;
52typedef unsigned int thread_key_t;
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070053
54extern int thr_create(void *, size_t, void *(*)(void *), void *, long,
55 thread_t *);
56extern int thr_join(thread_t, thread_t *, void **);
57extern int thr_setconcurrency(int);
58extern int thr_getconcurrency(void);
59extern void thr_exit(void *) __NORETURN;
60extern thread_t thr_self(void);
61
62/*
63 * the definition of thr_sigsetmask() is not strict ansi-c since sigset_t is
64 * not in the strict ansi-c name space. Hence, include the prototype for
65 * thr_sigsetmask() only if strict ansi-c conformance is not turned on.
66 */
67#if !defined(_STRICT_STDC) || defined(__EXTENSIONS__)
68extern int thr_sigsetmask(int, const sigset_t *, sigset_t *);
69#endif
70
71/*
72 * the definition of thr_stksegment() is not strict ansi-c since stack_t is
73 * not in the strict ansi-c name space. Hence, include the prototype for
74 * thr_stksegment() only if strict ansi-c conformance is not turned on.
75 */
76#if !defined(_STRICT_STDC) || defined(__EXTENSIONS__)
77extern int thr_stksegment(stack_t *);
78#endif
79
80extern int thr_main(void);
81extern int thr_kill(thread_t, int);
82extern int thr_suspend(thread_t);
83extern int thr_continue(thread_t);
84extern void thr_yield(void);
85extern int thr_setprio(thread_t, int);
86extern int thr_getprio(thread_t, int *);
87extern int thr_keycreate(thread_key_t *, void(*)(void *));
rafcb620782007-03-20 17:29:57 -070088extern int thr_keycreate_once(thread_key_t *, void(*)(void *));
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070089extern int thr_setspecific(thread_key_t, void *);
90extern int thr_getspecific(thread_key_t, void **);
91extern size_t thr_min_stack(void);
John Levonab618542018-10-08 15:34:11 +010092extern int thr_getname(thread_t, char *, size_t);
93extern int thr_setname(thread_t, const char *);
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070094
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070095#endif /* _ASM */
96
97#define THR_MIN_STACK thr_min_stack()
98/*
99 * thread flags (one word bit mask)
100 */
101/*
102 * POSIX.1c Note:
103 * THR_BOUND is defined same as PTHREAD_SCOPE_SYSTEM in <pthread.h>
104 * THR_DETACHED is defined same as PTHREAD_CREATE_DETACHED in <pthread.h>
105 * Any changes in these definitions should be reflected in <pthread.h>
106 */
107#define THR_BOUND 0x00000001 /* = PTHREAD_SCOPE_SYSTEM */
108#define THR_NEW_LWP 0x00000002
109#define THR_DETACHED 0x00000040 /* = PTHREAD_CREATE_DETACHED */
110#define THR_SUSPENDED 0x00000080
111#define THR_DAEMON 0x00000100
112
113/*
rafcb620782007-03-20 17:29:57 -0700114 * The key to be created by thr_keycreate_once()
115 * must be statically initialized with THR_ONCE_KEY.
116 * This must be the same as PTHREAD_ONCE_KEY_NP in <pthread.h>
117 */
118#define THR_ONCE_KEY (thread_key_t)(-1)
119
120/*
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700121 * The available register states returned by thr_getstate().
122 */
123#define TRS_VALID 0
124#define TRS_NONVOLATILE 1
125#define TRS_LWPID 2
126#define TRS_INVALID 3
127
128#ifdef __cplusplus
129}
130#endif
131
132#endif /* _THREAD_H */