* src/toolbox/list.hpp (List): Added new list class without a mutex.
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Tue, 12 May 2009 08:21:16 +0000 (10:21 +0200)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Tue, 12 May 2009 08:21:16 +0000 (10:21 +0200)
(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.

src/threads/threadlist.cpp
src/threads/threadlist.hpp
src/toolbox/list.hpp
src/vm/jit/code.hpp
src/vm/jit/patcher-common.cpp

index 9284bdb8412cc58226563cbba8279a9e76b17ac1..546aa06822984303e1e701368dacb5674bfa61e7 100644 (file)
@@ -43,9 +43,9 @@
 
 Mutex               ThreadList::_mutex;                // a mutex for all thread lists
 
-list<threadobject*> ThreadList::_active_thread_list;   // list of active threads
-list<threadobject*> ThreadList::_free_thread_list;     // list of free threads
-list<int32_t>       ThreadList::_free_index_list;      // list of free thread indexes
+List<threadobject*> ThreadList::_active_thread_list;   // list of active threads
+List<threadobject*> ThreadList::_free_thread_list;     // list of free threads
+List<int32_t>       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<threadobject*> &list)
+void ThreadList::get_active_threads(List<threadobject*> &list)
 {
        // Lock the thread lists.
        lock();
index b7f701d03995c89acf930c64b7939d05f8d95633..40e33171dfb3777ef206b397deddfd3bec64ce8a 100644 (file)
 
 #ifdef __cplusplus
 
-using std::list;
-
 class ThreadList {
 private:
        static Mutex               _mutex;              // a mutex for all thread lists
 
-       static list<threadobject*> _active_thread_list; // list of active threads
-       static list<threadobject*> _free_thread_list;   // list of free threads
-       static list<int32_t>       _free_index_list;    // list of free thread indexes
+       static List<threadobject*> _active_thread_list; // list of active threads
+       static List<threadobject*> _free_thread_list;   // list of free threads
+       static List<int32_t>       _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<threadobject*> &list);
+       static void                 get_active_threads(List<threadobject*> &list);
        static threadobject*        get_main_thread();
        static threadobject*        get_free_thread();
        static int32_t              get_free_thread_index();
index 0ca05c82e7b53f90496b94440eb23681afefff5c..1509f1ba00e59be41da99eac33bef34710c0a2c1 100644 (file)
 #include <stdint.h>
 
 #ifdef __cplusplus
-#include <list>
-#endif
-
-#include "threads/mutex.hpp"
 
-
-#ifdef __cplusplus
+#include <list>
 
 /**
- * List implementation with a Mutex.
+ * List implementation.
  */
 template<class T> class List : protected std::list<T> {
-private:
-       Mutex _mutex;
-
 public:
-       virtual ~List() {}
-
-       void lock  () { _mutex.lock(); }
-       void unlock() { _mutex.unlock(); }
-
        // make iterator of std::list visible
        using std::list<T>::iterator;
        using std::list<T>::reverse_iterator;
@@ -72,6 +59,25 @@ public:
 };
 
 
+// Required by LockedList.
+#include "threads/mutex.hpp"
+
+
+/**
+ * List implementation with a Mutex.
+ */
+template<class T> class LockedList : public List<T> {
+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
index 0cbf0a2a8001463eb5e9dd3756b8d9bca0862862..9a940457ebe49b1cbf813f73ffda74807c1a0a51 100644 (file)
@@ -85,9 +85,9 @@ struct codeinfo {
 
        /* patcher list */
 #ifdef __cplusplus
-       List<patchref_t>* patchers;
+       LockedList<patchref_t>* patchers;
 #else
-       List*         patchers;
+       LockedList*   patchers;
 #endif
 
        /* replacement */                                   
index b36e68dadaeddb7ae1a8c32b43545bdeefacd53a..8d3e6dcef9ae5f618d9e8312b2d6d996984fa73d 100644 (file)
@@ -90,7 +90,7 @@ static patcher_function_list_t patcher_function_list[] = {
 
 void patcher_list_create(codeinfo *code)
 {
-       code->patchers = new List<patchref_t>();
+       code->patchers = new LockedList<patchref_t>();
 }