From 70960b025136dbb17ae7861737e56c5cc27bfe0a Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 29 Jun 2018 22:09:36 -0700 Subject: [PATCH] Signal: rename Signal to Signal_mt and Signal_st to Signal. The single-threaded version is fine for most of the use cases we're planning on, and is half the size on most platforms. --- wpiutil/src/main/native/include/wpi/Signal.h | 7 +++---- wpiutil/src/test/native/cpp/sigslot/signal-threaded.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/wpiutil/src/main/native/include/wpi/Signal.h b/wpiutil/src/main/native/include/wpi/Signal.h index e518b71e9a..afc5eefacd 100644 --- a/wpiutil/src/main/native/include/wpi/Signal.h +++ b/wpiutil/src/main/native/include/wpi/Signal.h @@ -806,11 +806,10 @@ private: /** * Specialization of SignalBase to be used in single threaded contexts. * Slot connection, disconnection and signal emission are not thread-safe. - * The performance improvement over the thread-safe variant is not impressive, - * so this is not very useful. + * This is significantly smaller than the thread-safe variant. */ template -using Signal_st = SignalBase; +using Signal = SignalBase; /** * Specialization of SignalBase to be used in multi-threaded contexts. @@ -822,7 +821,7 @@ using Signal_st = SignalBase; * instead for that use case. */ template -using Signal = SignalBase; +using Signal_mt = SignalBase; /** * Specialization of SignalBase to be used in multi-threaded contexts, allowing diff --git a/wpiutil/src/test/native/cpp/sigslot/signal-threaded.cpp b/wpiutil/src/test/native/cpp/sigslot/signal-threaded.cpp index f3b05ef2f9..c4f7cdb04b 100644 --- a/wpiutil/src/test/native/cpp/sigslot/signal-threaded.cpp +++ b/wpiutil/src/test/native/cpp/sigslot/signal-threaded.cpp @@ -50,11 +50,11 @@ std::atomic sum{0}; void f(int i) { sum += i; } -void emit_many(Signal& sig) { +void emit_many(Signal_mt& sig) { for (int i = 0; i < 10000; ++i) sig(1); } -void connect_emit(Signal& sig) { +void connect_emit(Signal_mt& sig) { for (int i = 0; i < 100; ++i) { auto s = sig.connect_scoped(f); for (int j = 0; j < 100; ++j) sig(1); @@ -68,7 +68,7 @@ namespace wpi { TEST(Signal, ThreadedMix) { sum = 0; - Signal sig; + Signal_mt sig; std::array threads; for (auto& t : threads) t = std::thread(connect_emit, std::ref(sig)); @@ -79,7 +79,7 @@ TEST(Signal, ThreadedMix) { TEST(Signal, ThreadedEmission) { sum = 0; - Signal sig; + Signal_mt sig; sig.connect(f); std::array threads;