2 * (c) Copyright 1990-1996 OPEN SOFTWARE FOUNDATION, INC.
3 * (c) Copyright 1990-1996 HEWLETT-PACKARD COMPANY
4 * (c) Copyright 1990-1996 DIGITAL EQUIPMENT CORPORATION
5 * (c) Copyright 1991, 1992 Siemens-Nixdorf Information Systems
6 * To anyone who acknowledges that this file is provided "AS IS" without
7 * any express or implied warranty: permission to use, copy, modify, and
8 * distribute this file for any purpose is hereby granted without fee,
9 * provided that the above copyright notices and this notice appears in
10 * all source code copies, and that none of the names listed above be used
11 * in advertising or publicity pertaining to distribution of the software
12 * without specific, written prior permission. None of these organizations
13 * makes any representations about the suitability of this software for
17 * TCB-related type definitions.
26 # if !_CMA_THREAD_SYNC_IO_
27 # include <cma_thread_io.h>
30 #include <cma_debug_client.h>
33 #include <cma_handle.h>
34 #include <cma_queue.h>
35 #if _CMA_OS_ == _CMA__UNIX
36 # if defined(SNI_DCOSX)
37 # include <sys/ucontext.h>
41 #include <cma_sched.h>
44 * CONSTANTS AND MACROS
47 #if _CMA_PLATFORM_ == _CMA__IBMR2_UNIX
48 # define cma__c_ibmr2_ctx_stack_size 2048
49 # define cma__c_ibmr2_ctx_stack_top (cma__c_ibmr2_ctx_stack_size - 1)
57 # if _CMA_HARDWARE_ != _CMA__HPPA
58 struct CMA__T_SEMAPHORE
;
61 struct CMA__T_INT_MUTEX
;
62 struct CMA__T_INT_TCB
;
65 typedef cma_t_address
*cma__t_context_list
;
67 typedef struct CMA__T_TCB_PAD
{
69 * Adjust to align the tcb prolog at byte 32.
70 * 12 bytes are required as object header is currently
73 cma_t_integer pad1
; /* pad bytes */
74 cma_t_integer pad2
; /* pad bytes */
75 cma_t_integer pad3
; /* pad bytes */
78 #if (_CMA_OS_ == _CMA__UNIX) && !_CMA_THREAD_SYNC_IO_
79 typedef struct CMA__T_TCB_SELECT
{
81 #if (_CMA_UNIX_TYPE != _CMA__SVR4)
82 cma__t_file_mask
*rfds
;
83 cma__t_file_mask
*wfds
;
84 cma__t_file_mask
*efds
;
86 cma__t_poll_info poll_info
;
87 #endif /* (_CMA_UNIX_TYPE != _CMA__SVR4) */
92 typedef struct CMA__T_TCB_TIME
{
93 cma__t_queue queue
; /* must be first entry! */
95 struct CMA__T_SEMAPHORE
*semaphore
; /* used for timed semaphores */
96 cma_t_date_time wakeup_time
;
97 cma_t_integer quanta_remaining
;
100 typedef enum CMA__T_DEBEVT
{
101 cma__c_debevt_activating
= 1, /* First transition to running */
102 cma__c_debevt_running
= 2, /* Any transition to running */
103 cma__c_debevt_preempting
= 3, /* Preemted (replaced) another
105 cma__c_debevt_blocking
= 4, /* Any transition to blocked */
106 cma__c_debevt_terminating
= 5, /* Final state transition */
107 cma__c_debevt_term_alert
= 6, /* Terminated due to alert/cancel */
108 cma__c_debevt_term_exc
= 7, /* Terminated due to exception */
109 cma__c_debevt_exc_handled
= 8 /* Exception is being handled */
112 #define cma__c_debevt__first ((cma_t_integer)cma__c_debevt_activating)
113 #define cma__c_debevt__last ((cma_t_integer)cma__c_debevt_exc_handled)
114 #define cma__c_debevt__dim (cma__c_debevt__last + 1)
117 * Type defining thread substate, which is used by the debugger.
118 * If the state is blocked, substate indicates WHY the thread is blocked.
120 typedef enum CMA__T_SUBSTATE
{
121 cma__c_substa_normal
= 0,
122 cma__c_substa_mutex
= 1,
123 cma__c_substa_cv
= 2,
124 cma__c_substa_timed_cv
= 3,
125 cma__c_substa_term_alt
= 4,
126 cma__c_substa_term_exc
= 5,
127 cma__c_substa_delay
=6,
128 cma__c_substa_not_yet_run
= 7
130 #define cma__c_substa__first ((cma_t_integer)cma__c_substa_normal)
131 #define cma__c_substa__last ((cma_t_integer)cma__c_substa_not_yet_run)
132 #define cma__c_substa__dim (cma__c_substa__last + 1)
136 * Per-thread state for the debugger
138 typedef struct CMA__T_TCB_DEBUG
{
139 cma_t_boolean on_hold
; /* Thread was put on hold by
141 cma_t_boolean activated
; /* Activation event was reported */
142 cma_t_boolean did_preempt
; /* Thread preempted prior one */
143 cma_t_address start_pc
; /* Start routine address */
144 cma_t_address object_addr
; /* Addr of thread object */
145 cma__t_substate substate
; /* Reason blocked, terminated, etc.*/
146 cma_t_boolean notify_debugger
;/* Notify debugger thread is running */
147 cma_t_address SPARE2
; /* SPARE */
148 cma_t_address SPARE3
; /* SPARE */
149 struct CMA__T_INT_TCB
150 *preempted_tcb
; /* TCB of thread that got preempted */
151 cma_t_boolean flags
[cma__c_debevt__dim
];
152 /* Events enabled for this thread */
155 typedef struct CMA__T_TCB_SCHED
{
156 cma_t_integer adj_time
; /* Abs. time in ticks of last
158 cma_t_integer tot_time
; /* Weighted ave in ticks (scaled) */
159 cma_t_integer time_stamp
; /* Abs. time in ticks of last update */
160 cma_t_integer cpu_time
; /* Weighted average in ticks */
161 cma_t_integer cpu_ticks
; /* # of ticks while comp. (scaled) */
162 cma_t_integer q_num
; /* Number of last ready queue on */
163 cma_t_priority priority
; /* Thread priority */
164 cma_t_sched_policy policy
; /* Scheduling policy of thread */
165 cma_t_boolean rtb
; /* "Run 'Till Block" scheduling */
166 cma_t_boolean spp
; /* "Strict Priority
168 cma_t_boolean fixed_prio
; /* Fixed priority */
169 cma__t_sched_class
class; /* Scheduling class */
170 struct CMA__T_VP
*processor
; /* Current processor (if running) */
173 typedef struct CMA__T_INT_ALERT
{
174 cma_t_boolean pending
: 1; /* alert_pending bit */
175 cma_t_boolean g_enable
: 1; /* general delivery state */
176 cma_t_boolean a_enable
: 1; /* asynchronous delivery state */
177 cma_t_integer spare
: 29; /* Pad to longword */
178 cma_t_natural count
; /* Alert scope nesting count */
181 typedef enum CMA__T_STATE
{
182 cma__c_state_running
= 0, /* For consistency with initial TCB */
183 cma__c_state_ready
= 1,
184 cma__c_state_blocked
= 2,
185 cma__c_state_terminated
= 3
187 #define cma__c_state__first ((cma_t_integer)cma__c_state_running)
188 #define cma__c_state__last ((cma_t_integer)cma__c_state_terminated)
189 #define cma__c_state__dim (cma__c_state__last + 1)
191 typedef enum CMA__T_THKIND
{
192 cma__c_thkind_initial
= 0, /* Initial thread */
193 cma__c_thkind_normal
= 1, /* Normal thread */
194 cma__c_thkind_null
= 2 /* A null thread */
196 #define cma__c_thkind__first ((cma_t_integer)cma__c_thkind_initial)
197 #define cma__c_thkind__last ((cma_t_integer)cma__c_thkind_null)
198 #define cma__c_thkind__dim (cma__c_thkind__last + 1)
200 typedef enum CMA__T_SYSCALL_STATE
{
201 cma__c_syscall_ok
= 1, /* syscall was not interrupted */
202 cma__c_syscall_intintrpt
= 1, /* syscall was interrupted by VTALRM */
203 cma__c_syscall_extintrpt
= 2 /* syscall was interrupted by
205 } cma__t_syscall_state
;
208 typedef struct CMA__T_INT_TCB
{
211 * Modifications to the following three fields must be coordinated.
212 * The object header must always be first, and the prolog must always
213 * remain at the same offset (32) for all time. Thus the object header
214 * must never grow beyond a maximum of 32 bytes.
216 cma__t_object header
; /* Common object header */
217 cma__t_tcb_pad pad1
; /* Pad required to align prolog */
218 cma_t_tcb_prolog prolog
; /* Standard prolog for tasks,
222 * Floating part of TCB (fields here on are free to be moved and resized).
224 cma__t_queue threads
; /* List of all known threads */
225 cma__t_int_attr
*attributes
; /* Backpointer to attr obj */
226 cma__t_state state
; /* Current state of thread */
227 cma__t_thkind kind
; /* Which kind of thread */
228 struct CMA__T_INT_MUTEX
229 *mutex
; /* Mutex to control TCB access */
231 *term_cv
; /* CV for join */
232 struct CMA__T_INT_MUTEX
233 *tswait_mutex
; /* Mutex for
234 thread-synchronous waits */
236 *tswait_cv
; /* CV for thread-synchronous waits */
237 cma_t_start_routine start_code
; /* Address of start routine */
238 cma_t_address start_arg
; /* Argument to pass to start_code */
239 cma__t_queue stack
; /* Queue header for stack descr. */
240 cma_t_natural context_count
; /* Size of context array */
241 cma__t_context_list contexts
; /* Context value array pointer */
242 cma_t_exit_status exit_status
; /* Exit status of thread */
243 cma_t_address return_value
; /* Thread's return value */
244 cma__t_async_ctx async_ctx
; /* Asynchronous context switch info */
245 cma__t_static_ctx static_ctx
; /* Static context switch information */
246 cma_t_integer event_status
; /* Status of semaphore operation */
247 cma__t_tcb_time timer
; /* Time info for dispatcher */
248 cma__t_tcb_sched sched
; /* Scheduler info */
249 cma__t_tcb_debug debug
; /* Debugger info */
250 #if _CMA_OS_ == _CMA__UNIX
251 # if !_CMA_THREAD_SYNC_IO_
252 cma__t_tcb_select select
; /* Select info for timed selects */
254 struct sigaction sigaction_data
[NSIG
];
256 cma_t_natural syscall_state
; /* set if one of the cma
259 cma_t_boolean detached
; /* Set if already detached */
260 cma_t_boolean terminated
; /* Set if terminated */
261 cma_t_integer joiners
; /* Count of joiners, for
263 cma__t_int_alert alert
; /* Current alert state info */
265 *wait_cv
; /* CV thread is currently waiting on */
266 struct CMA__T_INT_MUTEX
267 *wait_mutex
; /* Mutex thread is waiting on */
269 *exc_stack
; /* Top of exception stack */
270 #if _CMA_PLATFORM_ == _CMA__IBMR2_UNIX
271 char ctx_stack
[cma__c_ibmr2_ctx_stack_size
];
273 cma_t_integer thd_errno
; /* Per-thread errno value */
274 #if _CMA_OS_ == _CMA__VMS
275 cma_t_integer thd_vmserrno
; /* Per-thread VMS errno value */