c0a123ce1d013620ef7f0382b12bfd7c1a649b1f
[cacao.git] / src / threads / threads-common.c
1 /* src/threads/threads-common.c - machine independent thread functions
2
3    Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    $Id: signal.c 7246 2007-01-29 18:49:05Z twisti $
26
27 */
28
29
30 #include "config.h"
31 #include "vm/types.h"
32
33
34 #include "native/jni.h"
35 #include "native/include/java_lang_Thread.h"
36
37 #if defined(WITH_CLASSPATH_GNU)
38 # include "native/include/java_lang_VMThread.h"
39 #endif
40
41 #include "threads/threads-common.h"
42
43 #if defined(ENABLE_THREADS)
44 # include "threads/native/threads.h"
45 #else
46 # include "threads/none/threads.h"
47 #endif
48
49 #include "vm/builtin.h"
50 #include "vm/stringlocal.h"
51
52 #include "vmcore/class.h"
53 #include "vmcore/utf8.h"
54
55
56 /* threads_create_thread *******************************************************
57
58    Creates a thread object with the given name.
59
60 *******************************************************************************/
61 #if defined(ENABLE_THREADS)
62 threadobject *threads_create_thread(utf *name)
63 {
64         threadobject *thread;
65 #if defined(WITH_CLASSPATH_GNU)
66         java_lang_VMThread *vmt;
67 #endif
68
69         /* create the finalizer object */
70
71         thread = (threadobject *) builtin_new(class_java_lang_Thread);
72
73         if (thread == NULL)
74                 return NULL;
75
76 #if defined(WITH_CLASSPATH_GNU)
77         vmt = (java_lang_VMThread *) builtin_new(class_java_lang_VMThread);
78
79         if (vmt == NULL)
80                 return NULL;
81
82         vmt->thread = (java_lang_Thread *) thread;
83
84         thread->o.vmThread = vmt;
85 #endif
86
87         thread->flags      = THREAD_FLAG_DAEMON;
88
89         /* set java.lang.Thread fields */
90
91         thread->o.name     = javastring_new(name);
92 #if defined(ENABLE_JAVASE)
93         thread->o.daemon   = true;
94 #endif
95         thread->o.priority = NORM_PRIORITY;
96
97         /* return the thread object */
98
99         return thread;
100 }
101 #endif
102
103
104 /* threads_get_current_tid *****************************************************
105
106    Return the tid of the current thread.
107    
108    RETURN VALUE:
109        the current tid
110
111 *******************************************************************************/
112
113 ptrint threads_get_current_tid(void)
114 {
115         threadobject *thread;
116
117         thread = THREADOBJECT;
118
119         /* this may happen during bootstrap */
120
121         if (thread == NULL)
122                 return 0;
123
124 #if defined(ENABLE_THREADS)
125         return (ptrint) thread->tid;
126 #else
127         return 0;
128 #endif
129 }
130
131
132 /*
133  * These are local overrides for various environment variables in Emacs.
134  * Please do not remove this and leave it at the end of the file, where
135  * Emacs will automagically detect them.
136  * ---------------------------------------------------------------------
137  * Local variables:
138  * mode: c
139  * indent-tabs-mode: t
140  * c-basic-offset: 4
141  * tab-width: 4
142  * End:
143  * vim:noexpandtab:sw=4:ts=4:
144  */