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