From: Michael Starzinger Date: Tue, 12 May 2009 08:21:16 +0000 (+0200) Subject: * src/toolbox/list.hpp (List): Added new list class without a mutex. X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=cacao.git;a=commitdiff_plain;h=a8d45af29fc8dbb5fdc664befabbf27bdcbff090 * src/toolbox/list.hpp (List): Added new list class without a mutex. (LockedList): Renamed list class with mutex to make mutex obvious. * src/threads/threadlist.hpp (ThreadList): Use above class. * src/threads/threadlist.cpp: Likewise. * src/vm/jit/code.hpp (codeinfo): Patcher list uses above class. * src/vm/jit/patcher-common.cpp (patcher_list_create): Likewise. --- diff --git a/src/threads/threadlist.cpp b/src/threads/threadlist.cpp index 9284bdb84..546aa0682 100644 --- a/src/threads/threadlist.cpp +++ b/src/threads/threadlist.cpp @@ -43,9 +43,9 @@ Mutex ThreadList::_mutex; // a mutex for all thread lists -list ThreadList::_active_thread_list; // list of active threads -list ThreadList::_free_thread_list; // list of free threads -list ThreadList::_free_index_list; // list of free thread indexes +List ThreadList::_active_thread_list; // list of active threads +List ThreadList::_free_thread_list; // list of free threads +List ThreadList::_free_index_list; // list of free thread indexes int32_t ThreadList::_number_of_non_daemon_threads; @@ -108,7 +108,7 @@ void ThreadList::dump_threads() * * @param list list class to be filled */ -void ThreadList::get_active_threads(list &list) +void ThreadList::get_active_threads(List &list) { // Lock the thread lists. lock(); diff --git a/src/threads/threadlist.hpp b/src/threads/threadlist.hpp index b7f701d03..40e33171d 100644 --- a/src/threads/threadlist.hpp +++ b/src/threads/threadlist.hpp @@ -39,15 +39,13 @@ #ifdef __cplusplus -using std::list; - class ThreadList { private: static Mutex _mutex; // a mutex for all thread lists - static list _active_thread_list; // list of active threads - static list _free_thread_list; // list of free threads - static list _free_index_list; // list of free thread indexes + static List _active_thread_list; // list of active threads + static List _free_thread_list; // list of free threads + static List _free_index_list; // list of free thread indexes static int32_t _number_of_non_daemon_threads; @@ -73,7 +71,7 @@ public: static void add_to_active_thread_list(threadobject* t); static void dump_threads(); - static void get_active_threads(list &list); + static void get_active_threads(List &list); static threadobject* get_main_thread(); static threadobject* get_free_thread(); static int32_t get_free_thread_index(); diff --git a/src/toolbox/list.hpp b/src/toolbox/list.hpp index 0ca05c82e..1509f1ba0 100644 --- a/src/toolbox/list.hpp +++ b/src/toolbox/list.hpp @@ -31,27 +31,14 @@ #include #ifdef __cplusplus -#include -#endif - -#include "threads/mutex.hpp" - -#ifdef __cplusplus +#include /** - * List implementation with a Mutex. + * List implementation. */ template class List : protected std::list { -private: - Mutex _mutex; - public: - virtual ~List() {} - - void lock () { _mutex.lock(); } - void unlock() { _mutex.unlock(); } - // make iterator of std::list visible using std::list::iterator; using std::list::reverse_iterator; @@ -72,6 +59,25 @@ public: }; +// Required by LockedList. +#include "threads/mutex.hpp" + + +/** + * List implementation with a Mutex. + */ +template class LockedList : public List { +private: + Mutex _mutex; + +public: + virtual ~LockedList() {} + + void lock () { _mutex.lock(); } + void unlock() { _mutex.unlock(); } +}; + + // Required by DumpList. #include "mm/dumpmemory.hpp" @@ -111,6 +117,7 @@ public: #else typedef struct List List; +typedef struct LockedList LockedList; typedef struct DumpList DumpList; #endif diff --git a/src/vm/jit/code.hpp b/src/vm/jit/code.hpp index 0cbf0a2a8..9a940457e 100644 --- a/src/vm/jit/code.hpp +++ b/src/vm/jit/code.hpp @@ -85,9 +85,9 @@ struct codeinfo { /* patcher list */ #ifdef __cplusplus - List* patchers; + LockedList* patchers; #else - List* patchers; + LockedList* patchers; #endif /* replacement */ diff --git a/src/vm/jit/patcher-common.cpp b/src/vm/jit/patcher-common.cpp index b36e68dad..8d3e6dcef 100644 --- a/src/vm/jit/patcher-common.cpp +++ b/src/vm/jit/patcher-common.cpp @@ -90,7 +90,7 @@ static patcher_function_list_t patcher_function_list[] = { void patcher_list_create(codeinfo *code) { - code->patchers = new List(); + code->patchers = new LockedList(); }