From 720ac2b80bb035e0cf019a26923e1b95f4c28559 Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Tue, 4 Aug 2015 17:20:36 +0800 Subject: [PATCH] EventSocket: Add EventSocket structure used for event notification 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 --- configure.ac | 11 +++++++-- src/common/event_socket.h | 52 +++++++++++++++++++++++++++++++++++++++ src/include/event_type.h | 21 ++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 src/common/event_socket.h create mode 100644 src/include/event_type.h diff --git a/configure.ac b/configure.ac index de025ecf41be8..77fe957d83d80 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 0000000000000..f2ac92de5b39a --- /dev/null +++ b/src/common/event_socket.h @@ -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 + * + * 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 index 0000000000000..adab6907227ab --- /dev/null +++ b/src/include/event_type.h @@ -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 + * + * 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 -- 2.39.5