Replaced ThreadLocal use with thread_local. Review: https://reviews.apache.org/r/36705
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f24db46b Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f24db46b Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f24db46b Branch: refs/heads/master Commit: f24db46b92796efaa15766c625b8ef4706240f2f Parents: 4225780 Author: Joris Van Remoortere <[email protected]> Authored: Fri Jul 24 14:39:43 2015 -0700 Committer: Benjamin Hindman <[email protected]> Committed: Fri Jul 24 15:29:04 2015 -0700 ---------------------------------------------------------------------- 3rdparty/libprocess/3rdparty/Makefile.am | 1 - 3rdparty/libprocess/include/process/executor.hpp | 12 ++++-------- 3rdparty/libprocess/include/process/process.hpp | 9 ++------- 3rdparty/libprocess/src/libev.cpp | 2 +- 3rdparty/libprocess/src/libev.hpp | 13 +++++-------- 3rdparty/libprocess/src/libevent.cpp | 2 +- 3rdparty/libprocess/src/libevent.hpp | 13 +++++-------- 3rdparty/libprocess/src/process.cpp | 5 ++--- 8 files changed, 20 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/f24db46b/3rdparty/libprocess/3rdparty/Makefile.am ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/Makefile.am b/3rdparty/libprocess/3rdparty/Makefile.am index bd95fe1..790bb46 100644 --- a/3rdparty/libprocess/3rdparty/Makefile.am +++ b/3rdparty/libprocess/3rdparty/Makefile.am @@ -190,7 +190,6 @@ stout_tests_SOURCES = \ $(STOUT)/tests/some_tests.cpp \ $(STOUT)/tests/strings_tests.cpp \ $(STOUT)/tests/subcommand_tests.cpp \ - $(STOUT)/tests/thread_tests.cpp \ $(STOUT)/tests/uuid_tests.cpp \ $(STOUT)/tests/version_tests.cpp http://git-wip-us.apache.org/repos/asf/mesos/blob/f24db46b/3rdparty/libprocess/include/process/executor.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/executor.hpp b/3rdparty/libprocess/include/process/executor.hpp index 434d23a..3167f0b 100644 --- a/3rdparty/libprocess/include/process/executor.hpp +++ b/3rdparty/libprocess/include/process/executor.hpp @@ -20,8 +20,6 @@ #include <process/id.hpp> #include <process/process.hpp> -#include <stout/thread.hpp> - namespace process { // Provides an abstraction that can take a standard function object @@ -68,14 +66,12 @@ private: }; -// Per thread executor pointer. The extra level of indirection from -// _executor_ to __executor__ is used in order to take advantage of -// the ThreadLocal operators without needing the extra dereference as -// well as lazily construct the actual executor. -extern ThreadLocal<Executor>* _executor_; +// Per thread executor pointer. We use a pointer to lazily construct the +// actual executor. +extern thread_local Executor* _executor_; #define __executor__ \ - (*_executor_ == NULL ? *_executor_ = new Executor() : *_executor_) + (_executor_ == NULL ? _executor_ = new Executor() : _executor_) } // namespace process { http://git-wip-us.apache.org/repos/asf/mesos/blob/f24db46b/3rdparty/libprocess/include/process/process.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/process.hpp b/3rdparty/libprocess/include/process/process.hpp index 8620547..8908bd2 100644 --- a/3rdparty/libprocess/include/process/process.hpp +++ b/3rdparty/libprocess/include/process/process.hpp @@ -36,7 +36,6 @@ #include <stout/lambda.hpp> #include <stout/option.hpp> #include <stout/synchronized.hpp> -#include <stout/thread.hpp> namespace process { @@ -505,12 +504,8 @@ inline bool wait(const ProcessBase* process, const Duration& duration) } -// Per thread process pointer. The extra level of indirection from -// _process_ to __process__ is used in order to take advantage of the -// ThreadLocal operators without needing the extra dereference. -extern ThreadLocal<ProcessBase>* _process_; - -#define __process__ (*_process_) +// Per thread process pointer. +extern thread_local ProcessBase* __process__; // NOTE: Methods in this namespace should only be used in tests to // inject arbitrary events. http://git-wip-us.apache.org/repos/asf/mesos/blob/f24db46b/3rdparty/libprocess/src/libev.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/libev.cpp b/3rdparty/libprocess/src/libev.cpp index 8960c75..4fa484b 100644 --- a/3rdparty/libprocess/src/libev.cpp +++ b/3rdparty/libprocess/src/libev.cpp @@ -39,7 +39,7 @@ std::mutex* watchers_mutex = new std::mutex(); std::queue<lambda::function<void(void)>>* functions = new std::queue<lambda::function<void(void)>>(); -ThreadLocal<bool>* _in_event_loop_ = new ThreadLocal<bool>(); +thread_local bool* _in_event_loop_ = NULL; void handle_async(struct ev_loop* loop, ev_async* _, int revents) http://git-wip-us.apache.org/repos/asf/mesos/blob/f24db46b/3rdparty/libprocess/src/libev.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/libev.hpp b/3rdparty/libprocess/src/libev.hpp index fd26728..fd8970b 100644 --- a/3rdparty/libprocess/src/libev.hpp +++ b/3rdparty/libprocess/src/libev.hpp @@ -25,7 +25,6 @@ #include <stout/lambda.hpp> #include <stout/synchronized.hpp> -#include <stout/thread.hpp> namespace process { @@ -47,14 +46,12 @@ extern std::mutex* watchers_mutex; // loop (protected by 'watchers' above). extern std::queue<lambda::function<void(void)>>* functions; -// Per thread bool pointer. The extra level of indirection from -// _in_event_loop_ to __in_event_loop__ is used in order to take -// advantage of the ThreadLocal operators without needing the extra -// dereference as well as lazily construct the actual bool. -extern ThreadLocal<bool>* _in_event_loop_; +// Per thread bool pointer. We use a pointer to lazily construct the +// actual bool. +extern thread_local bool* _in_event_loop_; -#define __in_event_loop__ *(*_in_event_loop_ == NULL ? \ - *_in_event_loop_ = new bool(false) : *_in_event_loop_) +#define __in_event_loop__ *(_in_event_loop_ == NULL ? \ + _in_event_loop_ = new bool(false) : _in_event_loop_) // Wrapper around function we want to run in the event loop. http://git-wip-us.apache.org/repos/asf/mesos/blob/f24db46b/3rdparty/libprocess/src/libevent.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/libevent.cpp b/3rdparty/libprocess/src/libevent.cpp index 02f9e61..1e44f2a 100644 --- a/3rdparty/libprocess/src/libevent.cpp +++ b/3rdparty/libprocess/src/libevent.cpp @@ -38,7 +38,7 @@ std::queue<lambda::function<void(void)>>* functions = new std::queue<lambda::function<void(void)>>(); -ThreadLocal<bool>* _in_event_loop_ = new ThreadLocal<bool>(); +thread_local bool* _in_event_loop_ = NULL; void async_function(int socket, short which, void* arg) http://git-wip-us.apache.org/repos/asf/mesos/blob/f24db46b/3rdparty/libprocess/src/libevent.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/libevent.hpp b/3rdparty/libprocess/src/libevent.hpp index 3a0a46b..07acb14 100644 --- a/3rdparty/libprocess/src/libevent.hpp +++ b/3rdparty/libprocess/src/libevent.hpp @@ -18,7 +18,6 @@ #include <event2/event.h> #include <stout/lambda.hpp> -#include <stout/thread.hpp> namespace process { @@ -26,15 +25,13 @@ namespace process { extern event_base* base; -// Per thread bool pointer. The extra level of indirection from -// _in_event_loop_ to __in_event_loop__ is used in order to take -// advantage of the ThreadLocal operators without needing the extra -// dereference as well as lazily construct the actual bool. -extern ThreadLocal<bool>* _in_event_loop_; +// Per thread bool pointer. We use a pointer to lazily construct the +// actual bool. +extern thread_local bool* _in_event_loop_; -#define __in_event_loop__ *(*_in_event_loop_ == NULL ? \ - *_in_event_loop_ = new bool(false) : *_in_event_loop_) +#define __in_event_loop__ *(_in_event_loop_ == NULL ? \ + _in_event_loop_ = new bool(false) : _in_event_loop_) enum EventLoopLogicFlow { http://git-wip-us.apache.org/repos/asf/mesos/blob/f24db46b/3rdparty/libprocess/src/process.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp index d6b0d55..7a5a60d 100644 --- a/3rdparty/libprocess/src/process.cpp +++ b/3rdparty/libprocess/src/process.cpp @@ -91,7 +91,6 @@ #include <stout/path.hpp> #include <stout/strings.hpp> #include <stout/synchronized.hpp> -#include <stout/thread.hpp> #include <stout/unreachable.hpp> #include "config.hpp" @@ -467,10 +466,10 @@ PID<GarbageCollector> gc; PID<Help> help; // Per thread process pointer. -ThreadLocal<ProcessBase>* _process_ = new ThreadLocal<ProcessBase>(); +thread_local ProcessBase* __process__ = NULL; // Per thread executor pointer. -ThreadLocal<Executor>* _executor_ = new ThreadLocal<Executor>(); +thread_local Executor* _executor_ = NULL; // TODO(dhamon): Reintroduce this when it is plumbed through to Statistics. // const Duration LIBPROCESS_STATISTICS_WINDOW = Days(1);
