Jpp  17.3.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ptrDispatcher Class Reference

#include <ptr_dispatcher.hh>

Public Member Functions

 ptrDispatcher ()
 
 ~ptrDispatcher ()
 
void close ()
 
void signal ()
 
void lock ()
 
void unlock ()
 
void * get_nolock ()
 
void * get ()
 
void put_nolock (void *pointer)
 
void put (void *pointer)
 

Private Member Functions

void wait ()
 

Private Attributes

std::deque< void * > m_queue
 
pthread_mutex_t m_mutex
 
pthread_cond_t m_cond
 
boost::atomic< bool > m_status
 

Detailed Description

Author
cpellegrino

Definition at line 12 of file ptr_dispatcher.hh.

Constructor & Destructor Documentation

ptrDispatcher::ptrDispatcher ( )
inline

Definition at line 24 of file ptr_dispatcher.hh.

25  :
26  m_status(true)
27  {
28  pthread_mutex_init(&m_mutex, 0);
29  pthread_cond_init (&m_cond, 0);
30  }
boost::atomic< bool > m_status
pthread_cond_t m_cond
pthread_mutex_t m_mutex
ptrDispatcher::~ptrDispatcher ( )
inline

Definition at line 32 of file ptr_dispatcher.hh.

33  {
34  close();
35  pthread_mutex_destroy(&m_mutex);
36  pthread_cond_destroy(&m_cond);
37  }
pthread_cond_t m_cond
pthread_mutex_t m_mutex

Member Function Documentation

void ptrDispatcher::close ( )
inline

Definition at line 39 of file ptr_dispatcher.hh.

40  {
41  m_status = false;
42  lock();
43  signal();
44  unlock();
45  }
boost::atomic< bool > m_status
void ptrDispatcher::signal ( )
inline

Definition at line 47 of file ptr_dispatcher.hh.

48  {
49  pthread_cond_signal(&m_cond);
50  }
pthread_cond_t m_cond
void ptrDispatcher::lock ( )
inline

Definition at line 52 of file ptr_dispatcher.hh.

53  {
54  pthread_mutex_lock(&m_mutex);
55  }
pthread_mutex_t m_mutex
void ptrDispatcher::unlock ( )
inline

Definition at line 57 of file ptr_dispatcher.hh.

58  {
59  pthread_mutex_unlock(&m_mutex);
60  }
pthread_mutex_t m_mutex
void* ptrDispatcher::get_nolock ( )
inline

Definition at line 62 of file ptr_dispatcher.hh.

63  {
64  if (m_queue.empty() || !m_status)
65  {
66  return 0;
67  }
68 
69  void* pointer = m_queue.front();
70  m_queue.pop_front();
71  return pointer;
72  }
boost::atomic< bool > m_status
std::deque< void * > m_queue
void* ptrDispatcher::get ( )
inline

Definition at line 74 of file ptr_dispatcher.hh.

75  {
76  if (!m_status)
77  {
78  return 0;
79  }
80 
81  lock();
82  wait();
83 
84  void* pointer = 0;
85 
86  if (m_queue.size())
87  {
88  pointer = m_queue.front();
89  m_queue.pop_front();
90  }
91 
92  unlock();
93  return pointer;
94  }
boost::atomic< bool > m_status
std::deque< void * > m_queue
void ptrDispatcher::put_nolock ( void *  pointer)
inline

Definition at line 96 of file ptr_dispatcher.hh.

97  {
98  if (m_status)
99  {
100  m_queue.push_back(pointer);
101  }
102  }
boost::atomic< bool > m_status
std::deque< void * > m_queue
void ptrDispatcher::put ( void *  pointer)
inline

Definition at line 104 of file ptr_dispatcher.hh.

105  {
106  if (m_status)
107  {
108  lock();
109  m_queue.push_back(pointer);
110  signal();
111  unlock();
112  }
113  }
boost::atomic< bool > m_status
std::deque< void * > m_queue
void ptrDispatcher::wait ( )
inlineprivate

Definition at line 117 of file ptr_dispatcher.hh.

118  {
119  while (m_queue.empty() && m_status)
120  {
121  if (pthread_cond_wait(&m_cond, &m_mutex) == EINVAL)
122  {
123  break;
124  }
125  }
126  }
boost::atomic< bool > m_status
pthread_cond_t m_cond
std::deque< void * > m_queue
pthread_mutex_t m_mutex

Member Data Documentation

std::deque<void*> ptrDispatcher::m_queue
private

Definition at line 14 of file ptr_dispatcher.hh.

pthread_mutex_t ptrDispatcher::m_mutex
private

Definition at line 16 of file ptr_dispatcher.hh.

pthread_cond_t ptrDispatcher::m_cond
private

Definition at line 18 of file ptr_dispatcher.hh.

boost::atomic<bool> ptrDispatcher::m_status
private

Definition at line 20 of file ptr_dispatcher.hh.


The documentation for this class was generated from the following file: