X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fsignal.h;h=fd7e4a6d359287ba925a7607ba0e9033b14e89be;hb=7d698ad128550cb4d2e3a60c83533c4370efd106;hp=beb28b22a478aa6fe90a33eeee1f3d4ff3efaaec;hpb=28602fd2f5f1c758b50cd82d4545da8e6c55f5c7;p=m6w6%2Flibmemcached diff --git a/libtest/signal.h b/libtest/signal.h index beb28b22..fd7e4a6d 100644 --- a/libtest/signal.h +++ b/libtest/signal.h @@ -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 @@ -34,23 +34,46 @@ * */ - #pragma once +#include +#include +#include + 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(); + + 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