本文整理汇总了C++中sigwaitinfo函数的典型用法代码示例。如果您正苦于以下问题:C++ sigwaitinfo函数的具体用法?C++ sigwaitinfo怎么用?C++ sigwaitinfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sigwaitinfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
/**
* Run the daemon and handle unix signals
*/
static void run()
{
sigset_t set;
/* handle SIGINT and SIGTERM in this handler */
sigemptyset(&set);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGTERM);
sigprocmask(SIG_BLOCK, &set, NULL);
while (TRUE)
{
int sig;
sig = sigwaitinfo(&set, NULL);
if (sig == -1)
{
if (errno == EINTR)
{ /* ignore signals we didn't wait for */
continue;
}
DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
return;
}
switch (sig)
{
case SIGINT:
{
DBG1(DBG_DMN, "signal of type SIGINT received. Shutting down");
charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
return;
}
case SIGTERM:
{
DBG1(DBG_DMN, "signal of type SIGTERM received. Shutting down");
charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
return;
}
}
}
}
示例2: luasandbox_timer_stop_one
static void luasandbox_timer_stop_one(luasandbox_timer * lt, struct timespec * remaining)
{
static struct timespec zero = {0, 0};
struct itimerspec its;
timer_gettime(lt->timer, &its);
if (remaining) {
*remaining = its.it_value;
}
its.it_value = zero;
its.it_interval = zero;
timer_settime(lt->timer, 0, &its, NULL);
if (lt->cbdata.type == LUASANDBOX_TIMER_PROFILER) {
// Invalidate the cbdata, delete the timer
lt->cbdata.sandbox = NULL;
timer_delete(lt->timer);
// If the timer event handler is running, wait for it to finish
// before returning to the caller, otherwise the timer event handler
// may find itself with a dangling pointer in its local scope.
while (sem_wait(<->cbdata.semaphore) && errno == EINTR);
sem_destroy(<->cbdata.semaphore);
} else {
// Block the signal, delete the timer, flush pending signals, restore
sigset_t sigset, oldset, pendset;
siginfo_t info;
sigemptyset(&sigset);
sigaddset(&sigset, LUASANDBOX_SIGNAL);
sigprocmask(SIG_BLOCK, &sigset, &oldset);
timer_delete(lt->timer);
while (1) {
sigpending(&pendset);
if (!sigismember(&pendset, LUASANDBOX_SIGNAL)) {
break;
}
sigwaitinfo(&sigset, &info);
luasandbox_timer_handle_signal(LUASANDBOX_SIGNAL, &info, NULL);
}
sigprocmask(SIG_SETMASK, &oldset, NULL);
}
}
示例3: trv_joystick_wait
static int trv_joystick_wait(void)
{
sigset_t set;
struct siginfo value;
int ret;
/* Wait for a signal */
(void)sigemptyset(&set);
(void)sigaddset(&set, CONFIG_GRAPHICS_TRAVELER_JOYSTICK_SIGNO);
ret = sigwaitinfo(&set, &value);
if (ret < 0)
{
int errcode = errno;
fprintf(stderr, "ERROR: sigwaitinfo() failed: %d\n", errcode);
return -errcode;
}
return OK;
}
示例4: sigwait_loop
/**
* This is a thread with priority kernel_prio that synchronously waits for
* rtdal_pipeline signals (usign sigwaitinfo). All signals except thread-specific
* ones (SIGSEGV,SIGILL,SIGBUS,SIGFPE) are blocked by all threads except this one.
* Thread-specific signals are handled by ProcThreads which send a SIGRTMIN+1,
* SIGRTMIN+2,SIGRTMIN+3,SIGRTMIN+4 (respectively) to this thread, which takes
* actions accordingly.
*
* for signals SIGRTMIN to SIGRTMIN+4, cast the rtdal_pipeline object from this
* si_value pointer and call rtdal_pipeline_recover_thread(pipeline,
* pipeline->running_process, TRUE)
*/
void sigwait_loop(void) {
int signum;
sigset_t set;
siginfo_t info;
sigfillset(&set);
sigdelset(&set,TASK_TERMINATION_SIGNAL);
while(!sigwait_stops) {
do {
signum = sigwaitinfo(&set, &info);
} while (signum == -1 && errno == EINTR);
if (signum == -1) {
poserror(errno, "sigwaitinfo");
goto out;
}
hdebug("detected signal %d\n",signum);
if (signum == KERNEL_SIG_THREAD_SPECIFIC) {
printf("[rtdal]: Caught thread-specific signal\n");
#ifdef EXIT_ON_THREADSIG
fflush(stdout);
goto out;
#else
sigwait_loop_process_thread_signal(&info);
#endif
} else if (signum == SIGINT) {
printf("Caught SIGINT, exiting\n");
fflush(stdout);
goto out;
} else if (signum != SIGWINCH && signum != SIGCHLD) {
printf("Got signal %d, exiting\n", signum);
fflush(stdout);
goto out;
}
}
out:
kernel_exit();
}
示例5: lio_waitall
static int lio_waitall(FAR struct aiocb *const *list, int nent)
{
sigset_t set;
int ret;
/* Loop until all I/O completes */
for (;;) {
/* Check if all I/O has completed */
ret = lio_checkio(list, nent);
if (ret != -EINPROGRESS) {
/* All I/O has completed.. We are finished. */
return ret;
}
/* Then wait for SIGPOLL -- indefinitely.
*
* NOTE: If completion of the I/O causes other signals to be generated
* first, then this will wake up and return EINTR instead of success.
*/
sigemptyset(&set);
sigaddset(&set, SIGPOLL);
ret = sigwaitinfo(&set, NULL);
if (ret < 0) {
/* The most likely reason that we would get here is because some
* unrelated signal has been received.
*/
int errcode = get_errno();
fdbg("ERROR: sigwaitinfo failed: %d\n", errcode);
DEBUGASSERT(errcode > 0);
return -errcode;
}
}
}
示例6: signal_check_functions
void signal_check_functions(pthread_t tid, sigset_t *ss, union sigval sv)
{
typedef void (*signal_cb_t)(int );
(void)kill((pid_t)0, 0);
#if __XSI_VISIBLE
(void)killpg((pid_t)0, 0);
#endif
#if !__APPLE__
(void)psiginfo((const siginfo_t *)0, (const char *)0);
#endif
(void)psignal(0, (const char*)0);
(void)pthread_kill(tid, 0);
(void)pthread_sigmask(0, (const sigset_t*)0, (sigset_t*)0);
(void)raise(0);
(void)sigaction(0, (const struct sigaction*)0, (struct sigaction*)0);
(void)sigaddset(ss, 0);
#if __XSI_VISIBLE
(void)sigaltstack((const stack_t*)0, (stack_t*)0);
#endif
(void)sigdelset(ss, 0);
(void)sigemptyset(ss);
(void)sigfillset(ss);
(void)sigismember(ss, 0);
(void)signal(0, (signal_cb_t)0);
(void)sigpending(ss);
(void)sigprocmask(0, (const sigset_t*)0, (sigset_t*)0);
#if _POSIX_REALTIME_SIGNALS > 0
(void)sigqueue((pid_t)0, 0, sv);
#endif
(void)sigsuspend(ss);
#if _POSIX_REALTIME_SIGNALS > 0
(void)sigtimedwait((const sigset_t*)0, (siginfo_t*)0, (const struct timespec*)0);
#endif
(void)sigwait(ss, (int*)0);
#if _POSIX_REALTIME_SIGNALS > 0
(void)sigwaitinfo(ss, (siginfo_t*)0);
#endif
}
示例7: memset
/* Helper function to support starting threads for SIGEV_THREAD. */
static void *timer_thread_main (void *arg)
{
/* Wait for the SIGTIMER signal */
sem_t *sem = (sem_t *)arg;
#ifdef ANDROID
unsigned long sigset[2];
memset(&sigset, 0, sizeof(sigset));
#else
sigset_t sigset;
sigemptyset(&sigset);
#endif
sigaddset((sigset_t*)&sigset, SIGTIMER);
th_timer_tid = gettid();
sem_post(sem);
/* Endless loop for waiting for signals. The loop is only ended when
the thread is canceled. */
while (1) {
siginfo_t si;
int result;
#ifdef ANDROID
result = __rt_sigtimedwait((sigset_t*)&sigset, &si, NULL, sizeof(sigset));
#else
result = sigwaitinfo(&sigset, &si);
#endif
if (result > 0)
{
if (si.si_code == SI_TIMER) {
timer *t;
t = static_cast<timer*>(si.si_value.sival_ptr);
t->alarm.signal();
}
}
}
return NULL;
}
示例8: main
int main(void)
{
int pid, rtsig;
union sigval value;
struct sigaction act;
sigset_t selectset;
act.sa_flags = SA_SIGINFO;
act.sa_sigaction = myhandler;
sigemptyset(&act.sa_mask);
sigemptyset(&selectset);
for (rtsig = SIGRTMAX; rtsig >= SIGRTMIN; rtsig--) {
sigaddset(&act.sa_mask, rtsig);
sighold(rtsig);
sigaddset(&selectset, rtsig);
}
pid = getpid();
value.sival_int = 5; /* 5 is just an arbitrary value */
for (rtsig = SIGRTMAX; rtsig >= SIGRTMIN; rtsig--) {
sigaction(rtsig, &act, 0);
if (sigqueue(pid, rtsig, value) != 0) {
printf
("Test UNRESOLVED: call to sigqueue did not return success\n");
return PTS_UNRESOLVED;
}
}
if (sigwaitinfo(&selectset, NULL) != SIGRTMIN) {
printf
("Test FAILED: sigwaitinfo() did not return the lowest of the multiple pending signals between SIGRTMIN and SIGRTMAX\n");
return PTS_FAIL;
}
return PTS_PASS;
}
示例9: timer_notify_thread_func
static void *
timer_notify_thread_func(void *arg)
{
sigset_t set;
siginfo_t info;
my_timer_t *timer;
pthread_barrier_t *barrier= arg;
my_thread_init();
sigemptyset(&set);
sigaddset(&set, MY_TIMER_EVENT_SIGNO);
sigaddset(&set, MY_TIMER_KILL_SIGNO);
/* Get the thread ID of the current thread. */
timer_notify_thread_id= (pid_t) syscall(SYS_gettid);
/* Wake up parent thread, timer_notify_thread_id is available. */
pthread_barrier_wait(barrier);
while (1)
{
if (sigwaitinfo(&set, &info) < 0)
continue;
if (info.si_signo == MY_TIMER_EVENT_SIGNO)
{
timer= (my_timer_t*)info.si_value.sival_ptr;
timer->notify_function(timer);
}
else if (info.si_signo == MY_TIMER_KILL_SIGNO)
break;
}
my_thread_end();
return NULL;
}
示例10: sigmgr_thread
void* sigmgr_thread()
{
sigset_t waitset, oset;
siginfo_t info;
int rc;
pthread_t ppid = pthread_self();
pthread_detach(ppid);
sigemptyset(&waitset);
sigaddset(&waitset, SIGRTMIN);
sigaddset(&waitset, SIGUSR1);
while (1) {
rc = sigwaitinfo(&waitset, &info);
if (rc != -1) {
printf("sigwaitinfo() fetch the signal - %d\n", rc);
sig_handler(info.si_signo);
} else {
printf("sigwaitinfo() returned err: %d; %s\n", errno, strerror(errno));
}
}
}
示例11: TEST
TEST(signal, sigwaitinfo) {
// Block SIGALRM.
sigset_t just_SIGALRM;
sigemptyset(&just_SIGALRM);
sigaddset(&just_SIGALRM, SIGALRM);
sigset_t original_set;
ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, &original_set));
// Raise SIGALRM.
sigval_t sigval;
sigval.sival_int = 1;
ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval));
// Get pending SIGALRM.
siginfo_t info;
errno = 0;
ASSERT_EQ(SIGALRM, sigwaitinfo(&just_SIGALRM, &info));
ASSERT_EQ(0, errno);
ASSERT_EQ(SIGALRM, info.si_signo);
ASSERT_EQ(1, info.si_value.sival_int);
ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &original_set, NULL));
}
示例12: ping_via_slots
int ping_via_slots(const char *name, struct servants_list_item *servants)
{
int sig = 0;
pid_t pid = 0;
int status = 0;
int servants_finished = 0;
sigset_t procmask;
siginfo_t sinfo;
struct servants_list_item *s;
sigemptyset(&procmask);
sigaddset(&procmask, SIGCHLD);
sigprocmask(SIG_BLOCK, &procmask, NULL);
for (s = servants; s; s = s->next) {
if(sbd_is_disk(s)) {
s->pid = assign_servant(s->devname, &slot_ping_wrapper, 0, (const void*)name);
}
}
while (servants_finished < disk_count) {
sig = sigwaitinfo(&procmask, &sinfo);
if (sig == SIGCHLD) {
while ((pid = wait(&status))) {
if (pid == -1 && errno == ECHILD) {
break;
} else {
s = lookup_servant_by_pid(pid);
if (s && sbd_is_disk(s)) {
servants_finished++;
}
}
}
}
}
return 0;
}
示例13: sigwaitinfo
/*[sig_thread]*/
static void *sig_thread(void *arg)
{
int signum;
siginfo_t info;
do {
signum = sigwaitinfo((sigset_t *)arg, &info);
if (signum == MYSIG_COUNT)
printf("Got MYSIG_COUNT; value: %s\n",
(char *)info.si_value.sival_ptr);
else if (signum == MYSIG_STOP) {
printf("Got MYSIG_STOP; terminating thread\n");
return (void *)true;
}
else
printf("Got %d\n", signum);
} while (signum != -1 || errno == EINTR);
EC_FAIL
EC_CLEANUP_BGN
EC_FLUSH("sig_thread")
return (void *)false;
EC_CLEANUP_END
}
示例14: msd_signal_thread_cycle
/**
* 功能: 专职信号处理线程
* 说明:
* 1.将别的线程阻塞起来的信号,全部加入到自己的监听掩码中来
* 2.无限循环,阻塞起来,等待自己监听的信号到来
* 注意:
* 1. 对于共有信号的这种处理,是"同步"方式
* 返回:成功:0; 失败:-x
**/
static void* msd_signal_thread_cycle(void *arg)
{
sigset_t waitset;
siginfo_t info;
int rc;
msd_thread_signal_t *sig_worker = (msd_thread_signal_t *)arg;
MSD_INFO_LOG("Worker[Signal] begin to work");
/* 将别的线程阻塞的信号,全部加入自己的监听范围 */
sigemptyset(&waitset);
sigaddset(&waitset, SIGTERM);
sigaddset(&waitset, SIGQUIT);
sigaddset(&waitset, SIGCHLD);
sigaddset(&waitset, SIGPIPE);
sigaddset(&waitset, SIGINT);
sigaddset(&waitset, SIGHUP);
/* 无线循环阻塞,等待信号到来 */
while (1)
{
rc = sigwaitinfo(&waitset, &info);
if (rc != MSD_ERR)
{
/* 同步处理信号 */
msd_public_signal_handler(info.si_signo, sig_worker);
}
else
{
MSD_ERROR_LOG("Sigwaitinfo() returned err: %d; %s", errno, strerror(errno));
}
}
//free(sig_worker);//msd_destroy_instance中会统一释放资源
return (void *)NULL;
}
示例15: my_sigwaitinfo
static int my_sigwaitinfo(const sigset_t* set, siginfo_t* info, struct timespec* timeout)
{
return sigwaitinfo(set, info);
}