]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
EventSocket: Add EventSocket structure used for event notification
authorHaomai Wang <haomaiwang@gmail.com>
Tue, 4 Aug 2015 09:20:36 +0000 (17:20 +0800)
committerHaomai Wang <haomai@xsky.com>
Thu, 26 Nov 2015 02:58:58 +0000 (10:58 +0800)
EventSocket will wrap different user event notification method like linux
eventfd, solaris port. Caller can user this to replace signal

Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
configure.ac
src/common/event_socket.h [new file with mode: 0644]
src/include/event_type.h [new file with mode: 0644]

index de025ecf41be8875c6fb0b0bee3e4ef233ce58cc..77fe957d83d80a7d5368093dff2521206ce8ac23 100644 (file)
@@ -1309,8 +1309,15 @@ AC_ARG_WITH(
     ]
 )
 
-
-
+# Force not to use eventfd
+AC_ARG_WITH([eventfd],
+            [AS_HELP_STRING([--without-eventfd], [disable eventfd [default=no]])],
+            ,
+            [with_eventfd=yes])
+AS_IF([test "x$with_eventfd" != xno],
+    AC_CHECK_HEADERS(sys/eventfd.h,
+                     [AC_DEFINE(HAVE_EVENTFD, 1, [Have eventfd extension.])]))
+AM_CONDITIONAL(WITH_EVENTFD, [ test "$with_eventfd" = "yes" ])
 
 # Checks for typedefs, structures, and compiler characteristics.
 #AC_HEADER_STDBOOL
diff --git a/src/common/event_socket.h b/src/common/event_socket.h
new file mode 100644 (file)
index 0000000..f2ac92d
--- /dev/null
@@ -0,0 +1,52 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2015 Haomai Wang <haomaiwang@gmail.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#ifndef CEPH_COMMON_EVENT_SOCKET_H
+#define CEPH_COMMON_EVENT_SOCKET_H
+
+#include "include/event_type.h"
+
+class EventSocket {
+  int socket;
+  int type;
+
+ public:
+  EventSocket(): socket(-1), type(EVENT_SOCKET_TYPE_NONE) {}
+  bool is_valid() const { return socket != -1; }
+  int init(int fd, int t) {
+#ifdef HAVE_EVENTFD
+    if (t == EVENT_SOCKET_TYPE_EVENTFD) {
+      socket = fd;
+      type = t;
+      return 0;
+    }
+#endif
+    return -1;
+  }
+  int notify() {
+    switch (type) {
+      case EVENT_SOCKET_TYPE_EVENTFD:
+      {
+        uint64_t value = 1;
+        return write(socket, &value, sizeof (value));
+      }
+      default:
+      {
+        return -1;
+      }
+    }
+  }
+};
+
+#endif
diff --git a/src/include/event_type.h b/src/include/event_type.h
new file mode 100644 (file)
index 0000000..adab690
--- /dev/null
@@ -0,0 +1,21 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2015 Haomai Wang <haomaiwang@gmail.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#ifndef CEPH_COMMON_EVENT_TYPE_H
+#define CEPH_COMMON_EVENT_TYPE_H
+
+#define EVENT_SOCKET_TYPE_NONE 0
+#define EVENT_SOCKET_TYPE_EVENTFD 1
+
+#endif