UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
state_root Struct Reference
Collaboration diagram for state_root:
Collaboration graph

Public Member Functions

 state_root () noexcept
 
 ~state_root ()
 
void broadcast_should_exit (bool quit_watcher=false)
 

Static Public Member Functions

static void deleter (struct module *m)
 
static void should_exit_watcher (state_root *s)
 

Public Attributes

volatile int exit_status = EXIT_SUCCESS
 

Private Attributes

mutex lock
 
list< tuple< void(*)(void *), void * > > should_exit_callbacks
 
fd_t should_exit_pipe [2]
 
thread should_exit_thread
 

Static Private Attributes

static constexpr char QUIT_WATCHER_FLAG = 1
 

Friends

void register_should_exit_callback (struct module *mod, void(*callback)(void *), void *udata)
 
void unregister_should_exit_callback (struct module *mod, void(*callback)(void *), void *udata)
 

Detailed Description

Definition at line 539 of file host.cpp.

Constructor & Destructor Documentation

◆ state_root()

state_root::state_root ( )
inlinenoexcept

Definition at line 540 of file host.cpp.

540 {
542 LOG(LOG_LEVEL_FATAL) << "FATAL: Cannot create pipe!\n";
543 abort();
544 }
546 }
#define LOG(level)
Definition debug.h:313
#define LOG_LEVEL_FATAL
errors that prevent UG run
Definition debug.h:58
int platform_pipe_init(fd_t p[2])
fd_t should_exit_pipe[2]
Definition host.cpp:591
thread should_exit_thread
Definition host.cpp:592
static void should_exit_watcher(state_root *s)
Definition host.cpp:561

References LOG, LOG_LEVEL_FATAL, platform_pipe_init(), should_exit_pipe, should_exit_thread, and should_exit_watcher().

Here is the call graph for this function:

◆ ~state_root()

state_root::~state_root ( )
inline

Definition at line 547 of file host.cpp.

547 {
548 unique_lock<mutex> lk(lock);
549 should_exit_callbacks.clear();
550 lk.unlock();
551 broadcast_should_exit(true); // here just exit the should exit thr
552 should_exit_thread.join();
553 for (int i = 0; i < 2; ++i) {
555 }
556 }
void platform_pipe_close(fd_t pipe)
list< tuple< void(*)(void *), void * > > should_exit_callbacks
Definition host.cpp:593
void broadcast_should_exit(bool quit_watcher=false)
Definition host.cpp:579

References broadcast_should_exit(), platform_pipe_close(), should_exit_callbacks, should_exit_pipe, and should_exit_thread.

Here is the call graph for this function:

Member Function Documentation

◆ broadcast_should_exit()

void state_root::broadcast_should_exit ( bool quit_watcher = false)
inline

Definition at line 579 of file host.cpp.

580 {
581 const char q = quit_watcher ? QUIT_WATCHER_FLAG : 0;
582 while (PLATFORM_PIPE_WRITE(should_exit_pipe[1], &q, 1) != 1) {
583 perror("PLATFORM_PIPE_WRITE");
584 }
585 }
#define PLATFORM_PIPE_WRITE
static constexpr char QUIT_WATCHER_FLAG
Definition host.cpp:589

References PLATFORM_PIPE_WRITE, QUIT_WATCHER_FLAG, and should_exit_pipe.

Referenced by ~state_root(), and exit_uv().

◆ deleter()

static void state_root::deleter ( struct module * m)
inlinestatic

Definition at line 557 of file host.cpp.

557 {
558 delete (state_root*) m->priv_data;
559 }
void * priv_data
Definition module.h:126

References module::priv_data.

Referenced by init_root_module().

◆ should_exit_watcher()

static void state_root::should_exit_watcher ( state_root * s)
inlinestatic

Definition at line 561 of file host.cpp.

561 {
562 set_thread_name(__func__);
563 char q = 0;
564 bool should_exit_thread_notified = false;
565 while (q != QUIT_WATCHER_FLAG) {
566 while (PLATFORM_PIPE_READ(s->should_exit_pipe[0], &q,
567 1) != 1) {
568 perror("PLATFORM_PIPE_READ");
569 }
570 if (!should_exit_thread_notified) {
571 unique_lock<mutex> lk(s->lock);
572 for (auto const &c : s->should_exit_callbacks) {
573 get<0>(c)(get<1>(c));
574 }
575 should_exit_thread_notified = true;
576 }
577 }
578 }
#define PLATFORM_PIPE_READ
mutex lock
Definition host.cpp:590
void set_thread_name(const char *name)
Definition thread.c:72

References lock, PLATFORM_PIPE_READ, QUIT_WATCHER_FLAG, set_thread_name(), should_exit_callbacks, and should_exit_pipe.

Referenced by state_root().

Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ register_should_exit_callback

void register_should_exit_callback ( struct module * mod,
void(* callback )(void *),
void * udata )
friend

Definition at line 1144 of file host.cpp.

1145{
1146 auto *s = (state_root *) get_root_module(mod)->priv_data;
1147 unique_lock<mutex> lk(s->lock);
1148 s->should_exit_callbacks.emplace_back(callback, udata);
1149}
struct module * get_root_module(struct module *node)
Definition module.c:203
Option::Callback::fcn_type callback
Definition settings.cpp:251

◆ unregister_should_exit_callback

void unregister_should_exit_callback ( struct module * mod,
void(* callback )(void *),
void * udata )
friend

Unregisters should_exit callback registered with register_should_exit_callback

The callback must have been registered (and not unregistered), otherwise abort is (currently) called.

Definition at line 1158 of file host.cpp.

1160{
1161 auto *s = (state_root *) get_root_module(mod)->priv_data;
1162 unique_lock<mutex> lk(s->lock);
1163 for (auto it = s->should_exit_callbacks.begin();
1164 it != s->should_exit_callbacks.end(); ++it) {
1165 if (get<0>(*it) == callback && get<1>(*it) == udata) {
1166 s->should_exit_callbacks.erase(it);
1167 return;
1168 }
1169 }
1170 abort();
1171}

Member Data Documentation

◆ exit_status

volatile int state_root::exit_status = EXIT_SUCCESS

Definition at line 587 of file host.cpp.

Referenced by exit_uv().

◆ lock

mutex state_root::lock
private

Definition at line 590 of file host.cpp.

Referenced by should_exit_watcher().

◆ QUIT_WATCHER_FLAG

char state_root::QUIT_WATCHER_FLAG = 1
staticconstexprprivate

Definition at line 589 of file host.cpp.

Referenced by broadcast_should_exit(), and should_exit_watcher().

◆ should_exit_callbacks

list<tuple<void (*)(void *), void *> > state_root::should_exit_callbacks
private

Definition at line 593 of file host.cpp.

Referenced by ~state_root(), and should_exit_watcher().

◆ should_exit_pipe

fd_t state_root::should_exit_pipe[2]
private

Definition at line 591 of file host.cpp.

Referenced by state_root(), ~state_root(), broadcast_should_exit(), and should_exit_watcher().

◆ should_exit_thread

thread state_root::should_exit_thread
private

Definition at line 592 of file host.cpp.

Referenced by state_root(), and ~state_root().


The documentation for this struct was generated from the following file: