25#ifndef JAU_SERVICE_RUNNER_HPP_
26#define JAU_SERVICE_RUNNER_HPP_
35#include <condition_variable>
78 std::mutex mtx_shall_stop_;
79 std::condition_variable cv_shall_stop_;
82 ::pthread_t thread_id_;
84 std::mutex mtx_lifecycle;
85 std::condition_variable cv_init;
87 void service_thread();
89 static bool install_sighandler() noexcept;
113 static bool r = install_sighandler();
144 const
std::
string&
name() const noexcept {
return name_; }
156 pthread_t
thread_id() const noexcept {
return thread_id_; }
192 bool shall_stop2(
int dummy)
noexcept { (void)dummy;
return shall_stop_; }
210 std::condition_variable&
cv_shall_stop() noexcept {
return cv_shall_stop_; }
226 void start() noexcept;
257 bool stop() noexcept;
275 bool join() noexcept;
Class template jau::function is a general-purpose static-polymorphic function wrapper.
Service runner, a reusable dedicated thread performing custom user services.
bool stop() noexcept
Stops this service, if running.
bool shall_stop2(int dummy) noexcept
Helper function to easy FunctionDef usage w/o creating a lambda alike capture with same semantics as ...
const std::string & name() const noexcept
Return the given name of this service.
function< void(service_runner_ref)> Callback
static bool remove_sighandler() noexcept
Remove the sighandler.
std::mutex & mtx_shall_stop() noexcept
mtx_shall_stop() and cv_shall_stop() allows caller to be notified when shall_stop() changes,...
fraction_i64 service_shutdown_timeout() const noexcept
Returns maximum duration in fractions of seconds to wait for service to stop at stop() and join(),...
static const ::pid_t pid_self
void set_shall_stop() noexcept
Marks the service thread to stop in due process by flagging shall stop to true.
service_runner & service_runner_ref
service_runner(std::string name, fraction_i64 service_shutdown_timeout, Callback service_work, Callback service_init_locked=Callback(), Callback service_end_locked=Callback()) noexcept
Service runner constructor.
std::condition_variable & cv_shall_stop() noexcept
mtx_shall_stop() and cv_shall_stop() allows caller to be notified when shall_stop() changes,...
bool is_running() const noexcept
Returns true if service is running.
pthread_t thread_id() const noexcept
Return the thread-id of this service service thread, zero if not running.
bool join() noexcept
Blocks the current thread until service is stopped or returns immediately if not running or called fr...
bool shall_stop() const noexcept
Returns true if service shall stop.
static bool singleton_sighandler() noexcept
Install the singleton SIGALRM sighandler instance.
std::string toString() const noexcept
Returns a string representation of this service.
void start() noexcept
Starts this service, if not running already.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.