You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2015/07/30 01:59:57 UTC
[1/5] mesos git commit: Used std::thread instead of pthread for
cgroups tests.
Repository: mesos
Updated Branches:
refs/heads/master 8727301d3 -> 2b952a76b
Used std::thread instead of pthread for cgroups tests.
Review: https://reviews.apache.org/r/36823
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/cbc102ed
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/cbc102ed
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/cbc102ed
Branch: refs/heads/master
Commit: cbc102ed6379d71f0386eba1b82dd75bbaa146da
Parents: 8727301
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Wed Jul 29 15:54:47 2015 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Wed Jul 29 16:19:24 2015 -0700
----------------------------------------------------------------------
src/tests/containerizer/cgroups_tests.cpp | 37 +++++++++++++-------------
1 file changed, 18 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/cbc102ed/src/tests/containerizer/cgroups_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/cgroups_tests.cpp b/src/tests/containerizer/cgroups_tests.cpp
index caecd5d..ea54ab8 100644
--- a/src/tests/containerizer/cgroups_tests.cpp
+++ b/src/tests/containerizer/cgroups_tests.cpp
@@ -26,6 +26,7 @@
#include <set>
#include <string>
+#include <thread>
#include <vector>
#include <sys/mman.h>
@@ -36,6 +37,7 @@
#include <gmock/gmock.h>
#include <process/gtest.hpp>
+#include <process/latch.hpp>
#include <process/owned.hpp>
#include <stout/gtest.hpp>
@@ -798,26 +800,20 @@ TEST_F(CgroupsAnyHierarchyWithFreezerTest, ROOT_CGROUPS_Destroy)
}
-void* threadFunction(void*)
-{
- // Newly created threads have PTHREAD_CANCEL_ENABLE and
- // PTHREAD_CANCEL_DEFERRED so they can be cancelled from the main thread.
- while (true) { sleep(1); }
-
- return NULL;
-}
-
-
TEST_F(CgroupsAnyHierarchyWithFreezerTest, ROOT_CGROUPS_AssignThreads)
{
- size_t numThreads = 5;
+ const size_t numThreads = 5;
- pthread_t pthreads[numThreads];
+ std::thread* runningThreads[numThreads];
+
+ Latch* latch = new Latch();
// Create additional threads.
- for (size_t i = 0; i < numThreads; i++)
- {
- EXPECT_EQ(0, pthread_create(&pthreads[i], NULL, threadFunction, NULL));
+ for (size_t i = 0; i < numThreads; i++) {
+ runningThreads[i] = new std::thread([=]() {
+ // Wait until the main thread tells us to exit.
+ latch->await();
+ });
}
std::string hierarchy = path::join(baseHierarchy, "freezer");
@@ -843,12 +839,15 @@ TEST_F(CgroupsAnyHierarchyWithFreezerTest, ROOT_CGROUPS_AssignThreads)
EXPECT_SOME_EQ(threads.get(), cgroupThreads);
// Terminate the additional threads.
- for (size_t i = 0; i < numThreads; i++)
- {
- EXPECT_EQ(0, pthread_cancel(pthreads[i]));
- EXPECT_EQ(0, pthread_join(pthreads[i], NULL));
+ latch->trigger();
+
+ for (size_t i = 0; i < numThreads; i++) {
+ runningThreads[i]->join();
+ delete runningThreads[i];
}
+ delete latch;
+
// Move ourselves to the root cgroup.
CHECK_SOME(cgroups::assign(hierarchy, "", ::getpid()));
[5/5] mesos git commit: Removed and guarded pthread specifics for
libevent-openssl.
Posted by be...@apache.org.
Removed and guarded pthread specifics for libevent-openssl.
Review: https://reviews.apache.org/r/36827
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2b952a76
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2b952a76
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2b952a76
Branch: refs/heads/master
Commit: 2b952a76b1bdae58d416768a2608d800cc049937
Parents: 4d4ba02
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Wed Jul 29 16:57:27 2015 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Wed Jul 29 16:59:53 2015 -0700
----------------------------------------------------------------------
3rdparty/libprocess/src/libevent.cpp | 10 ++++++++++
3rdparty/libprocess/src/openssl.cpp | 16 +++++++++-------
2 files changed, 19 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/2b952a76/3rdparty/libprocess/src/libevent.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/libevent.cpp b/3rdparty/libprocess/src/libevent.cpp
index 1f175a4..c604caa 100644
--- a/3rdparty/libprocess/src/libevent.cpp
+++ b/3rdparty/libprocess/src/libevent.cpp
@@ -183,9 +183,19 @@ double EventLoop::time()
void EventLoop::initialize()
{
+ // We need to initialize Libevent differently depending on the
+ // operating system threading support.
+#if defined(EVTHREAD_USE_PTHREADS_IMPLEMENTED)
if (evthread_use_pthreads() < 0) {
LOG(FATAL) << "Failed to initialize, evthread_use_pthreads";
}
+#elif defined(EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED)
+ if (evthread_use_windows_threads() < 0) {
+ LOG(FATAL) << "Failed to initialize, evthread_use_windows_threads";
+ }
+#else
+#error "Libevent must be compiled with either pthread or Windows thread support"
+#endif
// This enables debugging of libevent calls. We can remove this
// when the implementation settles and after we gain confidence.
http://git-wip-us.apache.org/repos/asf/mesos/blob/2b952a76/3rdparty/libprocess/src/openssl.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/openssl.cpp b/3rdparty/libprocess/src/openssl.cpp
index 1f68460..9ae5c1f 100644
--- a/3rdparty/libprocess/src/openssl.cpp
+++ b/3rdparty/libprocess/src/openssl.cpp
@@ -23,6 +23,7 @@
#include <mutex>
#include <string>
+#include <thread>
#include <process/once.hpp>
@@ -167,13 +168,14 @@ void locking_function(int mode, int n, const char* /*file*/, int /*line*/)
// OpenSSL threading.
unsigned long id_function()
{
- pthread_t pthread = pthread_self();
-#ifdef __APPLE__
- mach_port_t id = pthread_mach_thread_np(pthread);
-#else
- pthread_t id = pthread;
-#endif // __APPLE__
- return static_cast<unsigned long>(id);
+ static_assert(sizeof(std::thread::id) == sizeof(unsigned long),
+ "sizeof(std::thread::id) must be equal to sizeof(unsigned long)"
+ " for std::thread::id to be used as a function for determining "
+ "a thread id");
+
+ // We use the std::thread id and convert it to an unsigned long.
+ const std::thread::id id = std::this_thread::get_id();
+ return *reinterpret_cast<const unsigned long*>(&id);
}
[4/5] mesos git commit: Removed common/factory as it is not used.
Posted by be...@apache.org.
Removed common/factory as it is not used.
Review: https://reviews.apache.org/r/36826
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4d4ba026
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4d4ba026
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4d4ba026
Branch: refs/heads/master
Commit: 4d4ba026955430e6ca5ef2efb02aa172b4dddd54
Parents: 59b877f
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Wed Jul 29 16:25:11 2015 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Wed Jul 29 16:25:11 2015 -0700
----------------------------------------------------------------------
src/Makefile.am | 1 -
src/common/factory.hpp | 121 --------------------------------------------
2 files changed, 122 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/4d4ba026/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 917319a..54eaf20 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -583,7 +583,6 @@ libmesos_no_3rdparty_la_SOURCES += \
common/attributes.hpp \
common/build.hpp \
common/date_utils.hpp \
- common/factory.hpp \
common/http.hpp \
common/parse.hpp \
common/protobuf_utils.hpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/4d4ba026/src/common/factory.hpp
----------------------------------------------------------------------
diff --git a/src/common/factory.hpp b/src/common/factory.hpp
deleted file mode 100644
index bdddcf8..0000000
--- a/src/common/factory.hpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 __FACTORY_HPP__
-#define __FACTORY_HPP__
-
-#include <map>
-#include <string>
-
-#include <pthread.h>
-
-#include <stout/fatal.hpp>
-
-// These two macros create a Factory class that constructs instances of
-// subclasses of a type T, whose constructors take a parameter of type P,
-// based on a registered name for each subclass. To use them:
-//
-// 1) In a header file, call DECLARE_FACTORY(T, P).
-//
-// 2) In a source file, call DEFINE_FACTORY(T, P) { block }, where the block
-// calls registerClass<C>("name") for each subclass C of T to register.
-//
-// 3) You can now call TFactory::instantiate("name", p) to create an instance
-// of the class registered with a given name (or NULL if none exists).
-//
-// Note: Having to register all the classes in one file isn't ideal, but it
-// seems to be the most foolproof solution. If we also want to allow classes
-// to be loaded through shared libraries, it would be possible to add an init
-// function to the library that registers them and make the registerClass()
-// Another method people use to register classes is to have a static object
-// whose constructor adds the class to the factory, but this method doesn't
-// work without special care when the class is in a static library since the
-// unreferenced static object won't be included by the compiler.
-
-
-#define DECLARE_FACTORY(T, P) \
- class T##Factory : public ::mesos::internal::factory::Factory<T, P> { \
- T##Factory(); \
- static T##Factory *instance; \
- static void initialize(); \
- public: \
- static T* instantiate(const std::string& name, P p); \
- };
-
-
-#define DEFINE_FACTORY(T, P) \
- T##Factory *T##Factory::instance = 0; \
- namespace { \
- static pthread_once_t T##Factory_initialized = PTHREAD_ONCE_INIT; \
- } \
- void T##Factory::initialize() { \
- T##Factory::instance = new T##Factory(); \
- } \
- T * T##Factory::instantiate(const std::string& name, P p) { \
- pthread_once(&T##Factory_initialized, T##Factory::initialize); \
- return instance->instantiate2(name, p); \
- } \
- T##Factory::T##Factory() /* user code block follows */
-
-
-
-// Helper classes for the factory macros.
-
-namespace mesos { namespace internal { namespace factory {
-
-template<typename T, typename P> class Creator {
-public:
- virtual T * instantiate(P p) = 0;
-
- virtual ~Creator() {}
-};
-
-
-template<typename C, typename T, typename P>
-class ConcreteCreator : public Creator<T, P> {
-public:
- virtual T* instantiate(P p) { return new C(); }
-};
-
-
-template<typename T, typename P> class Factory {
- std::map<std::string, Creator<T, P> *> creators;
-
-protected:
- template<typename C> void registerClass(const std::string& name) {
- if (creators.find(name) != creators.end())
- fatal("Two classes registered with name \"%s\"", name.c_str());
- creators[name] = new ConcreteCreator<C, T, P>();
- }
-
- // Note: This instantiate needs to have a different name than the
- // static one in order to prevent infinite recursion in that one.
- T * instantiate2(const std::string& name, P p) {
- if (creators.find(name) == creators.end())
- return NULL;
- else
- return creators[name]->instantiate(p);
- }
-};
-
-} // namespace factory {
-} // namespace internal {
-} // namespace mesos {
-
-
-#endif
[3/5] mesos git commit: Removed common/thread as it is not used.
Posted by be...@apache.org.
Removed common/thread as it is not used.
Review: https://reviews.apache.org/r/36825
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/59b877f4
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/59b877f4
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/59b877f4
Branch: refs/heads/master
Commit: 59b877f490ca86dd582601f848cb2b46ca204315
Parents: 16de8bd
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Wed Jul 29 16:25:01 2015 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Wed Jul 29 16:25:01 2015 -0700
----------------------------------------------------------------------
src/Makefile.am | 2 --
src/common/thread.cpp | 52 ----------------------------------------------
src/common/thread.hpp | 39 ----------------------------------
3 files changed, 93 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/59b877f4/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 0794969..917319a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -358,7 +358,6 @@ libmesos_no_3rdparty_la_SOURCES = \
common/protobuf_utils.cpp \
common/resources.cpp \
common/resources_utils.cpp \
- common/thread.cpp \
common/type_utils.cpp \
common/values.cpp \
docker/docker.hpp \
@@ -590,7 +589,6 @@ libmesos_no_3rdparty_la_SOURCES += \
common/protobuf_utils.hpp \
common/resources_utils.hpp \
common/status_utils.hpp \
- common/thread.hpp \
credentials/credentials.hpp \
examples/test_anonymous_module.hpp \
examples/test_module.hpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/59b877f4/src/common/thread.cpp
----------------------------------------------------------------------
diff --git a/src/common/thread.cpp b/src/common/thread.cpp
deleted file mode 100644
index 751e9e8..0000000
--- a/src/common/thread.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 <stout/lambda.hpp>
-
-#include "common/thread.hpp"
-
-namespace thread {
-
-static void* __run(void* arg)
-{
- lambda::function<void(void)>* function =
- reinterpret_cast<lambda::function<void(void)>*>(arg);
- (*function)();
- delete function;
- return 0;
-}
-
-
-bool start(const lambda::function<void(void)>& f, bool detach /*= false*/)
-{
- lambda::function<void(void)>* __f = new lambda::function<void(void)>(f);
-
- pthread_t t;
- if (pthread_create(&t, NULL, __run, __f) != 0) {
- return false;
- }
-
- if (detach && pthread_detach(t) != 0) {
- return false;
- }
-
- return true;
-}
-
-
-} // namespace thread {
http://git-wip-us.apache.org/repos/asf/mesos/blob/59b877f4/src/common/thread.hpp
----------------------------------------------------------------------
diff --git a/src/common/thread.hpp b/src/common/thread.hpp
deleted file mode 100644
index 9685898..0000000
--- a/src/common/thread.hpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 __THREAD_HPP__
-#define __THREAD_HPP__
-
-#include <pthread.h>
-
-#include <stout/lambda.hpp>
-
-// Provides a simple threading facility for starting a thread to run
-// an arbitrary function. No mechanism for returning a value from the
-// function is currently provided (and in the future would probably be
-// provided by libprocess anyway).
-
-namespace thread {
-
-// TODO(benh): Provide a version of 'start' that returns a type T (the
-// value being a copy or preferablly via move semantics).
-bool start(const lambda::function<void(void)>& f, bool detach = false);
-
-} // namespace thread {
-
-#endif // __THREAD_HPP__
[2/5] mesos git commit: Used std::thread instead of pthread for ns
tests.
Posted by be...@apache.org.
Used std::thread instead of pthread for ns tests.
Review: https://reviews.apache.org/r/36824
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/16de8bd6
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/16de8bd6
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/16de8bd6
Branch: refs/heads/master
Commit: 16de8bd6ef8ba17008e63b8c65ec73be4e3c36d8
Parents: cbc102e
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Wed Jul 29 16:21:36 2015 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Wed Jul 29 16:24:53 2015 -0700
----------------------------------------------------------------------
src/tests/containerizer/ns_tests.cpp | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/16de8bd6/src/tests/containerizer/ns_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/ns_tests.cpp b/src/tests/containerizer/ns_tests.cpp
index c71c33f..3a22938 100644
--- a/src/tests/containerizer/ns_tests.cpp
+++ b/src/tests/containerizer/ns_tests.cpp
@@ -20,11 +20,11 @@
#include <iostream>
-#include <pthread.h>
#include <unistd.h>
#include <list>
#include <set>
+#include <thread>
#include <vector>
#include <gtest/gtest.h>
@@ -34,6 +34,8 @@
#include <stout/os.hpp>
#include <process/gtest.hpp>
+#include <process/latch.hpp>
+#include <process/owned.hpp>
#include <process/subprocess.hpp>
#include "linux/ns.hpp"
@@ -134,16 +136,6 @@ TEST(NsTest, ROOT_setns)
}
-static void* childThread(void* arg)
-{
- // Newly created threads have PTHREAD_CANCEL_ENABLE and
- // PTHREAD_CANCEL_DEFERRED so they can be cancelled.
- while (true) { os::sleep(Seconds(1)); }
-
- return NULL;
-}
-
-
// Test that setns correctly refuses to re-associate to a namespace if
// the caller is multi-threaded.
TEST(NsTest, ROOT_setnsMultipleThreads)
@@ -151,17 +143,24 @@ TEST(NsTest, ROOT_setnsMultipleThreads)
set<string> namespaces = ns::namespaces();
EXPECT_LT(0u, namespaces.size());
+ Latch* latch = new Latch();
+
// Do not allow multi-threaded environment.
- pthread_t pthread;
- ASSERT_EQ(0, pthread_create(&pthread, NULL, childThread, NULL));
+ std::thread thread([=]() {
+ // Wait until the main thread tells us to exit.
+ latch->await();
+ });
foreach (const string& ns, namespaces) {
EXPECT_ERROR(ns::setns(::getpid(), ns));
}
- // Terminate the threads.
- EXPECT_EQ(0, pthread_cancel(pthread));
- EXPECT_EQ(0, pthread_join(pthread, NULL));
+ // Terminate the thread.
+ latch->trigger();
+
+ thread.join();
+
+ delete latch;
}