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 *****************************************************************/
44 static Mutex _mutex; // a mutex for all thread lists
46 static List<threadobject*> _active_thread_list; // list of active threads
47 static List<threadobject*> _free_thread_list; // list of free threads
48 static List<int32_t> _free_index_list; // list of free thread indexes
50 static int32_t _number_of_non_daemon_threads;
52 static void remove_from_active_thread_list(threadobject* t);
53 static void add_to_free_thread_list(threadobject* t);
54 static void add_to_free_index_list(int32_t index);
58 class comparator : public std::binary_function<threadobject*, int32_t, bool> {
60 bool operator() (const threadobject* t, const int32_t index) const
62 return (t->index == index);
67 static void lock() { _mutex.lock(); }
68 static void unlock() { _mutex.unlock(); }
71 static void add_to_active_thread_list(threadobject* t);
73 static void dump_threads();
74 static void get_active_threads(List<threadobject*> &list);
75 static threadobject* get_main_thread();
76 static threadobject* get_free_thread();
77 static int32_t get_free_thread_index();
78 static int32_t get_number_of_non_daemon_threads();
79 static threadobject* get_thread_by_index(int32_t index);
80 static threadobject* get_thread_from_java_object(java_handle_t* h);
81 static void release_thread(threadobject* t);
84 struct ThreadListLocker {
85 ThreadListLocker() { ThreadList::lock(); }
86 ~ThreadListLocker() { ThreadList::unlock(); }
90 inline void ThreadList::add_to_active_thread_list(threadobject* t)
92 _active_thread_list.push_back(t);
95 inline void ThreadList::remove_from_active_thread_list(threadobject* t)
97 _active_thread_list.remove(t);
100 inline void ThreadList::add_to_free_thread_list(threadobject* t)
102 _free_thread_list.push_back(t);
105 inline void ThreadList::add_to_free_index_list(int32_t index)
107 _free_index_list.push_back(index);
110 inline threadobject* ThreadList::get_main_thread()
112 return _active_thread_list.front();
117 typedef struct ThreadList ThreadList;
119 void ThreadList_lock();
120 void ThreadList_unlock();
121 void ThreadList_dump_threads();
122 void ThreadList_release_thread(threadobject* t);
123 threadobject* ThreadList_get_free_thread();
124 int32_t ThreadList_get_free_thread_index();
125 void ThreadList_add_to_active_thread_list(threadobject* t);
126 threadobject* ThreadList_get_thread_by_index(int32_t index);
127 threadobject* ThreadList_get_main_thread();
128 threadobject* ThreadList_get_thread_from_java_object(java_handle_t* h);
129 int32_t ThreadList_get_number_of_non_daemon_threads();
133 #endif // _THREADLIST_HPP
137 * These are local overrides for various environment variables in Emacs.
138 * Please do not remove this and leave it at the end of the file, where
139 * Emacs will automagically detect them.
140 * ---------------------------------------------------------------------
143 * indent-tabs-mode: t
147 * vim:noexpandtab:sw=4:ts=4: