fix8  version 1.4.0
Open Source C++ FIX Framework
FIX8::_f8_threadcore Class Referenceabstract

pthread wrapper abstract base More...

#include <thread.hpp>

Inheritance diagram for FIX8::_f8_threadcore:
FIX8::f8_thread< FIX8::AsyncSocket > FIX8::f8_thread< FIX8::FIXReader > FIX8::f8_thread< FIX8::Logger > FIX8::f8_thread< FIX8::ReliableClientSession< T > > FIX8::f8_thread< FIX8::Timer > FIX8::f8_thread< T >

Public Member Functions

 _f8_threadcore ()
 
virtual ~_f8_threadcore ()
 Dtor. More...
 
virtual int start ()=0
 
virtual void request_stop ()=0
 
virtual int join (int timeoutInMs=0)
 
int yield () const
 
thread_id_t get_threadid () const
 
bool operator== (const _f8_threadcore &that) const
 
bool operator!= (const _f8_threadcore &that) const
 
_f8_threadcoreoperator= (const _f8_threadcore &)=delete
 

Static Public Member Functions

static thread_id_t getid ()
 

Protected Member Functions

template<typename T >
int _start (void *sub)
 

Static Private Member Functions

template<typename T >
static void * _run (void *what)
 

Private Attributes

pthread_attr_t _attr
 
pthread_t _tid
 

Detailed Description

pthread wrapper abstract base

Definition at line 65 of file thread.hpp.

Constructor & Destructor Documentation

FIX8::_f8_threadcore::_f8_threadcore ( )
inline

Ctor.

Definition at line 96 of file thread.hpp.

98  : _attr(), _tid()
99  {
100  if (pthread_attr_init(&_attr))
101  throw f8_threadException("pthread_attr_init failure");
102 #else
103  {
104 #endif
105  }
pthread_t _tid
Definition: thread.hpp:69
pthread_attr_t _attr
Definition: thread.hpp:68
virtual FIX8::_f8_threadcore::~_f8_threadcore ( )
inlinevirtual

Dtor.

Definition at line 108 of file thread.hpp.

References join().

109  {
110  join();
111 #if (FIX8_THREAD_SYSTEM == FIX8_THREAD_PTHREAD)
112  pthread_attr_destroy(&_attr);
113 #endif
114  }
virtual int join(int timeoutInMs=0)
Definition: thread.hpp:126
pthread_attr_t _attr
Definition: thread.hpp:68

Member Function Documentation

template<typename T >
static void* FIX8::_f8_threadcore::_run ( void *  what)
inlinestaticprivate

Definition at line 76 of file thread.hpp.

76 { return reinterpret_cast<void *>((*static_cast<T *>(what))()); }
template<typename T >
int FIX8::_f8_threadcore::_start ( void *  sub)
inlineprotected

Definition at line 84 of file thread.hpp.

85  {
86 #if (FIX8_THREAD_SYSTEM == FIX8_THREAD_PTHREAD)
87  return pthread_create(&_tid, &_attr, _run<T>, sub);
88 #elif (FIX8_THREAD_SYSTEM == FIX8_THREAD_STDTHREAD)
89  _thread.reset(new std::thread(_run<T>, sub));
90 #endif
91  return 0;
92  }
pthread_t _tid
Definition: thread.hpp:69
pthread_attr_t _attr
Definition: thread.hpp:68
thread_id_t FIX8::_f8_threadcore::get_threadid ( ) const
inline

Get the thread's thread ID.

Returns
the thread id

Definition at line 157 of file thread.hpp.

References _tid.

Referenced by join(), operator!=(), and operator==().

158  {
159 #if (FIX8_THREAD_SYSTEM == FIX8_THREAD_PTHREAD)
160  return _tid;
161 #elif (FIX8_THREAD_SYSTEM == FIX8_THREAD_STDTHREAD)
162  return _thread.get() ? _thread->get_id() : std::thread::id();
163 #endif
164  }
pthread_t _tid
Definition: thread.hpp:69
static thread_id_t FIX8::_f8_threadcore::getid ( )
inlinestatic

Get the thread's thread ID. Static version.

Returns
the thread id

Definition at line 168 of file thread.hpp.

Referenced by join().

169  {
170 #if (FIX8_THREAD_SYSTEM == FIX8_THREAD_PTHREAD)
171  return pthread_self();
172 #elif (FIX8_THREAD_SYSTEM == FIX8_THREAD_STDTHREAD)
173  return std::this_thread::get_id();
174 #endif
175  }
virtual int FIX8::_f8_threadcore::join ( int  timeoutInMs = 0)
inlinevirtual

Join the thread.

Returns
result of join

Definition at line 126 of file thread.hpp.

References get_threadid(), and getid().

Referenced by FIX8::AsyncSocket< f8String >::join(), FIX8::Timer< FIX8::Session >::join(), FIX8::FIXReader::quit(), FIX8::Logger::stop(), ~_f8_threadcore(), and FIX8::ReliableClientSession< T >::~ReliableClientSession().

127  {
128 #if (FIX8_THREAD_SYSTEM == FIX8_THREAD_PTHREAD)
129  return getid() != get_threadid() ? pthread_join(_tid, nullptr) ? -1 : 0 : -1; // prevent self-join
130 #elif (FIX8_THREAD_SYSTEM == FIX8_THREAD_STDTHREAD)
131  if (_thread.get() && _thread->joinable() && getid() != get_threadid())
132  _thread->join();
133  return 0;
134 #endif
135  }
static thread_id_t getid()
Definition: thread.hpp:168
pthread_t _tid
Definition: thread.hpp:69
thread_id_t get_threadid() const
Definition: thread.hpp:157
bool FIX8::_f8_threadcore::operator!= ( const _f8_threadcore that) const
inline

f8_thread inequivalence operator.

Parameters
thatthe other thread id
Returns
true if the threads are unequal

Definition at line 192 of file thread.hpp.

References _tid, and get_threadid().

193  {
194 #if (FIX8_THREAD_SYSTEM == FIX8_THREAD_PTHREAD)
195  return !pthread_equal(_tid, that._tid);
196 #else
197  return get_threadid() != that.get_threadid();
198 #endif
199  }
pthread_t _tid
Definition: thread.hpp:69
thread_id_t get_threadid() const
Definition: thread.hpp:157
_f8_threadcore& FIX8::_f8_threadcore::operator= ( const _f8_threadcore )
delete
bool FIX8::_f8_threadcore::operator== ( const _f8_threadcore that) const
inline

f8_thread equivalence operator.

Parameters
thatthe other thread id
Returns
true if the threads are equal

Definition at line 180 of file thread.hpp.

References _tid, and get_threadid().

181  {
182 #if (FIX8_THREAD_SYSTEM == FIX8_THREAD_PTHREAD)
183  return pthread_equal(_tid, that._tid);
184 #else
185  return get_threadid() == that.get_threadid();
186 #endif
187  }
pthread_t _tid
Definition: thread.hpp:69
thread_id_t get_threadid() const
Definition: thread.hpp:157
virtual void FIX8::_f8_threadcore::request_stop ( )
pure virtual
int FIX8::_f8_threadcore::yield ( ) const
inline

Yield CPU.

Returns
result of yield

Definition at line 143 of file thread.hpp.

144  {
145 #if (FIX8_THREAD_SYSTEM == FIX8_THREAD_PTHREAD)
146  return pthread_yield();
147 #elif (FIX8_THREAD_SYSTEM == FIX8_THREAD_STDTHREAD)
148  std::this_thread::yield();
149 #endif
150  return 0;
151  }

Member Data Documentation

pthread_attr_t FIX8::_f8_threadcore::_attr
private

Definition at line 68 of file thread.hpp.

pthread_t FIX8::_f8_threadcore::_tid
private

Definition at line 69 of file thread.hpp.

Referenced by get_threadid(), operator!=(), and operator==().


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