Belle II Software  release-08-01-10
RWLock.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include "daq/slc/system/RWLock.h"
9 
10 using namespace Belle2;
11 
12 RWLock::RWLock() : m_lock() {}
13 
14 RWLock::~RWLock() {}
15 
16 bool RWLock::init()
17 {
18  pthread_rwlockattr_t attr;
19  pthread_rwlockattr_init(&attr);
20  pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
21  pthread_rwlock_init(&m_lock, &attr);
22  pthread_rwlockattr_destroy(&attr);
23  return true;
24 }
25 
26 bool RWLock::rdlock()
27 {
28  if (pthread_rwlock_rdlock(&m_lock) != 0) {
29  return false;
30  } else {
31  return true;
32  }
33 }
34 
35 bool RWLock::wrlock()
36 {
37  if (pthread_rwlock_wrlock(&m_lock) != 0) {
38  return false;
39  }
40  return true;
41 }
42 
43 bool RWLock::unlock()
44 {
45  if (pthread_rwlock_unlock(&m_lock) != 0) {
46  return true;
47  } else {
48  return false;
49  }
50 }
51 
52 bool RWLock::destroy()
53 {
54  if (pthread_rwlock_destroy(&m_lock) != 0) {
55  return true;
56  } else {
57  return false;
58  }
59 }
60 
Abstract base class for different kinds of events.