本文整理汇总了C++中sigrelse函数的典型用法代码示例。如果您正苦于以下问题:C++ sigrelse函数的具体用法?C++ sigrelse怎么用?C++ sigrelse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sigrelse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: abort
/*
* abort() - terminate current process with dump via SIGABRT
*/
void
abort(void)
{
sigset_t set;
struct sigaction act;
if (!sigaction(SIGABRT, NULL, &act) &&
act.sa_handler != SIG_DFL && act.sa_handler != SIG_IGN) {
/*
* User handler is installed, invokes user handler before
* taking default action.
*
* Send SIGABRT, unblock SIGABRT if blocked.
* If there is pending signal SIGABRT, we only need to unblock
* SIGABRT.
*/
if (!sigprocmask(SIG_SETMASK, NULL, &set) &&
sigismember(&set, SIGABRT)) {
if (!sigpending(&set) && !sigismember(&set, SIGABRT))
(void) raise(SIGABRT);
(void) sigrelse(SIGABRT);
} else
(void) raise(SIGABRT);
}
if (++pass == 1)
__cleanup();
for (;;) {
(void) signal(SIGABRT, SIG_DFL);
(void) sigrelse(SIGABRT);
(void) raise(SIGABRT);
}
}
示例2: semaphore_wait
/**
* Decrements the value of the given semaphore.
* If the value goes below 0, the thread is put into a WAIT state.
*/
void semaphore_wait(int semaphore) {
// disable alarm while working with semaphore
sighold(SIGALRM);
#if DEBUG == 1
char print[100];
sprintf(print, "wait called on semaphore %d with value %d\n", semaphore,
semaphores[semaphore]->value);
perror(print);
#endif
semaphores[semaphore]->value -= 1;
if (semaphores[semaphore]->value < 0) {
#if DEBUG == 1
sprintf(print, "thread %d put on waitqueue\n", current_thread);
perror(print);
#endif
// block thread
threads[current_thread]->state = WAIT;
// put it on the wait queue
list_append_int(semaphores[semaphore]->thread_queue, current_thread);
//unblock alarm and wait for scheduler to take over
sigrelse(SIGALRM);
while (threads[current_thread]->state == WAIT)
; // when semaphore is signaled thread will be RUNNABLE again and return from this function
} else {
//don't block thread, unblock alarm and go back to the thread
sigrelse(SIGALRM);
}
}
示例3: do_test
static int
do_test (void)
{
int result = 0;
int e;
#define RUN(test) \
errno = 0; \
e = test; \
if (e != -1) \
{ \
printf ("%s returned %d\n", #test, e); \
result = 1; \
} \
else if (errno != EINVAL) \
{ \
printf ("%s didn't set errno to EINVAL (%s instead)\n", \
#test, strerror (errno)); \
result = 1; \
}
RUN (sighold (-1));
RUN (sighold (_NSIG + 100));
RUN (sigrelse (-1));
RUN (sigrelse (_NSIG + 100));
return result;
}
示例4: twine_mutex_lock
void twine_mutex_lock(twine_mutex *lockVar) {
sighold(SIGALRM); // stop signals for atomic operation
while (lockVar->value) { // wait while lock is 1 (locked)
sigrelse(SIGALRM);
sighold(SIGALRM);
}
lockVar->value = 1; // 1 = locked
sigrelse(SIGALRM);
}
示例5: sighold
void semaphore::wait(void){
sighold(SIGALRM);
this->value -= 1;
if(this->value < 0){
getRunningThread()->state = BLOCKED;
this->waitQueue.push(getRunningThread());
sigrelse(SIGALRM);
raise(SIGALRM);
}
else{
sigrelse(SIGALRM);
}
}
示例6: sem_wait
/*
* Tries to gain access to a critical section.
* Will either continue, or be put in the semaphore's private queue
*/
void sem_wait(sem_t *s){
sighold(14);
if(s->count > 0){
s->count--;
sigrelse(14);
return;
}
/* Count is 0 */
sem_enq(s, running);
deq();
if(s->last)
swapcontext(s->last->thread_context, running->thread_context);
sigrelse(14);
}
示例7: cupsdReleaseSignals
void
cupsdReleaseSignals(void)
{
holdcount --;
if (holdcount > 0)
return;
#ifdef HAVE_SIGSET
sigrelse(SIGTERM);
sigrelse(SIGCHLD);
#elif defined(HAVE_SIGACTION)
sigprocmask(SIG_SETMASK, &holdmask, NULL);
#endif /* HAVE_SIGSET */
}
示例8: relsesigs
/*
* Release signals SIGHUP - SIGQUIT
*/
void
relsesigs(void)
{
#ifndef OLD_BSD_SIGS
if (--sigdepth == 0)
#ifdef VMUNIX
sigsetmask(omask);
#else
sigprocmask(SIG_SETMASK, &omask, NULL);
#endif
#else
sigrelse(SIGHUP);
sigrelse(SIGINT);
sigrelse(SIGQUIT);
#endif
}
示例9: semaphore_signal
/**
* Increments the value of the given semaphore.
* If the value was 0, then the thread at the top of the wait queue is put on the runqueue.
*/
void semaphore_signal(int semaphore) {
int next_thread;
// disable alarm while working with semaphore
sighold(SIGALRM);
#if DEBUG == 1
char print[100];
sprintf(print, "signaling semaphore %d with value %d\n", semaphore,
semaphores[semaphore]->value);
perror(print);
#endif
if (semaphores[semaphore]->value < 0) {
// make first thread on the wait queue RUNNABLE
next_thread = list_shift_int(semaphores[semaphore]->thread_queue);
if (next_thread == 0) {
perror("no threads on waitqueue\n");
exit(-1);
}
#if DEBUG == 1
sprintf(print, "signaling thread %d\n", next_thread);
perror(print);
#endif
threads[next_thread]->state = RUNNABLE;
list_append_int(runqueue, next_thread);
}
semaphores[semaphore]->value += 1;
sigrelse(SIGALRM);
}
示例10: umem_do_abort
/*
* We can't use abort(3C), since it closes all of the standard library
* FILEs, which can call free().
*
* In addition, we can't just raise(SIGABRT), since the current handler
* might do allocation. We give them once chance, though.
*/
static void __NORETURN
umem_do_abort(void)
{
#ifdef _WIN32
abort();
#else
if (firstexit(UMEM_EXIT_ABORT)) {
(void) raise(SIGABRT);
}
for (;;) {
#if defined(__FreeBSD__)
sigset_t set;
struct sigaction sa;
sa.sa_handler = SIG_DFL;
(void) sigaction(SIGABRT, &sa, NULL);
(void) sigemptyset (&set);
(void) sigaddset (&set, SIGABRT);
(void) sigprocmask (SIG_UNBLOCK, &set, NULL);
(void) raise (SIGABRT);
#else
(void) signal(SIGABRT, SIG_DFL);
#if !defined(ANDROID) && !defined(ROUTER) && !defined(ARM)
(void) sigrelse(SIGABRT);
#endif
(void) raise(SIGABRT);
#endif
}
#endif
}
示例11: pause_on_sigusr
void
pause_on_sigusr( int which )
{
#ifndef HAVE_DOSISH_SYSTEM
#ifdef HAVE_SIGPROCMASK
sigset_t mask, oldmask;
assert( which == 1 );
sigemptyset( &mask );
sigaddset( &mask, SIGUSR1 );
sigprocmask( SIG_BLOCK, &mask, &oldmask );
while( !caught_sigusr1 )
sigsuspend( &oldmask );
caught_sigusr1 = 0;
sigprocmask( SIG_UNBLOCK, &mask, NULL );
#else
assert (which == 1);
sighold (SIGUSR1);
while (!caught_sigusr1)
sigpause(SIGUSR1);
caught_sigusr1 = 0;
sigrelse(SIGUSR1); ????
#endif /*!HAVE_SIGPROCMASK*/
#endif
}
示例12: TEST
TEST(signal, sighold_sigpause_sigrelse) {
static int sigalrm_handler_call_count;
auto sigalrm_handler = [](int) { sigalrm_handler_call_count++; };
ScopedSignalHandler sigalrm{SIGALRM, sigalrm_handler};
ScopedSignalMask mask;
sigset_t set;
// sighold(SIGALRM) should add SIGALRM to the signal mask ...
ASSERT_EQ(0, sighold(SIGALRM));
ASSERT_EQ(0, sigprocmask(SIG_SETMASK, 0, &set));
EXPECT_TRUE(sigismember(&set, SIGALRM));
// ... preventing our SIGALRM handler from running ...
raise(SIGALRM);
ASSERT_EQ(0, sigalrm_handler_call_count);
// ... until sigpause(SIGALRM) temporarily unblocks it.
ASSERT_EQ(-1, sigpause(SIGALRM));
ASSERT_EQ(EINTR, errno);
ASSERT_EQ(1, sigalrm_handler_call_count);
// But sigpause(SIGALRM) shouldn't permanently unblock SIGALRM.
ASSERT_EQ(0, sigprocmask(SIG_SETMASK, 0, &set));
EXPECT_TRUE(sigismember(&set, SIGALRM));
ASSERT_EQ(0, sigrelse(SIGALRM));
ASSERT_EQ(0, sigprocmask(SIG_SETMASK, 0, &set));
EXPECT_FALSE(sigismember(&set, SIGALRM));
}
示例13: BIO_dump_cmd
/*
* Name: BIO_dump_cmd
* Description: Dump the output of invoking a command
* to a BIO.
*
* Arguments: cmd - Command to invoke
* bio - BIO to dump output of command to
* only 'stdout' is dumped.
* Returns : 0 - success
* nonzero - failure. errors printed to screen.
*/
int
BIO_dump_cmd(char *cmd, BIO *bio)
{
char buf[BLK_SIZE];
FILE *fp;
int rc;
/* start up the process */
if ((fp = epopen(cmd, "r")) == NULL) {
rpterr();
return (1);
}
/* read output in chunks, transfer to BIO */
while (fread(buf, BLK_SIZE, 1, fp) == 1) {
if (BIO_write(bio, buf, BLK_SIZE) != BLK_SIZE) {
(void) sighold(SIGINT);
(void) sighold(SIGHUP);
(void) epclose(fp);
(void) sigrelse(SIGINT);
(void) sigrelse(SIGHUP);
rpterr();
return (1);
}
}
/* done with stream, make sure no errors were encountered */
if (ferror(fp)) {
(void) epclose(fp);
rpterr();
return (1);
}
/* done, close stream, report any errors */
(void) sighold(SIGINT);
(void) sighold(SIGHUP);
rc = epclose(fp);
(void) sigrelse(SIGINT);
(void) sigrelse(SIGHUP);
if (rc != 0) {
rpterr();
return (1);
}
return (rc);
}
示例14: emulator_run
void emulator_run(struct emulator *emu)
{
cur_run_emu = emu;
sigset(SIGINT, sig_int_handler);
while (!emu->stop_prog)
emulator_run_next_inst(emu);
sigrelse(SIGINT);
}
示例15: sem_signal
/*
* Tells the other semaphores that the running thread is done with the critical section
* Removes the first waiting thread in the semaphore queue
*/
void sem_signal(sem_t *s){
sighold(14);
if(s->first == NULL || s->count > 0){
s->count++;
}else if(s->count <= 0){ /* There is a waiting thread, counter is 0 */
sem_deq(s);/* Add thread to ready queue */
}
sigrelse(14);
}