当前位置: 首页>>代码示例>>C++>>正文


C++ sigwaitinfo函数代码示例

本文整理汇总了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;
			}
		}
	}
}
开发者ID:mikma,项目名称:strongswan,代码行数:44,代码来源:charon-nm.c

示例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(&lt->cbdata.semaphore) && errno == EINTR);
		sem_destroy(&lt->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);
	}
}
开发者ID:butch2k,项目名称:mediawiki-php-luasandbox,代码行数:41,代码来源:timer.c

示例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;
}
开发者ID:nodesign,项目名称:nuttx-apps,代码行数:21,代码来源:trv_input.c

示例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();
}
开发者ID:alring,项目名称:aloe,代码行数:51,代码来源:rtdal_kernel_signals.c

示例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;
		}
	}
}
开发者ID:drashti304,项目名称:TizenRT,代码行数:39,代码来源:lio_listio.c

示例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
}
开发者ID:Zengwn,项目名称:android-platform-ndk,代码行数:39,代码来源:signal.c

示例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;
}
开发者ID:Meticulus,项目名称:vendor_st-ericsson_u8500,代码行数:39,代码来源:timer.cpp

示例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;
}
开发者ID:1587,项目名称:ltp,代码行数:38,代码来源:2-1.c

示例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;
}
开发者ID:JohnOhl,项目名称:mysql-connector-c,代码行数:38,代码来源:posix_timers.c

示例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));
		}
	}
}
开发者ID:1023xp,项目名称:training,代码行数:23,代码来源:signalsync.c

示例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));
}
开发者ID:RUIXUEZHAOFENGNIAN,项目名称:platform_bionic,代码行数:23,代码来源:signal_test.cpp

示例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;
}
开发者ID:credativ,项目名称:sbd,代码行数:37,代码来源:sbd-md.c

示例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
}
开发者ID:4get,项目名称:aup2ex,代码行数:25,代码来源:thrq.c

示例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;
}
开发者ID:hq-cml,项目名称:mossad,代码行数:45,代码来源:msd_signal.c

示例15: my_sigwaitinfo

static int my_sigwaitinfo(const sigset_t* set, siginfo_t* info, struct timespec* timeout)
{
	return sigwaitinfo(set, info);
}
开发者ID:ystk,项目名称:debian-ltp,代码行数:4,代码来源:sigwaitinfo01.c


注:本文中的sigwaitinfo函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。