Coverage Report

Created: 2025-08-28 07:02

/src/poco/Foundation/include/Poco/Event.h
Line
Count
Source (jump to first uncovered line)
1
//
2
// Event.h
3
//
4
// Library: Foundation
5
// Package: Threading
6
// Module:  Event
7
//
8
// Definition of the Event class.
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_INCLUDED
18
#define Foundation_Event_INCLUDED
19
20
21
#include "Poco/Foundation.h"
22
#include "Poco/Exception.h"
23
24
25
#if defined(POCO_OS_FAMILY_WINDOWS)
26
#include "Poco/Event_WIN32.h"
27
#elif defined(POCO_VXWORKS)
28
#include "Poco/Event_VX.h"
29
#else
30
#include "Poco/Event_POSIX.h"
31
#endif
32
33
34
namespace Poco {
35
36
37
class Foundation_API Event: private EventImpl
38
  /// An Event is a synchronization object that
39
  /// allows one thread to signal one or more
40
  /// other threads that a certain event
41
  /// has happened.
42
  /// Usually, one thread signals an event,
43
  /// while one or more other threads wait
44
  /// for an event to become signalled.
45
{
46
public:
47
  enum EventType
48
  {
49
    EVENT_MANUALRESET, /// Manual reset event
50
    EVENT_AUTORESET    /// Auto-reset event
51
  };
52
53
  explicit Event(EventType type = EVENT_AUTORESET);
54
    /// Creates the event. If type is EVENT_AUTORESET,
55
    /// the event is automatically reset after
56
    /// a wait() successfully returns.
57
58
  POCO_DEPRECATED("")
59
  explicit Event(bool autoReset);
60
    /// Please use Event::Event(EventType) instead.
61
62
  ~Event();
63
    /// Destroys the event.
64
65
  void set();
66
    /// Signals the event. If autoReset is true,
67
    /// only one thread waiting for the event
68
    /// can resume execution.
69
    /// If autoReset is false, all waiting threads
70
    /// can resume execution.
71
72
  void wait();
73
    /// Waits for the event to become signalled.
74
75
  void wait(long milliseconds);
76
    /// Waits for the event to become signalled.
77
    /// Throws a TimeoutException if the event
78
    /// does not become signalled within the specified
79
    /// time interval.
80
81
  bool tryWait(long milliseconds);
82
    /// Waits for the event to become signalled.
83
    /// Returns true if the event
84
    /// became signalled within the specified
85
    /// time interval, false otherwise.
86
87
  void reset();
88
    /// Resets the event to unsignalled state.
89
90
private:
91
  Event(const Event&);
92
  Event& operator = (const Event&);
93
};
94
95
96
//
97
// inlines
98
//
99
inline void Event::set()
100
0
{
101
0
  setImpl();
102
0
}
103
104
105
inline void Event::wait()
106
0
{
107
0
  waitImpl();
108
0
}
109
110
111
inline void Event::wait(long milliseconds)
112
0
{
113
0
  if (!waitImpl(milliseconds))
114
0
    throw TimeoutException();
115
0
}
116
117
118
inline bool Event::tryWait(long milliseconds)
119
0
{
120
0
  return waitImpl(milliseconds);
121
0
}
122
123
124
inline void Event::reset()
125
0
{
126
0
  resetImpl();
127
0
}
128
129
130
} // namespace Poco
131
132
133
#endif // Foundation_Event_INCLUDED