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 2014/12/25 22:05:59 UTC

[08/12] mesos git commit: Introduce libevent header and implementation.

Introduce libevent header and implementation.

Review: https://reviews.apache.org/r/28321


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0e29981b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0e29981b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0e29981b

Branch: refs/heads/master
Commit: 0e29981b8bac58886f515485403f3b0c585e18e6
Parents: 3347a2b
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Sat Dec 20 12:03:28 2014 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Thu Dec 25 11:54:12 2014 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/Makefile.am      | 18 ++++++++-----
 3rdparty/libprocess/configure.ac     | 15 +++++++++++
 3rdparty/libprocess/src/libevent.cpp | 44 +++++++++++++++++++++++++++++++
 3rdparty/libprocess/src/libevent.hpp | 11 ++++++++
 3rdparty/libprocess/src/process.cpp  |  2 +-
 5 files changed, 83 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0e29981b/3rdparty/libprocess/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/Makefile.am b/3rdparty/libprocess/Makefile.am
index 5c92ee5..b95c0a9 100644
--- a/3rdparty/libprocess/Makefile.am
+++ b/3rdparty/libprocess/Makefile.am
@@ -58,7 +58,9 @@ libprocess_la_CPPFLAGS =		\
   $(AM_CPPFLAGS)
 
 if ENABLE_LIBEVENT
-# Place for libevent implementations.
+libprocess_la_SOURCES +=	\
+    src/libevent.hpp		\
+    src/libevent.cpp
 else
   libprocess_la_SOURCES +=	\
     src/libev.hpp		\
@@ -82,16 +84,20 @@ else
   HTTP_PARSER_LIB = -lhttp_parser
 endif
 
+if ENABLE_LIBEVENT
+  EVENT_LIB = -levent -levent_pthreads
+else
 if WITH_BUNDLED_LIBEV
-  LIBEV_LIB = $(LIBEV)/libev.la
+  EVENT_LIB = $(LIBEV)/libev.la
 else
-  LIBEV_LIB = -lev
+  EVENT_LIB = -lev
+endif
 endif
 
 libprocess_la_LIBADD =			\
   $(LIBGLOG)				\
   $(HTTP_PARSER_LIB)			\
-  $(LIBEV_LIB)
+  $(EVENT_LIB)
 
 if HAS_GPERFTOOLS
 libprocess_la_CPPFLAGS += -I$(GPERFTOOLS)/src
@@ -132,7 +138,7 @@ tests_LDADD =				\
   libprocess.la				\
   $(LIBGLOG)				\
   $(HTTP_PARSER_LIB)			\
-  $(LIBEV_LIB)
+  $(EVENT_LIB)
 
 benchmarks_SOURCES =			\
   src/tests/benchmarks.cpp
@@ -148,7 +154,7 @@ benchmarks_LDADD =			\
   libprocess.la				\
   $(LIBGLOG)				\
   $(HTTP_PARSER_LIB)			\
-  $(LIBEV_LIB)
+  $(EVENT_LIB)
 
 # We use a check-local target for now to avoid the parallel test
 # runner that ships with newer versions of autotools.

http://git-wip-us.apache.org/repos/asf/mesos/blob/0e29981b/3rdparty/libprocess/configure.ac
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/configure.ac b/3rdparty/libprocess/configure.ac
index 2f01a3b..19bc601 100644
--- a/3rdparty/libprocess/configure.ac
+++ b/3rdparty/libprocess/configure.ac
@@ -589,6 +589,21 @@ libevent is required for mesos to build.
   if test "x$found_libevent" = "xyes"; then
     AC_DEFINE([USE_LIBEVENT], [1])
   fi
+  AC_CHECK_HEADERS([event2/thread.h],
+                   [AC_CHECK_LIB([event_pthreads],
+                                 [evthread_use_pthreads],
+                                 [found_libevent_thread=yes],
+                                 [AC_MSG_ERROR([cannot find libevent_pthreads
+-------------------------------------------------------------------
+libevent_pthreads is required for mesos to build.
+-------------------------------------------------------------------
+                          ])],
+                                 [-levent])],
+                                 [AC_MSG_ERROR([cannot find libevent_pthreads headers
+-------------------------------------------------------------------
+libevent_pthreads is required for mesos to build.
+-------------------------------------------------------------------
+  ])])
 fi
 
 AS_IF([test "x${ac_cv_env_CFLAGS_set}" = "x"],

http://git-wip-us.apache.org/repos/asf/mesos/blob/0e29981b/3rdparty/libprocess/src/libevent.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/libevent.cpp b/3rdparty/libprocess/src/libevent.cpp
new file mode 100644
index 0000000..524d811
--- /dev/null
+++ b/3rdparty/libprocess/src/libevent.cpp
@@ -0,0 +1,44 @@
+#include <unistd.h>
+
+#include <event2/event.h>
+#include <event2/thread.h>
+
+#include <process/logging.hpp>
+
+#include "event_loop.hpp"
+#include "libevent.hpp"
+
+namespace process {
+
+struct event_base* base = NULL;
+
+void* EventLoop::run(void*)
+{
+  int result = event_base_loop(base, 0);
+  if (result < 0) {
+    LOG(FATAL) << "Failed to run event loop";
+  } else if (result == 1) {
+    VLOG(1) << "Finished running event loop due to lack of events";
+  }
+
+  return NULL;
+}
+
+
+void EventLoop::initialize()
+{
+  if (evthread_use_pthreads() < 0) {
+    LOG(FATAL) << "Failed to initialize, evthread_use_pthreads";
+  }
+
+  // This enables debugging of libevent calls. We can remove this
+  // when the implementation settles and after we gain confidence.
+  event_enable_debug_mode();
+
+  base = event_base_new();
+  if (base == NULL) {
+    LOG(FATAL) << "Failed to initialize, event_base_new";
+  }
+}
+
+} // namespace process {

http://git-wip-us.apache.org/repos/asf/mesos/blob/0e29981b/3rdparty/libprocess/src/libevent.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/libevent.hpp b/3rdparty/libprocess/src/libevent.hpp
new file mode 100644
index 0000000..f6cc721
--- /dev/null
+++ b/3rdparty/libprocess/src/libevent.hpp
@@ -0,0 +1,11 @@
+#ifndef __LIBEVENT_HPP__
+#define __LIBEVENT_HPP__
+
+namespace process {
+
+// Event loop.
+extern struct event_base* base;
+
+} // namespace process {
+
+#endif // __LIBEVENT_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/0e29981b/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index fabcca4..441ce48 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -84,7 +84,7 @@
 #ifndef USE_LIBEVENT
 #include "libev.hpp"
 #else
-// Place for libevent header.
+#include "libevent.hpp"
 #endif // USE_LIBEVENT
 #include "process_reference.hpp"
 #include "synchronized.hpp"