Defined TMB Message Poll Interval as a gflag.
diff --git a/third_party/src/tmb/CMakeLists.txt b/third_party/src/tmb/CMakeLists.txt
index 14e467b..a280a93 100644
--- a/third_party/src/tmb/CMakeLists.txt
+++ b/third_party/src/tmb/CMakeLists.txt
@@ -379,6 +379,26 @@
include_directories(${ZOOKEEPER_INCLUDE_DIRS})
endif()
+set_gflags_lib_name ()
+
+# NOTE(chasseur): We only add gflags and gtest to the build if those targets
+# don't already exist, so that TMB can be brought in to a build that already
+# uses one or both of those libraries with add_subdirectory() and not cause
+# name collisions.
+
+# Build GFlags command-line processing library if needed.
+if ((NOT TARGET ${GFLAGS_LIB_NAME}) AND (BUILD_BENCHMARKS OR ENABLE_NATIVENET))
+ add_subdirectory(third_party/gflags)
+ include_directories(${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include)
+endif()
+
+# Googletest Framework For Unit Testing
+if (NOT TARGET gtest)
+ add_subdirectory(third_party/gtest)
+ include_directories(third_party/gtest/include)
+ enable_testing()
+endif()
+
# Include path for TMB.
include_directories(${PROJECT_SOURCE_DIR}/include)
set(TMB_INCLUDE_DIRS ${TMB_INCLUDE_DIRS} CACHE STRING
@@ -391,7 +411,8 @@
add_library(tmb
${TMB_SRCS})
target_link_libraries(tmb
- ${CMAKE_THREAD_LIBS_INIT})
+ ${CMAKE_THREAD_LIBS_INIT}
+ ${GFLAGS_LIB_NAME})
if (ENABLE_LEVELDB)
target_link_libraries(tmb
@@ -418,24 +439,6 @@
${ZOOKEEPER_LIBRARIES})
endif()
-# NOTE(chasseur): We only add gflags and gtest to the build if those targets
-# don't already exist, so that TMB can be brought in to a build that already
-# uses one or both of those libraries with add_subdirectory() and not cause
-# name collisions.
-
-# Build GFlags command-line processing library if needed.
-if ((NOT TARGET gflags_nothreads-static) AND (BUILD_BENCHMARKS OR ENABLE_NATIVENET))
- add_subdirectory(third_party/gflags)
- include_directories(${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include)
-endif()
-
-# Googletest Framework For Unit Testing
-if (NOT TARGET gtest)
- add_subdirectory(third_party/gtest)
- include_directories(third_party/gtest/include)
- enable_testing()
-endif()
-
# Build the tmb_net_server executable if enabled.
if (ENABLE_NATIVENET)
add_executable(tmb_net_server src/tmb_net_server.cc)
diff --git a/third_party/src/tmb/include/tmb/message_bus.h b/third_party/src/tmb/include/tmb/message_bus.h
index a4ca525..74e298d 100644
--- a/third_party/src/tmb/include/tmb/message_bus.h
+++ b/third_party/src/tmb/include/tmb/message_bus.h
@@ -496,11 +496,6 @@
internal::IteratorAdapter<const AnnotatedMessage> *adapter) = 0;
private:
- // The number of milliseconds to sleep between calls to
- // ReceiveIfAvailableImpl() in the default active-polling implementation of
- // ReceiveImpl().
- static const unsigned int kReceivePollIntervalMS = 100;
-
// Disallow copy and assign:
MessageBus(const MessageBus &orig) = delete;
MessageBus& operator=(const MessageBus &rhs) = delete;
diff --git a/third_party/src/tmb/src/message_bus.cc b/third_party/src/tmb/src/message_bus.cc
index 44324ec..7fd0efb 100644
--- a/third_party/src/tmb/src/message_bus.cc
+++ b/third_party/src/tmb/src/message_bus.cc
@@ -24,9 +24,25 @@
#include <cstdlib>
#include <thread> // NOLINT(build/c++11)
+#include "gflags/gflags.h"
+
namespace tmb {
-const unsigned int MessageBus::kReceivePollIntervalMS;
+static bool ValidateTmbReceivePollInterval(const char *flagname,
+ std::int32_t value) {
+ if (value > 0) {
+ return true;
+ } else {
+ std::fprintf(stderr, "--%s must be at least 1\n", flagname);
+ return false;
+ }
+}
+DEFINE_int32(tmb_receive_poll_interval, 50,
+ "The number of milliseconds to sleep between calls to ReceiveIfAvailableImpl() "
+ "in the default active-polling implementation of ReceiveImpl().");
+static const bool tmb_receive_poll_interval_dummy = gflags::RegisterFlagValidator(
+ &FLAGS_tmb_receive_poll_interval,
+ &ValidateTmbReceivePollInterval);
internal::NetMessageRemovalInterface*
MessageBus::GetNetMessageRemovalInterface() {
@@ -49,7 +65,7 @@
pusher);
while (received == 0) {
std::this_thread::sleep_for(
- std::chrono::milliseconds(kReceivePollIntervalMS));
+ std::chrono::milliseconds(FLAGS_tmb_receive_poll_interval));
received = ReceiveIfAvailableImpl(receiver_id,
minimum_priority,
max_messages,