1 /* src/threads/threadlist.hpp - different thread-lists
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
26 #ifndef _THREADLIST_HPP
27 #define _THREADLIST_HPP
33 #include "threads/thread.hpp"
35 #include "toolbox/list.hpp"
38 /* ThreadList *****************************************************************/
46 static Mutex _mutex; // a mutex for all thread lists
48 static list<threadobject*> _active_thread_list; // list of active threads
49 static list<threadobject*> _free_thread_list; // list of free threads
50 static list<int32_t> _free_index_list; // list of free thread indexes
52 static int32_t _number_of_non_daemon_threads;
54 static inline void remove_from_active_thread_list(threadobject* t);
55 static inline void add_to_free_thread_list(threadobject* t);
56 static inline void add_to_free_index_list(int32_t index);
59 static inline void lock() { _mutex.lock(); }
60 static inline void unlock() { _mutex.unlock(); }
63 static inline void add_to_active_thread_list(threadobject* t);
65 static void dump_threads();
66 static inline threadobject* get_main_thread();
67 static threadobject* get_free_thread();
68 static int32_t get_free_thread_index();
69 static int32_t get_number_of_non_daemon_threads();
70 static threadobject* get_thread_by_index(int32_t index);
71 static threadobject* get_thread_from_java_object(java_handle_t* h);
72 static void release_thread(threadobject* t);
76 inline void ThreadList::add_to_active_thread_list(threadobject* t)
78 _active_thread_list.push_back(t);
81 inline void ThreadList::remove_from_active_thread_list(threadobject* t)
83 _active_thread_list.remove(t);
86 inline void ThreadList::add_to_free_thread_list(threadobject* t)
88 _free_thread_list.push_back(t);
91 inline void ThreadList::add_to_free_index_list(int32_t index)
93 _free_index_list.push_back(index);
96 inline threadobject* ThreadList::get_main_thread()
98 return _active_thread_list.front();
103 typedef struct ThreadList ThreadList;
105 void ThreadList_lock();
106 void ThreadList_unlock();
107 void ThreadList_dump_threads();
108 void ThreadList_release_thread(threadobject* t);
109 threadobject* ThreadList_get_free_thread();
110 int32_t ThreadList_get_free_thread_index();
111 void ThreadList_add_to_active_thread_list(threadobject* t);
112 threadobject* ThreadList_get_thread_by_index(int32_t index);
113 threadobject* ThreadList_get_main_thread();
114 threadobject* ThreadList_get_thread_from_java_object(java_handle_t* h);
115 int32_t ThreadList_get_number_of_non_daemon_threads();
119 #endif // _THREADLIST_HPP
123 * These are local overrides for various environment variables in Emacs.
124 * Please do not remove this and leave it at the end of the file, where
125 * Emacs will automagically detect them.
126 * ---------------------------------------------------------------------
129 * indent-tabs-mode: t
133 * vim:noexpandtab:sw=4:ts=4: