CACAO
thread-posix.hpp
Go to the documentation of this file.
1 /* src/threads/threadobject.hpp - POSIX thread data structure
2 
3  Copyright (C) 1996-2013
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 THREAD_POSIX_HPP_
27 #define THREAD_POSIX_HPP_ 1
28 
29 #ifndef THREAD_HPP_
30 # error "Do not directly include this header, include threads/thread.hpp instead"
31 #endif
32 
33 #include "config.h"
34 
35 #include <pthread.h>
36 #include <ucontext.h>
37 
38 #include "vm/types.hpp"
39 
40 #if defined(ENABLE_TLH)
41 # include "mm/tlh.hpp"
42 #endif
43 
44 #include "threads/condition.hpp"
45 #include "threads/mutex.hpp"
46 
47 /* current threadobject *******************************************************/
48 
49 #if defined(HAVE___THREAD)
50 
51 #define THREADOBJECT thread_current
52 
53 extern __thread threadobject *thread_current;
54 
55 #else /* defined(HAVE___THREAD) */
56 
57 #define THREADOBJECT \
58  ((threadobject *) pthread_getspecific(thread_current_key))
59 
60 extern pthread_key_t thread_current_key;
61 
62 #endif /* defined(HAVE___THREAD) */
63 
64 
65 
66 inline static threadobject* thread_get_current(void);
67 
68 
69 // Includes.
70 #include "native/localref.hpp"
71 
72 #include "threads/lock.hpp"
73 
74 #include "vm/global.hpp"
75 #include "vm/vm.hpp"
76 
77 #if defined(ENABLE_GC_CACAO)
78 # include "vm/jit/executionstate.hpp"
79 # include "vm/jit/replace.hpp"
80 #endif
81 
82 #if defined(ENABLE_INTRP)
83 #include "vm/jit/intrp/intrp.h"
84 #endif
85 
86 
87 /* inline functions ***********************************************************/
88 
89 /**
90  * Return the Thread object of the current thread.
91  *
92  * @return The current Thread object.
93  */
94 inline static threadobject* thread_get_current(void)
95 {
96  threadobject *t;
97 
98 #if defined(HAVE___THREAD)
99  t = thread_current;
100 #else
101  t = (threadobject *) pthread_getspecific(thread_current_key);
102 #endif
103 
104  return t;
105 }
106 
107 
108 /**
109  * Set the current Thread object.
110  *
111  * @param t The thread object to set.
112  */
113 inline static void thread_set_current(threadobject* t)
114 {
115 #if defined(HAVE___THREAD)
116  thread_current = t;
117 #else
118  int result;
119 
120  result = pthread_setspecific(thread_current_key, t);
121 
122  if (result != 0)
123  //os::abort_errnum(result, "thread_set_current: pthread_setspecific failed");
124  vm_abort("thread_set_current: pthread_setspecific failed");
125 #endif
126 }
127 
128 #endif // THREADOBJECT_POSIX_HPP_
129 
130 /*
131  * These are local overrides for various environment variables in Emacs.
132  * Please do not remove this and leave it at the end of the file, where
133  * Emacs will automagically detect them.
134  * ---------------------------------------------------------------------
135  * Local variables:
136  * mode: c++
137  * indent-tabs-mode: t
138  * c-basic-offset: 4
139  * tab-width: 4
140  * End:
141  * vim:noexpandtab:sw=4:ts=4:
142  */
void vm_abort(const char *text,...)
Definition: vm.cpp:2586
threadobject * thread_current
Definition: thread-none.cpp:41
static void thread_set_current(threadobject *t)
Set the current Thread object.
static threadobject * thread_get_current(void)
Return the Thread object of the current thread.