[beast: 61/95] BIRNET: remove birnet threading implementation, use std and Rapicorn



commit aa17c381296bfd3b623b42c39b94e0b63c169fca
Author: Tim Janik <timj gnu org>
Date:   Sat Mar 16 02:19:00 2013 +0100

    BIRNET: remove birnet threading implementation, use std and Rapicorn

 birnet/Makefile.am         |    3 -
 birnet/birnet.hh           |    1 -
 birnet/birnetcdefs.h       |  134 ----
 birnet/birnetthread.cc     |  262 -------
 birnet/birnetthread.hh     |  317 ---------
 birnet/birnetthreadimpl.cc | 1625 --------------------------------------------
 birnet/birnetutils.cc      |   30 +-
 birnet/birnetutils.hh      |  106 +---
 birnet/tests/datalist.cc   |    8 -
 birnet/tests/threads.cc    | 1101 ------------------------------
 10 files changed, 10 insertions(+), 3577 deletions(-)
---
diff --git a/birnet/Makefile.am b/birnet/Makefile.am
index 03fec55..ea3d918 100644
--- a/birnet/Makefile.am
+++ b/birnet/Makefile.am
@@ -14,17 +14,14 @@ birnet_headers = $(strip            \
        birnetdebugtools.hh             \
        birnetmsg.hh                    \
        birnettests.h                   \
-       birnetthread.hh                 \
        birnetmath.hh                   \
        birnetutf8.hh                   \
        birnetutils.hh                  \
 )
 birnet_sources = $(strip               \
-       birnetthreadimpl.cc             \
        birnetcpu.cc                    \
        birnetdebugtools.cc             \
        birnetmsg.cc                    \
-       birnetthread.cc                 \
        birnetmath.cc                   \
        birnetutf8.cc                   \
        birnetutils.cc                  \
diff --git a/birnet/birnet.hh b/birnet/birnet.hh
index 779e6ff..451d617 100644
--- a/birnet/birnet.hh
+++ b/birnet/birnet.hh
@@ -8,7 +8,6 @@
 #include <birnet/birnetmath.hh>
 #include <birnet/birnetutf8.hh>
 #include <birnet/birnetutils.hh>
-#include <birnet/birnetthread.hh>
 /**
  * @namespace Birnet
  * Library with utility functions, carried forward in Rapicorn: http://dev.testbit.eu/rapicorn/latest/
diff --git a/birnet/birnetcdefs.h b/birnet/birnetcdefs.h
index 7642283..311d907 100644
--- a/birnet/birnetcdefs.h
+++ b/birnet/birnetcdefs.h
@@ -197,140 +197,6 @@ typedef struct {
   uint x86_mmx : 1, x86_mmxext : 1, x86_3dnow : 1, x86_3dnowext : 1;
   uint x86_sse : 1, x86_sse2   : 1, x86_sse3  : 1, x86_sse4     : 1;
 } BirnetCPUInfo;
-/* --- Thread info --- */
-typedef enum {
-  BIRNET_THREAD_UNKNOWN    = '?',
-  BIRNET_THREAD_RUNNING    = 'R',
-  BIRNET_THREAD_SLEEPING   = 'S',
-  BIRNET_THREAD_DISKWAIT   = 'D',
-  BIRNET_THREAD_TRACED     = 'T',
-  BIRNET_THREAD_PAGING     = 'W',
-  BIRNET_THREAD_ZOMBIE     = 'Z',
-  BIRNET_THREAD_DEAD       = 'X',
-} BirnetThreadState;
-typedef struct {
-  int                  thread_id;
-  char                 *name;
-  uint                         aborted : 1;
-  BirnetThreadState     state;
-  int                          priority;       /* nice value */
-  int                          processor;      /* running processor # */
-  BirnetUInt64                 utime;          /* user time */
-  BirnetUInt64                 stime;          /* system time */
-  BirnetUInt64         cutime;         /* user time of dead children */
-  BirnetUInt64         cstime;         /* system time of dead children */
-} BirnetThreadInfo;
-/* --- threading ABI --- */
-typedef struct _BirnetThread BirnetThread;
-typedef void (*BirnetThreadFunc)   (void *user_data);
-typedef void (*BirnetThreadWakeup) (void *wakeup_data);
-typedef union {
-  void      *cond_pointer;
-  BirnetUInt8 cond_dummy[MAX (8, BIRNET_SIZEOF_PTH_COND_T)];
-  long long int align;
-} BirnetCond;
-typedef union {
-  void      *mutex_pointer;
-  BirnetUInt8 mutex_dummy[MAX (8, BIRNET_SIZEOF_PTH_MUTEX_T)];
-  long long int align;
-} BirnetMutex;
-typedef struct {
-  BirnetMutex   mutex;
-  BirnetThread *owner;
-  uint                 depth;
-} BirnetRecMutex;
-typedef struct {
-  void              (*mutex_chain4init)     (BirnetMutex       *mutex);
-  void              (*mutex_unchain)        (BirnetMutex       *mutex);
-  void              (*rec_mutex_chain4init) (BirnetRecMutex    *mutex);
-  void              (*rec_mutex_unchain)    (BirnetRecMutex    *mutex);
-  void              (*cond_chain4init)      (BirnetCond        *cond);
-  void              (*cond_unchain)         (BirnetCond        *cond);
-  void             (*atomic_pointer_set)   (volatile void     *atomic,
-                                            volatile void     *value);
-  void*                    (*atomic_pointer_get)   (volatile void     *atomic);
-  int/*bool*/      (*atomic_pointer_cas)   (volatile void     *atomic,
-                                            volatile void     *oldval,
-                                            volatile void     *newval);
-  void             (*atomic_int_set)       (volatile int      *atomic,
-                                            int                newval);
-  int              (*atomic_int_get)       (volatile int      *atomic);
-  int/*bool*/      (*atomic_int_cas)       (volatile int      *atomic,
-                                            int                oldval,
-                                            int                newval);
-  void             (*atomic_int_add)       (volatile int      *atomic,
-                                            int                diff);
-  int              (*atomic_int_swap_add)  (volatile int      *atomic,
-                                            int                diff);
-  void             (*atomic_uint_set)      (volatile uint     *atomic,
-                                            uint               newval);
-  uint             (*atomic_uint_get)      (volatile uint     *atomic);
-  int/*bool*/      (*atomic_uint_cas)      (volatile uint     *atomic,
-                                            uint               oldval,
-                                            uint               newval);
-  void             (*atomic_uint_add)      (volatile uint     *atomic,
-                                            uint               diff);
-  uint             (*atomic_uint_swap_add) (volatile uint     *atomic,
-                                            uint               diff);
-  BirnetThread*     (*thread_new)           (const char        *name);
-  BirnetThread*     (*thread_ref)           (BirnetThread      *thread);
-  BirnetThread*     (*thread_ref_sink)      (BirnetThread      *thread);
-  void              (*thread_unref)         (BirnetThread      *thread);
-  bool              (*thread_start)         (BirnetThread      *thread,
-                                            BirnetThreadFunc   func,
-                                            void              *user_data);
-  BirnetThread*     (*thread_self)          (void);
-  void*             (*thread_selfxx)        (void);
-  void*             (*thread_getxx)         (BirnetThread      *thread);
-  bool              (*thread_setxx)         (BirnetThread      *thread,
-                                            void              *xxdata);
-  int               (*thread_pid)           (BirnetThread      *thread);
-  const char*       (*thread_name)          (BirnetThread      *thread);
-  void              (*thread_set_name)      (const char        *newname);
-  bool             (*thread_sleep)         (BirnetInt64        max_useconds);
-  void             (*thread_wakeup)        (BirnetThread      *thread);
-  void             (*thread_awake_after)   (BirnetUInt64       stamp);
-  void             (*thread_emit_wakeups)  (BirnetUInt64       wakeup_stamp);
-  void             (*thread_set_wakeup)    (BirnetThreadWakeup wakeup_func,
-                                            void              *wakeup_data,
-                                            void             (*destroy_data) (void*));
-  void              (*thread_abort)        (BirnetThread      *thread);
-  void              (*thread_queue_abort)   (BirnetThread      *thread);
-  bool              (*thread_aborted)      (void);
-  bool             (*thread_get_aborted)   (BirnetThread      *thread);
-  bool             (*thread_get_running)   (BirnetThread      *thread);
-  void             (*thread_wait_for_exit) (BirnetThread      *thread);
-  void              (*thread_yield)         (void);
-  void              (*thread_exit)          (void              *retval) BIRNET_NORETURN;
-  void              (*thread_set_handle)    (BirnetThread      *handle);
-  BirnetThread*     (*thread_get_handle)    (void);
-  BirnetThreadInfo* (*info_collect)         (BirnetThread      *thread);
-  void              (*info_free)            (BirnetThreadInfo  *info);
-  void*                    (*qdata_get)            (uint               glib_quark);
-  void             (*qdata_set)            (uint               glib_quark,
-                                            void              *data,
-                                             void             (*destroy_data) (void*));
-  void*                    (*qdata_steal)          (uint               glib_quark);
-  void              (*mutex_init)           (BirnetMutex       *mutex);
-  void              (*mutex_lock)           (BirnetMutex       *mutex);
-  int               (*mutex_trylock)        (BirnetMutex       *mutex); /* 0==has_lock */
-  void              (*mutex_unlock)         (BirnetMutex       *mutex);
-  void              (*mutex_destroy)        (BirnetMutex       *mutex);
-  void              (*rec_mutex_init)       (BirnetRecMutex    *mutex);
-  void              (*rec_mutex_lock)       (BirnetRecMutex    *mutex);
-  int               (*rec_mutex_trylock)    (BirnetRecMutex    *mutex); /* 0==has_lock */
-  void              (*rec_mutex_unlock)     (BirnetRecMutex    *mutex);
-  void              (*rec_mutex_destroy)    (BirnetRecMutex    *mutex);
-  void              (*cond_init)            (BirnetCond        *cond);
-  void              (*cond_signal)          (BirnetCond        *cond);
-  void              (*cond_broadcast)       (BirnetCond        *cond);
-  void              (*cond_wait)            (BirnetCond        *cond,
-                                            BirnetMutex       *mutex);
-  void             (*cond_wait_timed)      (BirnetCond        *cond,
-                                            BirnetMutex       *mutex,
-                                            BirnetInt64        max_useconds);
-  void              (*cond_destroy)         (BirnetCond        *cond);
-} BirnetThreadTable;
 /* --- implementation bits --- */
 /* the above macros rely on a problem handler macro: */
 // BIRNET__RUNTIME_PROBLEM(ErrorWarningReturnAssertNotreach,domain,file,line,funcname,exprformat,...); // 
noreturn cases: 'E', 'A', 'N'
diff --git a/birnet/birnetutils.cc b/birnet/birnetutils.cc
index eea6dc0..785fa22 100644
--- a/birnet/birnetutils.cc
+++ b/birnet/birnetutils.cc
@@ -2,7 +2,6 @@
 #include <glib.h>
 #include "birnetutils.hh"
 #include "birnetutf8.hh"
-#include "birnetthread.hh"
 #include "birnetmsg.hh"
 #include "birnetcpu.hh"
 #include <unistd.h>
@@ -134,6 +133,7 @@ birnet_init (int        *argcp,
              const char *app_name,
              InitValue   ivalues[])
 {
+
   /* mandatory initial initialization */
   if (!g_threads_got_initialized)
     g_thread_init (NULL);
@@ -165,7 +165,6 @@ birnet_init (int        *argcp,
   }
   /* initialize sub systems */
   _birnet_init_cpuinfo();
-  _birnet_init_threads();
   if (run_init_hooks)
     run_init_hooks();
 }
@@ -816,17 +815,17 @@ static struct {
 #endif
 #define DELETABLE_MAP_HASH      (19)    /* use prime size for hashing, sum up to roughly 1k (use 83 for 4k) 
*/
 struct DeletableMap {
-  Mutex                                         mutex;
+  Rapicorn::Mutex                               mutex;
   std::map<Deletable*,Deletable::DeletionHook*> dmap;
 };
-static DeletableMap * volatile deletable_maps = NULL;
+static Rapicorn::Atomic<DeletableMap*> deletable_maps = NULL;
 static inline void
 auto_init_deletable_maps (void)
 {
   if (UNLIKELY (deletable_maps == NULL))
     {
       DeletableMap *dmaps = new DeletableMap[DELETABLE_MAP_HASH];
-      if (!Atomic::ptr_cas (&deletable_maps, (DeletableMap*) NULL, dmaps))
+      if (!deletable_maps.cas ((DeletableMap*) NULL, dmaps))
         delete dmaps;
     }
 }
@@ -928,24 +927,7 @@ Deletable::invoke_deletion_hooks()
         }
     }
 }
-/* --- ReferenceCountImpl --- */
-void
-ReferenceCountImpl::ref_diag (const char *msg) const
-{
-  fprintf (stderr, "%s: this=%p ref_count=%d floating=%d", msg ? msg : "ReferenceCountImpl", this, 
ref_count(), floating());
-}
-void
-ReferenceCountImpl::finalize ()
-{}
-void
-ReferenceCountImpl::delete_this ()
-{
-  delete this;
-}
-ReferenceCountImpl::~ReferenceCountImpl ()
-{
-  BIRNET_ASSERT (ref_count() == 0);
-}
+
 /* --- DataList --- */
 DataList::NodeBase::~NodeBase ()
 {}
@@ -1189,7 +1171,7 @@ typedef struct {
   GDestroyNotify handler;
   void          *data;
 } Cleanup;
-static Mutex cleanup_mutex;
+static Rapicorn::Mutex cleanup_mutex;
 static GSList *cleanup_list = NULL;
 static void
 cleanup_exec_Lm (Cleanup *cleanup)
diff --git a/birnet/birnetutils.hh b/birnet/birnetutils.hh
index 6e82a4f..14ee735 100644
--- a/birnet/birnetutils.hh
+++ b/birnet/birnetutils.hh
@@ -91,8 +91,6 @@ void    raise_sigtrap           ();
 #else   /* !__i386__ && !__alpha__ */
 //extern inline void BREAKPOINT() { raise_sigtrap(); }
 #endif  /* __i386__ */
-/* --- threading implementaiton bit --- */
-extern BirnetThreadTable ThreadTable; /* private, provided by birnetthreadimpl.cc */
 /* --- string functionality --- */
 String                         string_tolower           (const String &str);
 String                         string_toupper           (const String &str);
@@ -231,105 +229,10 @@ protected:
   void           invoke_deletion_hooks ();
   virtual       ~Deletable             ();
 };
+
 /* --- ReferenceCountImpl --- */
-class ReferenceCountImpl : public virtual Deletable
-{
-  volatile mutable uint32 ref_field;
-  static const uint32     FLOATING_FLAG = 1 << 31;
-  inline bool
-  ref_cas (uint32       oldv,
-           uint32       newv) const
-  {
-    return ThreadTable.atomic_uint_cas (&ref_field, oldv, newv);
-  }
-  inline uint32
-  ref_get() const
-  {
-    return ThreadTable.atomic_uint_get (&ref_field);
-  }
-protected:
-  inline uint32
-  ref_count() const
-  {
-    return ref_get() & ~FLOATING_FLAG;
-  }
-public:
-  ReferenceCountImpl() :
-    ref_field (FLOATING_FLAG + 1)
-  {}
-  bool
-  floating() const
-  {
-    return 0 != (ref_get() & FLOATING_FLAG);
-  }
-  void
-  ref() const
-  {
-    BIRNET_ASSERT (ref_count() > 0);
-    uint32 old_ref, new_ref;
-    do {
-      old_ref = ref_get();
-      new_ref = old_ref + 1;
-      BIRNET_ASSERT (new_ref & ~FLOATING_FLAG); /* catch overflow */
-    } while (!ref_cas (old_ref, new_ref));
-  }
-  void
-  ref_sink() const
-  {
-    BIRNET_ASSERT (ref_count() > 0);
-    ref();
-    uint32 old_ref, new_ref;
-    do {
-      old_ref = ref_get();
-      new_ref = old_ref & ~FLOATING_FLAG;
-    } while (!ref_cas (old_ref, new_ref));
-    if (old_ref & FLOATING_FLAG)
-      unref();
-  }
-  bool
-  finalizing() const
-  {
-    return ref_count() < 1;
-  }
-  void
-  unref() const
-  {
-    BIRNET_ASSERT (ref_count() > 0);
-    uint32 old_ref, new_ref;
-    do {
-      old_ref = ref_get();
-      BIRNET_ASSERT (old_ref & ~FLOATING_FLAG); /* catch underflow */
-      new_ref = old_ref - 1;
-    } while (!ref_cas (old_ref, new_ref));
-    if (0 == (new_ref & ~FLOATING_FLAG))
-      {
-        ReferenceCountImpl *self = const_cast<ReferenceCountImpl*> (this);
-        self->finalize();
-        self->delete_this(); // effectively: delete this;
-      }
-  }
-  void                            ref_diag (const char *msg = NULL) const;
-  template<class Obj> static Obj& ref      (Obj &obj) { obj.ref();       return obj; }
-  template<class Obj> static Obj* ref      (Obj *obj) { obj->ref();      return obj; }
-  template<class Obj> static Obj& ref_sink (Obj &obj) { obj.ref_sink();  return obj; }
-  template<class Obj> static Obj* ref_sink (Obj *obj) { obj->ref_sink(); return obj; }
-  template<class Obj> static void unref    (Obj &obj) { obj.unref(); }
-  template<class Obj> static void unref    (Obj *obj) { obj->unref(); }
-  template<class Obj> static void sink     (Obj &obj) { obj.ref_sink(); obj.unref(); }
-  template<class Obj> static void sink     (Obj *obj) { obj->ref_sink(); obj->unref(); }
-protected:
-  virtual void finalize           ();
-  virtual void delete_this        ();
-  virtual     ~ReferenceCountImpl ();
-};
-template<class Obj> static Obj& ref      (Obj &obj) { obj.ref();       return obj; }
-template<class Obj> static Obj* ref      (Obj *obj) { obj->ref();      return obj; }
-template<class Obj> static Obj& ref_sink (Obj &obj) { obj.ref_sink();  return obj; }
-template<class Obj> static Obj* ref_sink (Obj *obj) { obj->ref_sink(); return obj; }
-template<class Obj> static void unref    (Obj &obj) { obj.unref(); }
-template<class Obj> static void unref    (Obj *obj) { obj->unref(); }
-template<class Obj> static void sink     (Obj &obj) { obj.ref_sink(); obj.unref(); }
-template<class Obj> static void sink     (Obj *obj) { obj->ref_sink(); obj->unref(); }
+typedef Rapicorn::ReferenceCountable ReferenceCountImpl;
+
 /* --- Binary Lookups --- */
 template<typename RandIter, class Cmp, typename Arg, int case_lookup_or_sibling_or_insertion>
 static inline std::pair<RandIter,bool>
@@ -571,8 +474,7 @@ public:
     return n_elements;
   }
 };
-/* --- implementation --- */
-void _birnet_init_threads (void);
+
 } // Birnet
 #endif /* __BIRNET_UTILS_XX_HH__ */
 /* vim:set ts=8 sts=2 sw=2: */
diff --git a/birnet/tests/datalist.cc b/birnet/tests/datalist.cc
index 4b7f8ec..d1f12aa 100644
--- a/birnet/tests/datalist.cc
+++ b/birnet/tests/datalist.cc
@@ -80,14 +80,6 @@ data_list_test ()
     data_list_test_strings (r);
   }
   TDONE();
-  TSTART ("DataList-threaded");
-  {
-    Thread &thread = Thread::self();
-    data_list_test_strings (thread);
-    data_list_test_ints (thread);
-    data_list_test_strings (thread);
-  }
-  TDONE();
 }
 } // anon
 int


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]