1 #ifndef __EVENT_LOOP_H__
 
   2 #define __EVENT_LOOP_H__
 
   6 #include "stg/noncopyable.h"
 
   9 class EVENT_LOOP : private NONCOPYABLE,
 
  15         bool IsRunning() const { return _running; }
 
  17         template <class ACTIVE_CLASS, typename DATA_TYPE>
 
  18         void Enqueue(ACTIVE_CLASS & ac,
 
  19                      typename ACTOR<ACTIVE_CLASS, DATA_TYPE>::TYPE a,
 
  26         pthread_mutex_t _mutex;
 
  27         pthread_cond_t _condition;
 
  30         virtual ~EVENT_LOOP();
 
  32         static void * Run(void *);
 
  35         friend class EVENT_LOOP_SINGLETON;
 
  38 class EVENT_LOOP_SINGLETON : private NONCOPYABLE
 
  41         static EVENT_LOOP & GetInstance();
 
  44         static EVENT_LOOP * _instance;
 
  45         static void CreateInstance();
 
  47         EVENT_LOOP_SINGLETON() {}
 
  48         ~EVENT_LOOP_SINGLETON() {}
 
  51 template <class ACTIVE_CLASS, typename DATA_TYPE>
 
  52 void EVENT_LOOP::Enqueue(ACTIVE_CLASS & ac,
 
  53                          typename ACTOR<ACTIVE_CLASS, DATA_TYPE>::TYPE a,
 
  56 STG_LOCKER lock(&_mutex, __FILE__, __LINE__);
 
  58 ACTIONS_LIST::Enqueue(ac, a, d);
 
  59 // Signal about new action
 
  60 pthread_cond_signal(&_condition);