-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventFlags.cpp
61 lines (51 loc) · 1.72 KB
/
eventFlags.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "eventFlags.hpp"
#include <utility>
namespace ThreadX
{
EventFlags::EventFlags(const std::string_view name, const NotifyCallback &setNotifyCallback)
: Native::TX_EVENT_FLAGS_GROUP{}, m_setNotifyCallback{setNotifyCallback}
{
using namespace Native;
[[maybe_unused]] Error error{tx_event_flags_create(this, const_cast<char *>(name.data()))};
assert(error == Error::success);
if (m_setNotifyCallback)
{
error = Error{tx_event_flags_set_notify(this, EventFlags::setNotifyCallback)};
assert(error == Error::success);
}
}
EventFlags::~EventFlags()
{
[[maybe_unused]] Error error{tx_event_flags_delete(this)};
assert(error == Error::success);
}
Error EventFlags::set(const Bitmask &bitMask)
{
return Error{tx_event_flags_set(this, bitMask.to_ulong(), std::to_underlying(FlagOption::orInto))};
}
Error EventFlags::clear(const Bitmask &bitMask)
{
return Error{tx_event_flags_set(this, (~bitMask).to_ulong(), std::to_underlying(FlagOption::andInto))};
}
EventFlags::BitmaskPair EventFlags::get(const Bitmask &bitMask, const Option option)
{
return waitAllFor(bitMask, TickTimer::noWait, option);
}
EventFlags::BitmaskPair EventFlags::waitAll(const Bitmask &bitMask, const Option option)
{
return waitAllFor(bitMask, TickTimer::waitForever, option);
}
EventFlags::BitmaskPair EventFlags::waitAny(const Bitmask &bitMask, const Option option)
{
return waitAnyFor(bitMask, TickTimer::waitForever, option);
}
std::string_view EventFlags::name() const
{
return tx_event_flags_group_name;
}
void EventFlags::setNotifyCallback(auto notifyGroupPtr)
{
auto &eventFlags{static_cast<EventFlags &>(*notifyGroupPtr)};
eventFlags.m_setNotifyCallback(eventFlags);
}
} // namespace ThreadX