Skip to content

Commit 6ec0fa8

Browse files
committed
Update DelegateMQ library
1 parent a348e37 commit 6ec0fa8

File tree

6 files changed

+49
-45
lines changed

6 files changed

+49
-45
lines changed

DelegateMQ/delegate/Delegate.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -476,46 +476,46 @@ class DelegateMember<TClass, RetType(Args...)> : public Delegate<RetType(Args...
476476
};
477477

478478
template <class C, class R>
479-
struct DelegateMemberShared; // Not defined
479+
struct DelegateMemberSp; // Not defined
480480

481-
/// @brief `DelegateMemberShared<>` class synchronously invokes a class member target
481+
/// @brief `DelegateMemberSp<>` class synchronously invokes a class member target
482482
/// function using a weak pointer.
483483
/// @details This class is a "safe" version of DelegateMember. It holds a std::weak_ptr
484484
/// to the target. If the target is destroyed, the callback is silently dropped.
485485
/// @tparam TClass The class type that contains the member function.
486486
/// @tparam RetType The return type of the bound delegate function.
487487
/// @tparam Args The argument types of the bound delegate function.
488488
template <class TClass, class RetType, class... Args>
489-
class DelegateMemberShared<TClass, RetType(Args...)> : public Delegate<RetType(Args...)> {
489+
class DelegateMemberSp<TClass, RetType(Args...)> : public Delegate<RetType(Args...)> {
490490
public:
491491
typedef TClass* ObjectPtr;
492492
typedef std::shared_ptr<TClass> SharedPtr;
493493
typedef std::weak_ptr<TClass> WeakPtr;
494494
typedef RetType(TClass::* MemberFunc)(Args...);
495495
typedef RetType(TClass::* ConstMemberFunc)(Args...) const;
496-
using ClassType = DelegateMemberShared<TClass, RetType(Args...)>;
496+
using ClassType = DelegateMemberSp<TClass, RetType(Args...)>;
497497

498498
/// @brief Constructor to create a class instance.
499499
/// @param[in] object The target object pointer to store.
500500
/// @param[in] func The target member function to store.
501-
DelegateMemberShared(SharedPtr object, MemberFunc func) { Bind(object, func); }
501+
DelegateMemberSp(SharedPtr object, MemberFunc func) { Bind(object, func); }
502502

503503
/// @brief Constructor to create a class instance.
504504
/// @param[in] object The target object pointer to store.
505505
/// @param[in] func The target const member function to store.
506-
DelegateMemberShared(SharedPtr object, ConstMemberFunc func) { Bind(object, func); }
506+
DelegateMemberSp(SharedPtr object, ConstMemberFunc func) { Bind(object, func); }
507507

508508
/// @brief Copy constructor.
509-
DelegateMemberShared(const ClassType& rhs) { Assign(rhs); }
509+
DelegateMemberSp(const ClassType& rhs) { Assign(rhs); }
510510

511511
/// @brief Move constructor.
512-
DelegateMemberShared(ClassType&& rhs) noexcept : m_object(std::move(rhs.m_object)), m_func(rhs.m_func) { rhs.Clear(); }
512+
DelegateMemberSp(ClassType&& rhs) noexcept : m_object(std::move(rhs.m_object)), m_func(rhs.m_func) { rhs.Clear(); }
513513

514514
/// @brief Default constructor.
515-
DelegateMemberShared() = default;
515+
DelegateMemberSp() = default;
516516

517517
/// @brief Destructor.
518-
~DelegateMemberShared() { Clear(); }
518+
~DelegateMemberSp() { Clear(); }
519519

520520
/// @brief Bind a member function to the delegate.
521521
void Bind(SharedPtr object, MemberFunc func) {
@@ -864,7 +864,7 @@ auto MakeDelegate(const TClass* object, RetType(TClass::* func)(Args... args) co
864864
/// @return A `DelegateMember` shared pointer bound to the specified non-const member function.
865865
template <class TClass, class RetType, class... Args>
866866
auto MakeDelegate(std::shared_ptr<TClass> object, RetType(TClass::* func)(Args... args)) {
867-
return DelegateMemberShared<TClass, RetType(Args...)>(object, func);
867+
return DelegateMemberSp<TClass, RetType(Args...)>(object, func);
868868
}
869869

870870
/// @brief Creates a delegate that binds to a const member function with a shared pointer to the object.
@@ -876,7 +876,7 @@ auto MakeDelegate(std::shared_ptr<TClass> object, RetType(TClass::* func)(Args..
876876
/// @return A `DelegateMember` shared pointer bound to the specified const member function.
877877
template <class TClass, class RetType, class... Args>
878878
auto MakeDelegate(std::shared_ptr<TClass> object, RetType(TClass::* func)(Args... args) const) {
879-
return DelegateMemberShared<TClass, RetType(Args...)>(object, func);
879+
return DelegateMemberSp<TClass, RetType(Args...)>(object, func);
880880
}
881881

882882
/// @brief Creates a delegate that binds to a `std::function`.

DelegateMQ/delegate/DelegateAsync.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -694,44 +694,40 @@ class DelegateMemberAsync<TClass, RetType(Args...)> : public DelegateMember<TCla
694694
// </common_code>
695695
};
696696

697-
// ----------------------------------------------------------------------------------------------
698-
// NEW CLASS: DelegateMemberAsyncShared
699-
// ----------------------------------------------------------------------------------------------
700-
701697
template <class C, class R>
702-
struct DelegateMemberAsyncShared; // Not defined
698+
struct DelegateMemberAsyncSp; // Not defined
703699

704-
/// @brief `DelegateMemberAsyncShared<>` class asynchronously invokes a class member target function
700+
/// @brief `DelegateMemberAsyncSp<>` class asynchronously invokes a class member target function
705701
/// using a weak pointer (safe from use-after-free).
706702
/// @tparam TClass The class type that contains the member function.
707703
/// @tparam RetType The return type of the bound delegate function.
708704
/// @tparam Args The argument types of the bound delegate function.
709705
template <class TClass, class RetType, class... Args>
710-
class DelegateMemberAsyncShared<TClass, RetType(Args...)> : public DelegateMemberShared<TClass, RetType(Args...)>, public IThreadInvoker {
706+
class DelegateMemberAsyncSp<TClass, RetType(Args...)> : public DelegateMemberSp<TClass, RetType(Args...)>, public IThreadInvoker {
711707
public:
712708
typedef TClass* ObjectPtr;
713709
typedef std::shared_ptr<TClass> SharedPtr;
714710
typedef RetType(TClass::* MemberFunc)(Args...);
715711
typedef RetType(TClass::* ConstMemberFunc)(Args...) const;
716-
using ClassType = DelegateMemberAsyncShared<TClass, RetType(Args...)>;
717-
using BaseType = DelegateMemberShared<TClass, RetType(Args...)>;
712+
using ClassType = DelegateMemberAsyncSp<TClass, RetType(Args...)>;
713+
using BaseType = DelegateMemberSp<TClass, RetType(Args...)>;
718714

719-
DelegateMemberAsyncShared(SharedPtr object, MemberFunc func, IThread& thread) : BaseType(object, func), m_thread(&thread) {
715+
DelegateMemberAsyncSp(SharedPtr object, MemberFunc func, IThread& thread) : BaseType(object, func), m_thread(&thread) {
720716
Bind(object, func, thread);
721717
}
722718

723-
DelegateMemberAsyncShared(SharedPtr object, ConstMemberFunc func, IThread& thread) : BaseType(object, func), m_thread(&thread) {
719+
DelegateMemberAsyncSp(SharedPtr object, ConstMemberFunc func, IThread& thread) : BaseType(object, func), m_thread(&thread) {
724720
Bind(object, func, thread);
725721
}
726722

727-
DelegateMemberAsyncShared(const ClassType& rhs) : BaseType(rhs) { Assign(rhs); }
723+
DelegateMemberAsyncSp(const ClassType& rhs) : BaseType(rhs) { Assign(rhs); }
728724

729-
DelegateMemberAsyncShared(ClassType&& rhs) noexcept :
725+
DelegateMemberAsyncSp(ClassType&& rhs) noexcept :
730726
BaseType(std::move(rhs)), m_thread(rhs.m_thread), m_priority(rhs.m_priority) {
731727
rhs.Clear();
732728
}
733729

734-
DelegateMemberAsyncShared() = default;
730+
DelegateMemberAsyncSp() = default;
735731

736732
void Bind(SharedPtr object, MemberFunc func, IThread& thread) {
737733
m_thread = &thread;
@@ -1253,10 +1249,10 @@ auto MakeDelegate(const TClass* object, RetType(TClass::* func)(Args... args) co
12531249
/// @param[in] object A shared pointer to the instance of `TClass` that will be used for the delegate.
12541250
/// @param[in] func A pointer to the non-const member function of `TClass` to bind to the delegate.
12551251
/// @param[in] thread The `IThread` on which the function will be invoked asynchronously.
1256-
/// @return A `DelegateMemberAsyncShared` (SAFE) bound to the specified non-const member function and thread.
1252+
/// @return A `DelegateMemberAsyncSp` (SAFE) bound to the specified non-const member function and thread.
12571253
template <class TClass, class RetVal, class... Args>
12581254
auto MakeDelegate(std::shared_ptr<TClass> object, RetVal(TClass::* func)(Args... args), IThread& thread) {
1259-
return DelegateMemberAsyncShared<TClass, RetVal(Args...)>(object, func, thread);
1255+
return DelegateMemberAsyncSp<TClass, RetVal(Args...)>(object, func, thread);
12601256
}
12611257

12621258

@@ -1267,10 +1263,10 @@ auto MakeDelegate(std::shared_ptr<TClass> object, RetVal(TClass::* func)(Args...
12671263
/// @param[in] object A shared pointer to the instance of `TClass` that will be used for the delegate.
12681264
/// @param[in] func A pointer to the const member function of `TClass` to bind to the delegate.
12691265
/// @param[in] thread The `IThread` on which the function will be invoked asynchronously.
1270-
/// @return A `DelegateMemberAsyncShared` (SAFE) bound to the specified const member function and thread.
1266+
/// @return A `DelegateMemberAsyncSp` (SAFE) bound to the specified const member function and thread.
12711267
template <class TClass, class RetVal, class... Args>
12721268
auto MakeDelegate(std::shared_ptr<TClass> object, RetVal(TClass::* func)(Args... args) const, IThread& thread) {
1273-
return DelegateMemberAsyncShared<TClass, RetVal(Args...)>(object, func, thread);
1269+
return DelegateMemberAsyncSp<TClass, RetVal(Args...)>(object, func, thread);
12741270
}
12751271

12761272
/// @brief Creates an asynchronous delegate that binds to a `std::function`.

DelegateMQ/delegate/DelegateAsyncWait.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -895,47 +895,47 @@ class DelegateMemberAsyncWait<TClass, RetType(Args...)> : public DelegateMember<
895895
};
896896

897897
template <class C, class R>
898-
struct DelegateMemberAsyncWaitShared; // Not defined
898+
struct DelegateMemberAsyncWaitSp; // Not defined
899899

900-
/// @brief `DelegateMemberAsyncWaitShared<>` class asynchronously block invokes a class member target function
900+
/// @brief `DelegateMemberAsyncWaitSp<>` class asynchronously block invokes a class member target function
901901
/// using a weak/shared pointer semantics.
902902
/// @tparam TClass The class type that contains the member function.
903903
/// @tparam RetType The return type of the bound delegate function.
904904
/// @tparam Args The argument types of the bound delegate function.
905905
template <class TClass, class RetType, class... Args>
906-
class DelegateMemberAsyncWaitShared<TClass, RetType(Args...)> : public DelegateMemberShared<TClass, RetType(Args...)>, public IThreadInvoker {
906+
class DelegateMemberAsyncWaitSp<TClass, RetType(Args...)> : public DelegateMemberSp<TClass, RetType(Args...)>, public IThreadInvoker {
907907
public:
908908
using SharedPtr = std::shared_ptr<TClass>;
909909
using MemberFunc = RetType(TClass::*)(Args...);
910910
using ConstMemberFunc = RetType(TClass::*)(Args...) const;
911-
using ClassType = DelegateMemberAsyncWaitShared<TClass, RetType(Args...)>;
912-
using BaseType = DelegateMemberShared<TClass, RetType(Args...)>;
911+
using ClassType = DelegateMemberAsyncWaitSp<TClass, RetType(Args...)>;
912+
using BaseType = DelegateMemberSp<TClass, RetType(Args...)>;
913913

914914
/// @brief Constructor for non-const member function
915-
DelegateMemberAsyncWaitShared(SharedPtr object, MemberFunc func, IThread& thread, Duration timeout = WAIT_INFINITE) :
915+
DelegateMemberAsyncWaitSp(SharedPtr object, MemberFunc func, IThread& thread, Duration timeout = WAIT_INFINITE) :
916916
BaseType(object, func), m_thread(&thread), m_timeout(timeout) {
917917
Bind(object, func, thread, timeout);
918918
}
919919

920920
/// @brief Constructor for const member function
921-
DelegateMemberAsyncWaitShared(SharedPtr object, ConstMemberFunc func, IThread& thread, Duration timeout = WAIT_INFINITE) :
921+
DelegateMemberAsyncWaitSp(SharedPtr object, ConstMemberFunc func, IThread& thread, Duration timeout = WAIT_INFINITE) :
922922
BaseType(object, func), m_thread(&thread), m_timeout(timeout) {
923923
Bind(object, func, thread, timeout);
924924
}
925925

926926
/// @brief Copy constructor
927-
DelegateMemberAsyncWaitShared(const ClassType& rhs) :
927+
DelegateMemberAsyncWaitSp(const ClassType& rhs) :
928928
BaseType(rhs) {
929929
Assign(rhs);
930930
}
931931

932932
/// @brief Move constructor
933-
DelegateMemberAsyncWaitShared(ClassType&& rhs) noexcept :
933+
DelegateMemberAsyncWaitSp(ClassType&& rhs) noexcept :
934934
BaseType(std::move(rhs)), m_thread(rhs.m_thread), m_priority(rhs.m_priority), m_timeout(rhs.m_timeout), m_success(rhs.m_success), m_retVal(rhs.m_retVal) {
935935
rhs.Clear();
936936
}
937937

938-
DelegateMemberAsyncWaitShared() = default;
938+
DelegateMemberAsyncWaitSp() = default;
939939

940940
/// @brief Bind a non-const member function
941941
void Bind(SharedPtr object, MemberFunc func, IThread& thread, Duration timeout = WAIT_INFINITE) {
@@ -1637,7 +1637,7 @@ auto MakeDelegate(const TClass* object, RetType(TClass::* func)(Args... args) co
16371637
/// @return A `DelegateMemberAsyncWait` shared pointer bound to the specified non-const member function, thread, and timeout.
16381638
template <class TClass, class RetVal, class... Args>
16391639
auto MakeDelegate(std::shared_ptr<TClass> object, RetVal(TClass::* func)(Args... args), IThread& thread, Duration timeout) {
1640-
return DelegateMemberAsyncWaitShared<TClass, RetVal(Args...)>(object, func, thread, timeout);
1640+
return DelegateMemberAsyncWaitSp<TClass, RetVal(Args...)>(object, func, thread, timeout);
16411641
}
16421642

16431643
/// @brief Creates an asynchronous delegate that binds to a const member function using a shared pointer, with a wait and timeout.
@@ -1651,7 +1651,7 @@ auto MakeDelegate(std::shared_ptr<TClass> object, RetVal(TClass::* func)(Args...
16511651
/// @return A `DelegateMemberAsyncWait` shared pointer bound to the specified const member function, thread, and timeout.
16521652
template <class TClass, class RetVal, class... Args>
16531653
auto MakeDelegate(std::shared_ptr<TClass> object, RetVal(TClass::* func)(Args... args) const, IThread& thread, Duration timeout) {
1654-
return DelegateMemberAsyncWaitShared<TClass, RetVal(Args...)>(object, func, thread, timeout);
1654+
return DelegateMemberAsyncWaitSp<TClass, RetVal(Args...)>(object, func, thread, timeout);
16551655
}
16561656

16571657
/// @brief Creates an asynchronous delegate that binds to a `std::function` with a wait and timeout.

DelegateMQ/delegate/DelegateOpt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace dmq
1010
{
11-
// @TODO: Change aliases to switch clocks globally if necessary
11+
// @TODO: Change aliases to switch clock type globally if necessary
1212
using Clock = std::chrono::steady_clock;
1313
using Duration = std::chrono::duration<int64_t, std::milli>;
1414
using TimePoint = std::chrono::time_point<Clock, Duration>;

DelegateMQ/predef/os/stdlib/Thread.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,17 @@ void Thread::ExitThread()
124124
if (!m_thread)
125125
return;
126126

127-
if (m_watchdogTimer)
127+
if (m_watchdogTimer)
128+
{
128129
m_watchdogTimer->Stop();
129-
if (m_threadTimer)
130+
m_watchdogTimer->Expired.Clear();
131+
}
132+
133+
if (m_threadTimer)
134+
{
130135
m_threadTimer->Stop();
136+
m_threadTimer->Expired.Clear();
137+
}
131138

132139
// Create a new ThreadMsg
133140
std::shared_ptr<ThreadMsg> threadMsg(new ThreadMsg(MSG_EXIT_THREAD, 0));

DelegateMQ/predef/util/Timer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/// @brief A timer class provides periodic timer callbacks on the client's
99
/// thread of control. Timer is thread safe.
10+
/// See example SafeTimer.cpp to prevent a latent callback on a dead object.
1011
class Timer
1112
{
1213
public:

0 commit comments

Comments
 (0)