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