Develop Biology
The language of life
bio::ThreadSafe Class Reference

#include <ThreadSafe.h>

+ Inheritance diagram for bio::ThreadSafe:

Public Member Functions

 ThreadSafe ()
 
 ThreadSafe (const ThreadSafe &toCopy)
 
virtual ~ThreadSafe ()
 
void LockThread () const
 
void UnlockThread () const
 

Detailed Description

ThreadSafe classes are ones that can work with threads. They are meant to be simple and abstract. The actual interface of ThreadSafe methods is c++ version and platform specific. Fortunately, threading was standardized in c++11; however, we do still support c++98 builds. At this time, ThreadSafe methods are only implemented for c++11 and on and on linux systems using c++98 and on. Support for c++98 on other platforms may or may not ever happen.

NOTE: if you do not need threading and don't want to waste time locking & unlocking a single thread all the time, check out Optimize.h (in bio/common), which will let you turn off threading for an extra performance boost.

Definition at line 48 of file ThreadSafe.h.

Constructor & Destructor Documentation

◆ ThreadSafe() [1/2]

bio::ThreadSafe::ThreadSafe ( )

Definition at line 26 of file ThreadSafe.cpp.

30 :
31 m_mutex(),
32 m_lock(m_mutex, std::defer_lock)
33 #endif
34 //@formatter:on
35{
36 //@formatter:off
37 #if BIO_CPP_VERSION < 11
38 #ifdef BIO_OS_IS_LINUX
39 pthread_mutexattr_t mutexattr;
40 pthread_mutexattr_init(&mutexattr);
41 pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
42 pthread_mutex_init(&m_lock, &mutexattr);
43 #endif
44 #else
45 #endif
46 //@formatter:on
47}

◆ ThreadSafe() [2/2]

bio::ThreadSafe::ThreadSafe ( const ThreadSafe toCopy)
Parameters
toCopy

Definition at line 49 of file ThreadSafe.cpp.

53 :
54 m_mutex(),
55 m_lock(m_mutex, std::defer_lock)
56 #endif
57 //@formatter:on
58{
59 //@formatter:off
60 #if BIO_CPP_VERSION < 11
61 #ifdef BIO_OS_IS_LINUX
62 pthread_mutexattr_t mutexattr;
63 pthread_mutexattr_init(&mutexattr);
64 pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
65 pthread_mutex_init(&m_lock, &mutexattr);
66 #endif
67 #else
68 #endif
69 //@formatter:on
70}

◆ ~ThreadSafe()

bio::ThreadSafe::~ThreadSafe ( )
virtual

Definition at line 72 of file ThreadSafe.cpp.

73{
74 //@formatter:off
75 #if BIO_CPP_VERSION < 11
76 #ifdef BIO_OS_IS_LINUX
77 pthread_mutex_destroy(&m_lock);
78 #endif
79 #else
80 #endif
81 //@formatter:on
82}

Member Function Documentation

◆ LockThread()

void bio::ThreadSafe::LockThread ( ) const

uses const_cast to call LockThread().

Definition at line 84 of file ThreadSafe.cpp.

85{
86 //@formatter:off
87 #if BIO_CPP_VERSION < 11
88 #ifdef BIO_OS_IS_LINUX
89 pthread_mutex_lock(&m_lock);
90 #endif
91 #else
92 m_lock.lock();
93 #endif
94 //@formatter:on
95}

Referenced by bio::physical::Perspective< DIMENSION >::~Perspective(), bio::chemical::UnorderedStructureInterface::Add(), bio::chemical::PeriodicTableImplementation::AssociateType(), bio::physical::Perspective< DIMENSION >::AssociateType(), bio::chemical::UnorderedStructureInterface::Clear(), bio::chemical::PeriodicTableImplementation::DisassociateType(), bio::physical::Perspective< DIMENSION >::DisassociateType(), bio::physical::Perspective< DIMENSION >::Find(), bio::chemical::LinearStructureInterface::ForEach(), bio::chemical::UnorderedStructureInterface::GetAll(), bio::chemical::LinearStructureInterface::GetById(), bio::chemical::LinearStructureInterface::GetByName(), bio::chemical::UnorderedStructureInterface::GetCount(), bio::physical::Perspective< DIMENSION >::GetIdFromName(), bio::chemical::UnorderedStructureInterface::GetNumMatching(), bio::chemical::LinearStructureInterface::GetOrCreateById(), bio::chemical::LinearStructureInterface::GetOrCreateByName(), bio::chemical::PeriodicTableImplementation::GetPropertiesOf(), bio::chemical::UnorderedStructureInterface::GetStringFrom(), bio::chemical::UnorderedStructureInterface::Has(), bio::chemical::UnorderedStructureInterface::HasAll(), bio::chemical::UnorderedStructureInterface::Import(), bio::chemical::UnorderedStructureInterface::ImportAll(), bio::chemical::LinearStructureInterface::Insert(), bio::Threaded::IsRunning(), bio::chemical::PeriodicTableImplementation::RecordPropertiesOf(), bio::chemical::UnorderedStructureInterface::Remove(), bio::Threaded::RequestStop(), bio::Threaded::Start(), bio::Threaded::Stop(), and bio::Threaded::Worker().

◆ UnlockThread()

void bio::ThreadSafe::UnlockThread ( ) const

uses const_cast to call UnlockThread().

Definition at line 97 of file ThreadSafe.cpp.

98{
99 //@formatter:off
100 #if BIO_CPP_VERSION < 11
101 #ifdef BIO_OS_IS_LINUX
102 pthread_mutex_unlock(&m_lock);
103 #endif
104 #else
105 m_lock.unlock();
106 #endif
107 //@formatter:on
108}

Referenced by bio::physical::Perspective< DIMENSION >::~Perspective(), bio::chemical::UnorderedStructureInterface::Add(), bio::chemical::PeriodicTableImplementation::AssociateType(), bio::physical::Perspective< DIMENSION >::AssociateType(), bio::chemical::UnorderedStructureInterface::Clear(), bio::chemical::PeriodicTableImplementation::DisassociateType(), bio::physical::Perspective< DIMENSION >::DisassociateType(), bio::physical::Perspective< DIMENSION >::Find(), bio::chemical::LinearStructureInterface::ForEach(), bio::chemical::UnorderedStructureInterface::GetAll(), bio::chemical::LinearStructureInterface::GetById(), bio::chemical::LinearStructureInterface::GetByName(), bio::chemical::UnorderedStructureInterface::GetCount(), bio::physical::Perspective< DIMENSION >::GetIdFromName(), bio::chemical::UnorderedStructureInterface::GetNumMatching(), bio::chemical::LinearStructureInterface::GetOrCreateById(), bio::chemical::LinearStructureInterface::GetOrCreateByName(), bio::chemical::PeriodicTableImplementation::GetPropertiesOf(), bio::chemical::UnorderedStructureInterface::GetStringFrom(), bio::chemical::UnorderedStructureInterface::Has(), bio::chemical::UnorderedStructureInterface::HasAll(), bio::chemical::UnorderedStructureInterface::Import(), bio::chemical::UnorderedStructureInterface::ImportAll(), bio::chemical::LinearStructureInterface::Insert(), bio::Threaded::IsRunning(), bio::chemical::PeriodicTableImplementation::RecordPropertiesOf(), bio::chemical::UnorderedStructureInterface::Remove(), bio::Threaded::RequestStop(), bio::Threaded::Start(), bio::Threaded::Stop(), and bio::Threaded::Worker().


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