Repository: mesos Updated Branches: refs/heads/master 1b9ce37f3 -> b80ef400d
Stout: Introduced THREAD_LOCAL wrapper for thread local storage. This replaced the `ThreadLocal` primitive with the new C++11 standard. The exception is on OSX where we use `__thread` as `thread_local` is not supported. Review: https://reviews.apache.org/r/36845 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9c86375c Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9c86375c Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9c86375c Branch: refs/heads/master Commit: 9c86375cd9297cc02ed17d5043597d4b240bfbba Parents: 1b9ce37 Author: Joris Van Remoortere <[email protected]> Authored: Thu Jul 30 15:27:37 2015 -0700 Committer: Benjamin Hindman <[email protected]> Committed: Thu Jul 30 15:27:37 2015 -0700 ---------------------------------------------------------------------- 3rdparty/libprocess/3rdparty/stout/Makefile.am | 1 - .../3rdparty/stout/include/Makefile.am | 2 +- .../3rdparty/stout/include/stout/thread.hpp | 80 -------------------- .../stout/include/stout/thread_local.hpp | 30 ++++++++ .../3rdparty/stout/tests/thread_tests.cpp | 40 ---------- 5 files changed, 31 insertions(+), 122 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/9c86375c/3rdparty/libprocess/3rdparty/stout/Makefile.am ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/Makefile.am b/3rdparty/libprocess/3rdparty/stout/Makefile.am index 89e7b18..f95ed03 100644 --- a/3rdparty/libprocess/3rdparty/stout/Makefile.am +++ b/3rdparty/libprocess/3rdparty/stout/Makefile.am @@ -56,6 +56,5 @@ EXTRA_DIST = \ tests/strings_tests.cpp \ tests/subcommand_tests.cpp \ tests/svn_tests.cpp \ - tests/thread_tests.cpp \ tests/uuid_tests.cpp \ tests/version_tests.cpp http://git-wip-us.apache.org/repos/asf/mesos/blob/9c86375c/3rdparty/libprocess/3rdparty/stout/include/Makefile.am ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am index 5c19e3e..b299ce8 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am +++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am @@ -84,7 +84,7 @@ nobase_include_HEADERS = \ stout/svn.hpp \ stout/synchronized.hpp \ stout/tests/utils.hpp \ - stout/thread.hpp \ + stout/thread_local.hpp \ stout/try.hpp \ stout/unreachable.hpp \ stout/utils.hpp \ http://git-wip-us.apache.org/repos/asf/mesos/blob/9c86375c/3rdparty/libprocess/3rdparty/stout/include/stout/thread.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/thread.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/thread.hpp deleted file mode 100644 index 552d6e9..0000000 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/thread.hpp +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __STOUT_THREAD_HPP__ -#define __STOUT_THREAD_HPP__ - -#include <errno.h> -#include <pthread.h> -#include <stdio.h> // For perror. - -#include <string> - -#include <stout/abort.hpp> - -template <typename T> -struct ThreadLocal -{ - ThreadLocal() - { - errno = pthread_key_create(&key, NULL); - - if (errno != 0) { - ABORT(std::string("Failed to create thread local, pthread_key_create: ") + - strerror(errno)); - } - } - - ~ThreadLocal() - { - errno = pthread_key_delete(key); - - if (errno != 0) { - ABORT("Failed to destruct thread local, pthread_key_delete: " + - std::string(strerror(errno))); - } - } - - ThreadLocal<T>& operator = (T* t) - { - errno = pthread_setspecific(key, t); - - if (errno != 0) { - ABORT(std::string("Failed to set thread local, pthread_setspecific: ") + - strerror(errno)); - } - return *this; - } - - operator T* () const - { - return reinterpret_cast<T*>(pthread_getspecific(key)); - } - - T* operator -> () const - { - return reinterpret_cast<T*>(pthread_getspecific(key)); - } - -private: - // Not expecting any other operators to be used (and the rest?). - bool operator * (const ThreadLocal<T>&) const; - bool operator == (const ThreadLocal<T>&) const; - bool operator != (const ThreadLocal<T>&) const; - bool operator < (const ThreadLocal<T>&) const; - bool operator > (const ThreadLocal<T>&) const; - - pthread_key_t key; -}; - -#endif // __STOUT_THREAD_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/9c86375c/3rdparty/libprocess/3rdparty/stout/include/stout/thread_local.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/thread_local.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/thread_local.hpp new file mode 100644 index 0000000..454abdf --- /dev/null +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/thread_local.hpp @@ -0,0 +1,30 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __STOUT_THREAD_LOCAL_HPP__ +#define __STOUT_THREAD_LOCAL_HPP__ + +// A wrapper around the thread local storage attribute. The default +// clang on OSX does not support the c++11 standard `thread_local` +// intentionally until a higher performance implementation is +// released. See https://devforums.apple.com/message/1079348#1079348 +// Until then, we use `__thread` on OSX instead. +// We required that THREAD_LOCAL is only used with POD types as this +// is a requirement of `__thread`. +#ifdef __APPLE__ +#define THREAD_LOCAL __thread +#else +#define THREAD_LOCAL thread_local +#endif + +#endif // __STOUT_THREAD_LOCAL_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/9c86375c/3rdparty/libprocess/3rdparty/stout/tests/thread_tests.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/tests/thread_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/thread_tests.cpp deleted file mode 100644 index 319fcdf..0000000 --- a/3rdparty/libprocess/3rdparty/stout/tests/thread_tests.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/** -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License -*/ - -#include <string> - -#include <gtest/gtest.h> - -#include <stout/thread.hpp> - -TEST(ThreadTest, Local) -{ - ThreadLocal<std::string>* _s_ = new ThreadLocal<std::string>(); - - std::string* s = new std::string(); - - ASSERT_TRUE(*(_s_) == NULL); - - (*_s_) = s; - - ASSERT_TRUE(*(_s_) == s); - ASSERT_FALSE(*(_s_) == NULL); - - (*_s_) = NULL; - - ASSERT_TRUE(*(_s_) == NULL); - - delete s; - delete _s_; -}
