Belle II Software development
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
10using namespace Belle2;
11
12RWLock::RWLock() : m_lock() {}
13
14RWLock::~RWLock() {}
15
16bool 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
26bool RWLock::rdlock()
27{
28 if (pthread_rwlock_rdlock(&m_lock) != 0) {
29 return false;
30 } else {
31 return true;
32 }
33}
34
35bool RWLock::wrlock()
36{
37 if (pthread_rwlock_wrlock(&m_lock) != 0) {
38 return false;
39 }
40 return true;
41}
42
43bool RWLock::unlock()
44{
45 if (pthread_rwlock_unlock(&m_lock) != 0) {
46 return true;
47 } else {
48 return false;
49 }
50}
51
52bool 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.