* src/mm/boehm-gc/BCC_MAKEFILE, src/mm/boehm-gc/digimars.mak: unix2dos'ed
[cacao.git] / src / threads / threads-common.h
1 /* src/threads/threads-common.h - machine independent thread functions
2
3    Copyright (C) 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _THREADS_COMMON_H
27 #define _THREADS_COMMON_H
28
29 #include "config.h"
30 #include "vm/types.h"
31
32 #include "vm/global.h"
33
34 #include "native/llni.h"
35
36 #if defined(ENABLE_THREADS)
37 # include "threads/native/threads.h"
38 #else
39 # include "threads/none/threads.h"
40 #endif
41
42 #include "vmcore/utf8.h"
43
44
45 /* only define the following stuff with thread enabled ************************/
46
47 #if defined(ENABLE_THREADS)
48
49 /* thread states **************************************************************/
50
51 #define THREAD_STATE_NEW              0
52 #define THREAD_STATE_RUNNABLE         1
53 #define THREAD_STATE_BLOCKED          2
54 #define THREAD_STATE_WAITING          3
55 #define THREAD_STATE_TIMED_WAITING    4
56 #define THREAD_STATE_TERMINATED       5
57
58
59 /* thread priorities **********************************************************/
60
61 #define MIN_PRIORITY     1
62 #define NORM_PRIORITY    5
63 #define MAX_PRIORITY     10
64
65
66 /* debug **********************************************************************/
67
68 #if !defined(NDEBUG)
69 # define DEBUGTHREADS(message, thread) \
70         do { \
71                 if (opt_DebugThreads) { \
72                         printf("[Thread %-16s: ", message); \
73                         threads_thread_print_info(thread); \
74                         printf("]\n"); \
75                 } \
76         } while (0)
77 #else
78 # define DEBUGTHREADS(message, thread)
79 #endif
80
81
82 #if defined(__LINUX__)
83 /* XXX Remove for exact-GC. */
84 extern bool threads_pthreads_implementation_nptl;
85 #endif
86
87
88 /* inline functions ***********************************************************/
89
90 /* threads_thread_get_object ***************************************************
91
92    Return the java.lang.Thread object for the given thread.
93
94 *******************************************************************************/
95
96 static inline java_handle_t *threads_thread_get_object(threadobject *t)
97 {
98         return LLNI_WRAP(t->object);
99 }
100
101
102 /* threads_thread_set_object ***************************************************
103
104    Set the java.lang.Thread object for the given thread.
105
106 *******************************************************************************/
107
108 static inline void threads_thread_set_object(threadobject *t, java_handle_t *object)
109 {
110         t->object = LLNI_DIRECT(object);
111 }
112
113
114 /* function prototypes ********************************************************/
115
116 void          threads_preinit(void);
117
118 threadobject *threads_thread_new(void);
119 void          threads_thread_free(threadobject *t);
120
121 bool          threads_thread_start_internal(utf *name, functionptr f);
122 void          threads_thread_start(java_handle_t *object);
123
124 void          threads_thread_print_info(threadobject *t);
125
126 ptrint        threads_get_current_tid(void);
127 java_object_t *threads_get_current_object(void);
128
129 void          threads_thread_state_runnable(threadobject *t);
130 void          threads_thread_state_waiting(threadobject *t);
131 void          threads_thread_state_timed_waiting(threadobject *t);
132 void          threads_thread_state_terminated(threadobject *t);
133 utf          *threads_thread_get_state(threadobject *t);
134
135 bool          threads_thread_is_alive(threadobject *t);
136
137 void          threads_dump(void);
138 void          threads_thread_print_stacktrace(threadobject *thread);
139 void          threads_print_stacktrace(void);
140
141
142 /* implementation specific functions */
143
144 void          threads_impl_preinit(void);
145
146 void          threads_list_lock(void);
147 void          threads_list_unlock(void);
148
149 #if defined(ENABLE_GC_CACAO)
150 void          threads_mutex_gc_lock(void);
151 void          threads_mutex_gc_unlock(void);
152 #endif
153
154 void          threads_mutex_join_lock(void);
155 void          threads_mutex_join_unlock(void);
156
157 void          threads_set_current_threadobject(threadobject *thread);
158 void          threads_impl_thread_init(threadobject *t);
159 void          threads_impl_thread_clear(threadobject *t);
160 void          threads_impl_thread_reuse(threadobject *t);
161 void          threads_impl_thread_free(threadobject *t);
162 void          threads_impl_thread_start(threadobject *thread, functionptr f);
163
164 void          threads_yield(void);
165
166 #endif /* ENABLE_THREADS */
167
168 #endif /* _THREADS_COMMON_H */
169
170
171 /*
172  * These are local overrides for various environment variables in Emacs.
173  * Please do not remove this and leave it at the end of the file, where
174  * Emacs will automagically detect them.
175  * ---------------------------------------------------------------------
176  * Local variables:
177  * mode: c
178  * indent-tabs-mode: t
179  * c-basic-offset: 4
180  * tab-width: 4
181  * End:
182  * vim:noexpandtab:sw=4:ts=4:
183  */