1 /* -*- mode: c ; c-file-style: "canonware-c-style" -*-
2 ******************************************************************************
3 *
4 * Copyright (C) 1996-2005 Jason Evans <jasone@canonware.com>.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice(s), this list of conditions and the following disclaimer
12 * unmodified other than the allowable addition of one or more
13 * copyright notices.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice(s), this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
26 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 ******************************************************************************
32 *
33 * Version: Onyx 5.1.2
34 *
35 ******************************************************************************/
36
37 #ifndef CW_USE_INLINES
38 cw_nxoe_t *
39 nx_l_ref_iter(cw_nx_t *a_nx, bool a_reset);
40
41 void
42 nx_l_thread_insert(cw_nx_t *a_nx, cw_nxo_t *a_thread);
43
44 void
45 nx_l_thread_remove(cw_nx_t *a_nx, cw_nxo_t *a_thread);
46
47 cw_op_t *
48 nx_l_thread_init(cw_nx_t *a_nx);
49
50 cw_thread_start_t *
51 nx_l_thread_start(cw_nx_t *a_nx);
52 #endif
53
54 #if (defined(CW_USE_INLINES) || defined(CW_NX_C_))
55 CW_INLINE cw_nxoe_t *
nx_l_ref_iter(cw_nx_t * a_nx,bool a_reset)56 nx_l_ref_iter(cw_nx_t *a_nx, bool a_reset)
57 {
58 cw_nxoe_t *retval;
59 /* Used for remembering the current state of reference iteration. This
60 * function is only called by the garbage collector, so using a static
61 * variable works fine. */
62 static uint32_t ref_iter;
63
64 cw_check_ptr(a_nx);
65 cw_dassert(a_nx->magic == CW_NX_MAGIC);
66
67 if (a_reset)
68 {
69 ref_iter = 0;
70 }
71
72 for (retval = NULL; retval == NULL; ref_iter++)
73 {
74 switch (ref_iter)
75 {
76 case 0:
77 {
78 retval = nxo_nxoe_get(&a_nx->threadsdict);
79 break;
80 }
81 case 1:
82 {
83 retval = nxo_nxoe_get(&a_nx->systemdict);
84 break;
85 }
86 case 2:
87 {
88 retval = nxo_nxoe_get(&a_nx->globaldict);
89 break;
90 }
91 case 3:
92 {
93 retval = nxo_nxoe_get(&a_nx->stdin_nxo);
94 break;
95 }
96 case 4:
97 {
98 retval = nxo_nxoe_get(&a_nx->stdout_nxo);
99 break;
100 }
101 case 5:
102 {
103 retval = nxo_nxoe_get(&a_nx->stderr_nxo);
104 break;
105 }
106 default:
107 {
108 retval = NULL;
109 goto RETURN;
110 }
111 }
112 }
113
114 RETURN:
115 return retval;
116 }
117
118 CW_INLINE void
nx_l_thread_insert(cw_nx_t * a_nx,cw_nxo_t * a_thread)119 nx_l_thread_insert(cw_nx_t *a_nx, cw_nxo_t *a_thread)
120 {
121 cw_nxo_t nxo;
122
123 cw_check_ptr(a_nx);
124 cw_dassert(a_nx->magic == CW_NX_MAGIC);
125
126 cw_check_ptr(a_thread);
127 cw_assert(nxo_type_get(a_thread) == NXOT_THREAD);
128
129 nxo_null_new(&nxo);
130 nxo_dict_def(&a_nx->threadsdict, a_thread, &nxo);
131 }
132
133 CW_INLINE void
nx_l_thread_remove(cw_nx_t * a_nx,cw_nxo_t * a_thread)134 nx_l_thread_remove(cw_nx_t *a_nx, cw_nxo_t *a_thread)
135 {
136 cw_check_ptr(a_nx);
137 cw_dassert(a_nx->magic == CW_NX_MAGIC);
138
139 cw_check_ptr(a_thread);
140 cw_assert(nxo_type_get(a_thread) == NXOT_THREAD);
141
142 nxo_dict_undef(&a_nx->threadsdict, a_thread);
143 }
144
145 CW_INLINE cw_op_t *
nx_l_thread_init(cw_nx_t * a_nx)146 nx_l_thread_init(cw_nx_t *a_nx)
147 {
148 cw_check_ptr(a_nx);
149 cw_dassert(a_nx->magic == CW_NX_MAGIC);
150
151 return a_nx->thread_init;
152 }
153
154 CW_INLINE cw_thread_start_t *
nx_l_thread_start(cw_nx_t * a_nx)155 nx_l_thread_start(cw_nx_t *a_nx)
156 {
157 cw_check_ptr(a_nx);
158 cw_dassert(a_nx->magic == CW_NX_MAGIC);
159
160 return a_nx->thread_start;
161 }
162 #endif /* (defined(CW_USE_INLINES) || defined(CW_NX_C_)) */
163