Coverage Report

Created: 2025-09-05 06:24

/src/poco/Foundation/include/Poco/RWLock_POSIX.h
Line
Count
Source (jump to first uncovered line)
1
//
2
// RWLock_POSIX.h
3
//
4
// Library: Foundation
5
// Package: Threading
6
// Module:  RWLock
7
//
8
// Definition of the RWLockImpl class for POSIX Threads.
9
//
10
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11
// and Contributors.
12
//
13
// SPDX-License-Identifier: BSL-1.0
14
//
15
16
17
#ifndef Foundation_RWLock_POSIX_INCLUDED
18
#define Foundation_RWLock_POSIX_INCLUDED
19
20
21
#include "Poco/Foundation.h"
22
#include "Poco/Exception.h"
23
#include <pthread.h>
24
#include <errno.h>
25
26
27
namespace Poco {
28
29
30
class Foundation_API RWLockImpl
31
{
32
protected:
33
  RWLockImpl();
34
  ~RWLockImpl();
35
  void readLockImpl();
36
  bool tryReadLockImpl();
37
  void writeLockImpl();
38
  bool tryWriteLockImpl();
39
  void unlockImpl();
40
41
private:
42
  pthread_rwlock_t _rwl;
43
};
44
45
46
//
47
// inlines
48
//
49
inline void RWLockImpl::readLockImpl()
50
56.2k
{
51
56.2k
  if (pthread_rwlock_rdlock(&_rwl))
52
0
    throw SystemException("cannot lock reader/writer lock");
53
56.2k
}
54
55
56
inline bool RWLockImpl::tryReadLockImpl()
57
0
{
58
0
  int rc = pthread_rwlock_tryrdlock(&_rwl);
59
0
  if (rc == 0)
60
0
    return true;
61
0
  else if (rc == EBUSY)
62
0
    return false;
63
0
  else
64
0
    throw SystemException("cannot lock reader/writer lock");
65
0
66
0
}
67
68
69
inline void RWLockImpl::writeLockImpl()
70
33
{
71
33
  if (pthread_rwlock_wrlock(&_rwl))
72
0
    throw SystemException("cannot lock reader/writer lock");
73
33
}
74
75
76
inline bool RWLockImpl::tryWriteLockImpl()
77
0
{
78
0
  int rc = pthread_rwlock_trywrlock(&_rwl);
79
0
  if (rc == 0)
80
0
    return true;
81
0
  else if (rc == EBUSY)
82
0
    return false;
83
0
  else
84
0
    throw SystemException("cannot lock reader/writer lock");
85
0
86
0
}
87
88
89
inline void RWLockImpl::unlockImpl()
90
56.2k
{
91
56.2k
  if (pthread_rwlock_unlock(&_rwl))
92
0
    throw SystemException("cannot unlock mutex");
93
56.2k
}
94
95
96
} // namespace Poco
97
98
99
#endif // Foundation_RWLock_POSIX_INCLUDED