Skip to content

Commit 06713b3

Browse files
committed
Update DelegateMQ library
1 parent ffa0b8e commit 06713b3

File tree

10 files changed

+71
-58
lines changed

10 files changed

+71
-58
lines changed

DelegateMQ/delegate/DelegateAsyncWait.h

Lines changed: 32 additions & 26 deletions
Large diffs are not rendered by default.

DelegateMQ/delegate/DelegateOpt.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
/// @file
55
/// @brief Delegate library options header file.
66

7+
#include <chrono>
8+
9+
namespace dmq
10+
{
11+
using Duration = std::chrono::duration<uint32_t, std::milli>;
12+
}
13+
714
#ifdef DMQ_ASSERTS
815
#include <cassert>
916
// Use assert error handling. Change assert to a different error

DelegateMQ/delegate/MulticastDelegateSafe.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ class MulticastDelegateSafe<RetType(Args...)> : public MulticastDelegate<RetType
106106
/// @param[in] delegate A delegate target to insert
107107
void PushBack(const DelegateType& delegate) {
108108
const std::lock_guard<std::mutex> lock(m_lock);
109-
return BaseType::PushBack(delegate);
109+
BaseType::PushBack(delegate);
110110
}
111111

112112
/// Remove a delegate into the container.
113113
/// @param[in] delegate The delegate target to remove.
114114
void Remove(const DelegateType& delegate) {
115115
const std::lock_guard<std::mutex> lock(m_lock);
116-
return BaseType::Remove(delegate);
116+
BaseType::Remove(delegate);
117117
}
118118

119119
/// Any registered delegates?

DelegateMQ/delegate/Semaphore.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ class Semaphore
2222
~Semaphore() = default;
2323

2424
/// Called to wait on a semaphore to be signaled.
25-
/// @param[in] timeout - timeout in milliseconds
25+
/// @param[in] timeout - semaphore timeout
2626
/// @return Return true if semaphore signaled, false if timeout occurred.
27-
bool Wait(std::chrono::milliseconds timeout)
27+
bool Wait(Duration timeout)
2828
{
2929
std::unique_lock<std::mutex> lk(m_lock);
30-
if (timeout == std::chrono::milliseconds::max())
30+
if (timeout == Duration::max())
3131
{
3232
m_sema.wait(lk, [this] { return m_signaled; });
3333
}

DelegateMQ/predef/serialize/msgpack/Serializer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void make_serialized(msgpack::sbuffer& buffer, Arg1& arg1, Args... args) {
3131
// make_unserialized unserializes each remote function argument
3232
template<typename Arg1, typename... Args>
3333
void make_unserialized(msgpack::unpacker& unpacker, Arg1& arg1, Args&&... args) {
34+
static_assert(!std::is_pointer<Arg1>::value, "Arg1 cannot be a pointer.");
3435
static_assert(!is_const_type<Arg1>::value, "Arg1 cannot be const.");
3536
msgpack::object_handle oh;
3637
if (!unpacker.next(oh))

DelegateMQ/predef/transport/DmqHeader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class DmqHeader
6262
static std::atomic<uint16_t> seqNum(0);
6363

6464
// Atomically increment and return the previous value
65-
return seqNum.fetch_add(1, std::memory_order_relaxed);
65+
return seqNum.fetch_add(1);
6666
}
6767

6868
private:

DelegateMQ/predef/util/AsyncInvoke.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Thread;
2121
/// @param[in] timeout - the time to wait for invoke to complete
2222
/// @param[in] args - the function argument(s) passed to func
2323
template <class Func, class... Args>
24-
auto AsyncInvoke(Func func, Thread& thread, const std::chrono::milliseconds& timeout, Args&&... args) {
24+
auto AsyncInvoke(Func func, Thread& thread, const dmq::Duration& timeout, Args&&... args) {
2525
// Deduce return type of func
2626
using RetType = decltype(func(std::forward<Args>(args)...));
2727

@@ -61,7 +61,7 @@ auto AsyncInvoke(Func func, Thread& thread, const std::chrono::milliseconds& tim
6161
/// @param[in] timeout - the time to wait for invoke to complete
6262
/// @param[in] args - the function argument(s) passed to func
6363
template <class TClass, class Func, class... Args>
64-
auto AsyncInvoke(TClass tclass, Func func, Thread& thread, const std::chrono::milliseconds& timeout, Args&&... args) {
64+
auto AsyncInvoke(TClass tclass, Func func, Thread& thread, const dmq::Duration& timeout, Args&&... args) {
6565
// Deduce return type of func
6666
using RetType = decltype((tclass->*func)(std::forward<Args>(args)...));
6767

DelegateMQ/predef/util/Timer.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ Timer::~Timer()
3838
//------------------------------------------------------------------------------
3939
// Start
4040
//------------------------------------------------------------------------------
41-
void Timer::Start(std::chrono::milliseconds timeout, bool once)
41+
void Timer::Start(dmq::Duration timeout, bool once)
4242
{
43-
if (timeout <= std::chrono::milliseconds(0))
43+
if (timeout <= dmq::Duration(0))
4444
throw std::invalid_argument("Timeout cannot be 0");
4545

4646
const std::lock_guard<std::mutex> lock(m_lock);
@@ -99,14 +99,13 @@ void Timer::CheckExpired()
9999
}
100100

101101
// Call the client's expired callback function
102-
//if (Expired)
103-
Expired();
102+
Expired();
104103
}
105104

106105
//------------------------------------------------------------------------------
107106
// Difference
108107
//------------------------------------------------------------------------------
109-
std::chrono::milliseconds Timer::Difference(std::chrono::milliseconds time1, std::chrono::milliseconds time2)
108+
dmq::Duration Timer::Difference(dmq::Duration time1, dmq::Duration time2)
110109
{
111110
return (time2 - time1);
112111
}
@@ -134,10 +133,10 @@ void Timer::ProcessTimers()
134133
}
135134
}
136135

137-
std::chrono::milliseconds Timer::GetTime()
136+
dmq::Duration Timer::GetTime()
138137
{
139-
auto duration = std::chrono::system_clock::now().time_since_epoch();
140-
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
141-
return millis;
138+
auto now = std::chrono::system_clock::now().time_since_epoch();
139+
auto duration = std::chrono::duration_cast<dmq::Duration>(now);
140+
return duration;
142141
}
143142

DelegateMQ/predef/util/Timer.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class Timer
2020
~Timer(void);
2121

2222
/// Starts a timer for callbacks on the specified timeout interval.
23-
/// @param[in] timeout - the timeout in milliseconds.
23+
/// @param[in] timeout - the timeout.
2424
/// @param[in] once - true if only one timer expiration
25-
void Start(std::chrono::milliseconds timeout, bool once = false);
25+
void Start(dmq::Duration timeout, bool once = false);
2626

2727
/// Stops a timer.
2828
void Stop();
@@ -31,16 +31,16 @@ class Timer
3131
/// @return TRUE if the timer is enabled, FALSE otherwise.
3232
bool Enabled() { return m_enabled; }
3333

34-
/// Get the current time in ticks.
35-
/// @return The current time in ticks.
36-
static std::chrono::milliseconds GetTime();
34+
/// Get the current time.
35+
/// @return The current time.
36+
static dmq::Duration GetTime();
3737

38-
/// Computes the time difference in ticks between two tick values taking into
38+
/// Computes the time difference between two duration values taking into
3939
/// account rollover.
40-
/// @param[in] time1 - time stamp 1 in ticks.
41-
/// @param[in] time2 - time stamp 2 in ticks.
42-
/// @return The time difference in ticks.
43-
static std::chrono::milliseconds Difference(std::chrono::milliseconds time1, std::chrono::milliseconds time2);
40+
/// @param[in] time1 - time stamp 1.
41+
/// @param[in] time2 - time stamp 2.
42+
/// @return The time difference.
43+
static dmq::Duration Difference(dmq::Duration time1, dmq::Duration time2);
4444

4545
/// Called on a periodic basic to service all timer instances.
4646
static void ProcessTimers();
@@ -60,8 +60,8 @@ class Timer
6060
/// A lock to make this class thread safe.
6161
static std::mutex m_lock;
6262

63-
std::chrono::milliseconds m_timeout = std::chrono::milliseconds(0);
64-
std::chrono::milliseconds m_expireTime = std::chrono::milliseconds(0);
63+
dmq::Duration m_timeout = dmq::Duration(0);
64+
dmq::Duration m_expireTime = dmq::Duration(0);
6565
bool m_enabled = false;
6666
bool m_once = false;
6767
static bool m_timerStopped;

DelegateMQ/predef/util/TransportMonitor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TransportMonitor : public ITransportMonitor
2525
// either the Remove() caller's thread or the Process() caller's thread.
2626
dmq::MulticastDelegateSafe<void(dmq::DelegateRemoteId id, uint16_t seqNum, Status status)> SendStatusCb;
2727

28-
TransportMonitor(const std::chrono::milliseconds& timeout) : TRANSPORT_TIMEOUT(timeout) {}
28+
TransportMonitor(const dmq::Duration timeout) : TRANSPORT_TIMEOUT(timeout) {}
2929
~TransportMonitor()
3030
{
3131
const std::unique_lock<std::mutex> lock(m_lock);
@@ -67,7 +67,7 @@ class TransportMonitor : public ITransportMonitor
6767
while (it != m_pending.end())
6868
{
6969
// Calculate the elapsed time as a duration
70-
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - (*it).second.timeStamp);
70+
auto elapsed = std::chrono::duration_cast<dmq::Duration>(now - (*it).second.timeStamp);
7171

7272
// Has timeout expired?
7373
if (elapsed > TRANSPORT_TIMEOUT)
@@ -90,7 +90,7 @@ class TransportMonitor : public ITransportMonitor
9090
};
9191

9292
std::map<uint16_t, TimeoutData> m_pending;
93-
const std::chrono::milliseconds TRANSPORT_TIMEOUT;
93+
const dmq::Duration TRANSPORT_TIMEOUT;
9494
std::mutex m_lock;
9595
};
9696

0 commit comments

Comments
 (0)