Coverage Report

Created: 2025-11-23 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/poco/Foundation/include/Poco/Event_POSIX.h
Line
Count
Source
1
//
2
// Event_POSIX.h
3
//
4
// Library: Foundation
5
// Package: Threading
6
// Module:  Event
7
//
8
// Definition of the EventImpl 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_Event_POSIX_INCLUDED
18
#define Foundation_Event_POSIX_INCLUDED
19
20
21
#include "Poco/Foundation.h"
22
#include "Poco/Exception.h"
23
#include <pthread.h>
24
#include <errno.h>
25
#include <atomic>
26
27
28
namespace Poco {
29
30
31
class Foundation_API EventImpl
32
{
33
protected:
34
  EventImpl(bool autoReset);
35
  ~EventImpl();
36
  void setImpl();
37
  void waitImpl();
38
  bool waitImpl(long milliseconds);
39
  void resetImpl();
40
41
private:
42
  std::atomic<bool> _auto;
43
  std::atomic<bool> _state;
44
  pthread_mutex_t _mutex;
45
  pthread_cond_t  _cond;
46
};
47
48
49
//
50
// inlines
51
//
52
inline void EventImpl::setImpl()
53
0
{
54
0
  if (pthread_mutex_lock(&_mutex))
55
0
    throw SystemException("cannot signal event (lock)");
56
0
  _state = true;
57
0
  if (pthread_cond_broadcast(&_cond))
58
0
  {
59
0
    pthread_mutex_unlock(&_mutex);
60
0
    throw SystemException("cannot signal event");
61
0
  }
62
0
  pthread_mutex_unlock(&_mutex);
63
0
}
64
65
66
inline void EventImpl::resetImpl()
67
0
{
68
0
  if (pthread_mutex_lock(&_mutex))
69
0
    throw SystemException("cannot reset event");
70
0
  _state = false;
71
0
  pthread_mutex_unlock(&_mutex);
72
0
}
73
74
75
} // namespace Poco
76
77
78
#endif // Foundation_Event_POSIX_INCLUDED