]> git.saurik.com Git - apple/libc.git/blob - threads/cthread_internals.h
Libc-262.3.2.tar.gz
[apple/libc.git] / threads / cthread_internals.h
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1989 Carnegie-Mellon University
28 * All rights reserved. The CMU software License Agreement specifies
29 * the terms and conditions for use and redistribution.
30 */
31
32 /*
33 * HISTORY
34 * 08-Mar-90 Avadis Tevanian, Jr. (avie) at NeXT
35 * Added errno field to cproc structure.
36 *
37 */
38
39 /*
40 * cthread_internals.h - by Eric Cooper
41 *
42 * Private definitions for the C Threads implementation.
43 *
44 * The cproc structure is used for different implementations
45 * of the basic schedulable units that execute cthreads.
46 *
47 * MTHREAD MACH threads; single address space,
48 * kernel-mode preemptive scheduling
49 */
50 #include <assert.h>
51 #include <mach/mach.h>
52 #include <mach/mach_error.h>
53
54 /*
55 * Low-level thread implementation.
56 * This structure must agree with struct ur_cthread in cthreads.h
57 */
58 typedef struct cproc {
59 struct cproc *next; /* for lock, condition, and ready queues */
60 struct cproc *incarnation; /* for cthread_self() */
61 int state;
62 mach_port_t reply_port; /* for mig_get_reply_port() */
63
64 mach_port_t wait_port;
65
66 int id;
67 struct cproc *link; /* so all cprocs can be found
68 after a fork() */
69 int flags;
70
71 unsigned int stack_base;
72 unsigned int stack_size;
73 int error;
74
75 } *cproc_t;
76
77 #define NO_CPROC ((cproc_t) 0)
78 #define cproc_self() ((cproc_t) ur_cthread_self())
79 extern void cthread_set_self(cproc_t p);
80
81 /*
82 * Possible cproc states.
83 */
84 #define CPROC_RUNNING 0
85 #define CPROC_SPINNING 1
86 #define CPROC_BLOCKED 2
87
88 /*
89 * The cproc flag bits.
90 */
91 #define CPROC_INITIAL_STACK 0x1
92 #define CPROC_NOCACHE_THREAD /* Don't try to cache this cthread on exit */
93
94 /*
95 * C Threads imports:
96 */
97 #ifdef __STRICT_BSD__
98 extern char *malloc();
99 #endif /* __STRICT_BSD__ */
100
101 /*
102 * Mach imports:
103 */
104 extern void mach_error();
105
106 /*
107 * C library imports:
108 */
109 #ifdef __STRICT_BSD__
110 extern exit();
111 #else
112 #include <stdlib.h>
113 #endif /* __STRICT_BSD__ */
114
115 /*
116 * Macro for MACH kernel calls.
117 */
118 #ifndef MACH_CALL
119 #define MACH_CALL(expr, ret) { \
120 if (((ret) = (expr)) != KERN_SUCCESS) { \
121 mach_error(#expr, (ret)); \
122 assert(0); \
123 } \
124 }
125 #endif
126
127 /*
128 * Debugging support.
129 */
130 #ifdef CTHREADS_DEBUG
131
132 #define private
133 #define TRACE(x) if (cthread_debug) x ; else
134 extern int cthread_debug;
135
136 /*
137 * C library imports:
138 */
139 #include <stdio.h>
140 #include <stdlib.h>
141 #else /* CTHREADS_DEBUG */
142
143 #define private static
144 #define TRACE(x)
145
146 #endif /* DEBUG */