about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-02-15 02:54:20 +0000
committerEric Wong <normalperson@yhbt.net>2013-02-15 02:54:20 +0000
commit476cc380a94db3355f818b2c798cdeeb0c626cc0 (patch)
treef4ec80ae1f073cf0a73418f0dd37068f12b13cfd
parentb7403080f0266ac41cecae80adcfa0391f3f93b7 (diff)
downloadcmogstored-476cc380a94db3355f818b2c798cdeeb0c626cc0.tar.gz
We want to favor ppoll over pselect, since ppoll is a better
interface and we can have a slightly smaller binary with fewer
dependencies.

While we're at it, use mog_sleep(-1) as an alias for
mog_selfwake_wait to further reduce binary size.
-rw-r--r--cmogstored.h10
-rw-r--r--selfwake.h7
-rw-r--r--sig.c24
3 files changed, 27 insertions, 14 deletions
diff --git a/cmogstored.h b/cmogstored.h
index 393cecb..d5f6137 100644
--- a/cmogstored.h
+++ b/cmogstored.h
@@ -242,6 +242,11 @@ struct mog_file {
 
 #include "queue_epoll.h"
 #include "notify.h"
+
+/* sig.c */
+void mog_intr_disable(void);
+void mog_intr_enable(void);
+void mog_sleep(long seconds);
 #include "selfwake.h"
 
 enum mog_fd_type {
@@ -411,11 +416,6 @@ void mog_queue_quit_loop(struct mog_queue *queue);
 /* queue_step.c */
 enum mog_next mog_queue_step(struct mog_fd *mfd) MOG_CHECK;
 
-/* sig.c */
-void mog_intr_disable(void);
-void mog_intr_enable(void);
-void mog_sleep(long seconds);
-
 /* file.c */
 struct mog_fd * mog_file_open_read(struct mog_svc *, char *path);
 struct mog_fd * mog_file_open_put(struct mog_svc *, char *path, int flags);
diff --git a/selfwake.h b/selfwake.h
index 6806b94..37bf0f6 100644
--- a/selfwake.h
+++ b/selfwake.h
@@ -28,12 +28,7 @@ void mog_selfwake_wait(struct mog_fd *);
 #else /* use Linux-only facilities like epoll_pwait or ppoll */
 static inline void mog_selfwake_wait(struct mog_fd *mfd)
 {
-        sigset_t set;
-
-        CHECK(int, 0, sigemptyset(&set));
-        if (ppoll(NULL, 0, NULL, &set) != 0)
-                assert((errno == EINTR || errno == ENOMEM)
-                       && "ppoll usage bug");
+        mog_sleep(-1);
 }
 static inline struct mog_fd * mog_selfwake_new(void) { return NULL; }
 static inline void mog_selfwake_trigger(struct mog_fd *mfd) {}
diff --git a/sig.c b/sig.c
index 7fa2708..28f5017 100644
--- a/sig.c
+++ b/sig.c
@@ -24,6 +24,26 @@ void mog_intr_enable(void)
         CHECK(int, 0, pthread_sigmask(SIG_SETMASK, &set, NULL));
 }
 
+/*
+ * favor ppoll if available since this is our only pselect user and
+ * would increase the size of the executable
+ */
+#ifdef HAVE_PPOLL
+static void sleeper(struct timespec *tsp, const sigset_t *sigmask)
+{
+        if (ppoll(NULL, 0, tsp, sigmask) < 0)
+                assert((errno == EINTR || errno == ENOMEM) &&
+                       "BUG in ppoll usage");
+}
+#else /* PSELECT */
+static void sleeper(struct timespec *tsp, const sigset_t *sigmask)
+{
+        if (pselect(0, NULL, NULL, NULL, tsp, sigmask) < 0)
+                assert((errno == EINTR || errno == ENOMEM) &&
+                       "BUG in pselect usage");
+}
+#endif /* PSELECT */
+
 /* thread-safe, interruptible sleep, negative seconds -> sleep forever */
 void mog_sleep(long seconds)
 {
@@ -40,7 +60,5 @@ void mog_sleep(long seconds)
         }
 
         CHECK(int, 0, sigemptyset(&set));
-        if (pselect(0, NULL, NULL, NULL, tsp, &set) < 0)
-                assert((errno == EINTR || errno == ENOMEM) &&
-                       "BUG in pselect usage");
+        sleeper(tsp, &set);
 }