docs: gzip manpages
[m6w6/libmemcached] / libtest / signal.h
index beb28b22a478aa6fe90a33eeee1f3d4ff3efaaec..6e68bb3878b0a289aafbe48fb0487b92ed4d04c4 100644 (file)
@@ -1,8 +1,8 @@
 /*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
- * 
- *  uTest, libtest
  *
- *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *  Data Differential YATL (i.e. libtest)  library
+ *
+ *  Copyright (C) 2012 Data Differential, http://datadifferential.com/
  *
  *  Redistribution and use in source and binary forms, with or without
  *  modification, are permitted provided that the following conditions are
  *
  */
 
-
 #pragma once 
 
+#include <pthread.h>
+#include <semaphore.h>
+#include <signal.h>
+
 enum shutdown_t {
   SHUTDOWN_RUNNING,
   SHUTDOWN_GRACEFUL,
   SHUTDOWN_FORCED
 };
 
-LIBTEST_INTERNAL_API
-bool is_shutdown();
+namespace libtest {
+
+class SignalThread {
+  sigset_t set;
+  sem_t lock;
+  uint64_t magic_memory;
+  volatile shutdown_t __shutdown;
+  pthread_mutex_t shutdown_mutex;
+  pthread_t thread;
+  sigset_t original_set;
 
-LIBTEST_INTERNAL_API
-shutdown_t get_shutdown();
+public:
 
-LIBTEST_INTERNAL_API
-void set_shutdown(shutdown_t arg);
+  SignalThread();
+  ~SignalThread();
+
+  void test();
+  void post();
+  bool setup();
+  bool unblock();
+
+  int wait(int& sig)
+  {
+    return sigwait(&set, &sig);
+  }
+
+  void set_shutdown(shutdown_t arg);
+  bool is_shutdown();
+  shutdown_t get_shutdown();
+};
 
-LIBTEST_INTERNAL_API
-void setup_signals(void);
+} // namespace libtest