本文整理汇总了C++中sched_yield函数的典型用法代码示例。如果您正苦于以下问题:C++ sched_yield函数的具体用法?C++ sched_yield怎么用?C++ sched_yield使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sched_yield函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int
main (int argc, char **argv)
{
error_t err;
pthread_rwlockattr_t attr;
pthread_rwlock_t lock;
int pshared;
int i;
pthread_t tid[THREADS];
void *ret;
err = pthread_rwlockattr_init (&attr);
if (err)
error (1, err, "pthread_rwlockattr_init");
err = pthread_rwlockattr_getpshared (&attr, &pshared);
if (err)
error (1, err, "pthread_rwlockattr_getpshared");
/* Assert the default state as mandated by POSIX. */
assert (pshared == PTHREAD_PROCESS_PRIVATE);
err = pthread_rwlockattr_setpshared (&attr, pshared);
if (err)
error (1, err, "pthread_rwlockattr_setpshared");
err = pthread_rwlock_init (&lock, &attr);
if (err)
error (1, err, "pthread_rwlock_init");
err = pthread_rwlockattr_destroy (&attr);
if (err)
error (1, err, "pthread_rwlockattr_destroy");
/* Now test the lock. */
for (i = 0; i < THREADS; i++)
{
err = pthread_create (&tid[i], 0, test1, &lock);
if (err)
error (1, err, "pthread_create");
}
for (i = 0; i < 10; i++)
{
sched_yield ();
/* Get a write lock. */
pthread_rwlock_wrlock (&lock);
/* Increment a and b giving other threads a chance to run in
between. */
sched_yield ();
a++;
sched_yield ();
b++;
sched_yield ();
/* Unlock. */
pthread_rwlock_unlock (&lock);
}
for (i = 0; i < THREADS; i++)
{
err = pthread_join (tid[i], &ret);
if (err)
error (1, err, "pthread_join");
}
/* Read lock it. */
err = pthread_rwlock_tryrdlock (&lock);
assert (err == 0);
/* Try to write lock it. It should fail with EBUSY. */
err = pthread_rwlock_trywrlock (&lock);
assert (err == EBUSY);
/* Drop the read lock. */
err = pthread_rwlock_unlock (&lock);
assert (err == 0);
/* Get a write lock. */
err = pthread_rwlock_trywrlock (&lock);
assert (err == 0);
/* Fail trying to acquire another write lock. */
err = pthread_rwlock_trywrlock (&lock);
assert (err == EBUSY);
/* Try to get a read lock which should also fail. */
err = pthread_rwlock_tryrdlock (&lock);
assert (err == EBUSY);
/* Unlock it. */
err = pthread_rwlock_unlock (&lock);
assert (err == 0);
err = pthread_rwlock_destroy (&lock);
if (err)
error (1, err, "pthread_rwlock_destroy");
//.........这里部分代码省略.........
示例2: timer_del_safe
void timer_del_safe(struct timer_ln* tl)
#endif
{
again:
/* quick exit if timer inactive */
if ( !(tl->flags & F_TIMER_ACTIVE)){
#ifdef TIMER_DEBUG
LOG(timerlog, "timer_del called on an inactive timer %p (%p, %p),"
" flags %x\n", tl, tl->next, tl->prev, tl->flags);
LOG(timerlog, "WARN: -timer_del-; called from %s(%s):%d\n",
func, file, line);
LOG(timerlog, "WARN: -timer_del-: added %d times"
", last from: %s(%s):%d, deleted %d times"
", last from: %s(%s):%d, init %d times, expired %d \n",
tl->add_calls, tl->add_func, tl->add_file, tl->add_line,
tl->del_calls, tl->del_func, tl->del_file, tl->del_line,
tl->init, tl->expires_no);
#else
DBG("timer_del called on an inactive timer %p (%p, %p),"
" flags %x\n", tl, tl->next, tl->prev, tl->flags);
#endif
return;
}
#ifdef USE_SLOW_TIMER
if (IS_ON_SLOW_LIST(tl) && (tl->slow_idx!=*t_idx)){
LOCK_SLOW_TIMER_LIST();
if (!IS_ON_SLOW_LIST(tl) || (tl->slow_idx==*t_idx)){
UNLOCK_SLOW_TIMER_LIST();
goto again;
}
if (IS_RUNNING_SLOW(tl)){
UNLOCK_SLOW_TIMER_LIST();
if (IS_IN_TIMER_SLOW()){
/* if somebody tries to shoot himself in the foot,
* warn him and ignore the delete */
LOG(L_CRIT, "BUG: timer handle %p (s) tried to delete"
" itself\n", tl);
#ifdef TIMER_DEBUG
LOG(timerlog, "WARN: -timer_del-: called from %s(%s):%d\n",
func, file, line);
LOG(timerlog, "WARN: -timer_del-: added %d times"
", last from: %s(%s):%d, deleted %d times"
", last from: %s(%s):%d, init %d times, expired %d \n",
tl->add_calls, tl->add_func, tl->add_file,
tl->add_line, tl->del_calls, tl->del_func,
tl->del_file, tl->del_line, tl->init, tl->expires_no);
#endif
return; /* do nothing */
}
sched_yield(); /* wait for it to complete */
goto again;
}
if (tl->next!=0){
_timer_rm_list(tl); /* detach */
tl->next=tl->prev=0;
#ifdef TIMER_DEBUG
tl->del_file=file;
tl->del_func=func;
tl->del_line=line;
tl->flags|=F_TIMER_DELETED;
#endif
}else{
#ifdef TIMER_DEBUG
LOG(timerlog, "timer_del: (s) timer %p (%p, %p) flags %x "
"already detached\n",
tl, tl->next, tl->prev, tl->flags);
LOG(timerlog, "WARN: -timer_del-: @%d tl=%p "
"{ %p, %p, %d, %d, %p, %p, %04x, -}\n", get_ticks_raw(),
tl, tl->next, tl->prev, tl->expire, tl->initial_timeout,
tl->data, tl->f, tl->flags);
LOG(timerlog, "WARN: -timer_del-; called from %s(%s):%d\n",
func, file, line);
LOG(timerlog, "WARN: -timer_del-: added %d times"
", last from: %s(%s):%d, deleted %d times"
", last from: %s(%s):%d, init %d times, expired %d \n",
tl->add_calls,
tl->add_func, tl->add_file, tl->add_line,
tl->del_calls,
tl->del_func, tl->del_file, tl->del_line,
tl->init, tl->expires_no);
#else
DBG("timer_del: (s) timer %p (%p, %p) flags %x "
"already detached\n",
tl, tl->next, tl->prev, tl->flags);
#endif
}
UNLOCK_SLOW_TIMER_LIST();
}else{
#endif
LOCK_TIMER_LIST();
#ifdef USE_SLOW_TIMER
if (IS_ON_SLOW_LIST(tl) && (tl->slow_idx!=*t_idx)){
UNLOCK_TIMER_LIST();
goto again;
}
#endif
if (IS_RUNNING(tl)){
UNLOCK_TIMER_LIST();
if (IS_IN_TIMER()){
//.........这里部分代码省略.........
示例3: stm_rollback
/*
* Rollback transaction.
*/
static inline void stm_rollback(stm_tx_t *tx, int reason)
{
w_entry_t *w;
int i;
PRINT_DEBUG("==> stm_rollback(%p[%lu-%lu])\n", tx, (unsigned long)tx->start, (unsigned long)tx->end);
assert(IS_ACTIVE(tx->status));
/* Drop locks */
i = tx->w_set.nb_entries;
if (i > 0) {
w = tx->w_set.entries;
for (; i > 0; i--, w++) {
if (w->next == NULL) {
/* Only drop lock for last covered address in write set */
ATOMIC_STORE(w->lock, LOCK_SET_TIMESTAMP(w->version));
}
}
/* Make sure that all lock releases become visible */
ATOMIC_MB_WRITE;
}
tx->retries++;
tx->aborts++;
if (tx->retries == 1)
tx->aborts_1++;
else if (tx->retries == 2)
tx->aborts_2++;
if (tx->max_retries < tx->retries)
tx->max_retries = tx->retries;
/* Callbacks */
if (nb_abort_cb != 0) {
int cb;
for (cb = 0; cb < nb_abort_cb; cb++)
abort_cb[cb].f(TXARGS abort_cb[cb].arg);
}
/* Set status to ABORTED */
SET_STATUS(tx->status, TX_ABORTED);
/* Reset nesting level */
tx->nesting = 1;
/* Wait until contented lock is free */
if (tx->c_lock != NULL) {
/* Busy waiting (yielding is expensive) */
while (LOCK_GET_OWNED(ATOMIC_LOAD(tx->c_lock))) {
sched_yield();
}
tx->c_lock = NULL;
}
/* Reset field to restart transaction */
stm_prepare(tx);
/* Jump back to transaction start */
if (tx->attr == NULL || !tx->attr->no_retry)
siglongjmp(tx->env, reason);
}
示例4: main
int main(void)
{
int child_count, i;
struct sched_param param;
int *child_pid;
float ratio;
/* Only use a single CPU and one child process
when set_affinity is availaible.It's because
no matter what value of the counter is set to,
There is no guarantee that the LOOP of the child
can be certainly big enough on any device at any time.
*/
int rc = set_affinity_single();
if (rc) {
nb_child = get_ncpu();
if (nb_child == -1) {
printf("Can not get the number of"
"CPUs of your machine.\n");
return PTS_UNRESOLVED;
}
} else {
nb_child = 1;
}
child_pid = malloc(nb_child * sizeof(int));
if (child_pid == NULL) {
printf("malloc failed\n");
return PTS_UNRESOLVED;
}
param.sched_priority = (sched_get_priority_min(SCHED_RR) +
sched_get_priority_max(SCHED_RR)) / 2;
if (sched_setscheduler(getpid(), SCHED_RR, ¶m) == -1) {
if (errno == EPERM) {
printf
("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root\n");
} else {
perror
("An error occurs when calling sched_setscheduler()");
}
return PTS_UNRESOLVED;
}
if (signal(SIGTERM, sigterm_handler) == SIG_ERR) {
perror("An error occurs when calling signal()");
return PTS_UNRESOLVED;
}
pipe(the_pipe);
for (i = 0; i < nb_child; i++) {
child_pid[i] = fork();
if (child_pid[i] == -1) {
perror("An error occurs when calling fork()");
return PTS_UNRESOLVED;
} else if (child_pid[i] == 0) {
child_process(i);
printf("This code should not be executed.\n");
return PTS_UNRESOLVED;
}
}
param.sched_priority = sched_get_priority_max(SCHED_RR);
if (sched_setparam(0, ¶m) != 0) {
perror("An error occurs when calling sched_setparam()");
return PTS_UNRESOLVED;
}
close(STDIN);
close(the_pipe[1]);
dup2(the_pipe[0], STDIN);
close(the_pipe[0]);
for (i = 0; i < NB_LOOP; i++) {
count++;
}
if (kill(child_pid[nb_child - 1], SIGTERM) != 0) {
perror("An error occurs when calling kill()");
return PTS_UNRESOLVED;
}
param.sched_priority = sched_get_priority_min(SCHED_RR);
if (sched_setparam(0, ¶m) != 0) {
perror("An error occurs when calling sched_setparam()");
return PTS_UNRESOLVED;
}
while (scanf("*%i*", &child_count) == 0)
sched_yield();
for (i = 0; i < (nb_child - 1); i++) {
if (kill(child_pid[i], SIGKILL) != 0) {
perror("An error occurs when calling kill()");
return PTS_UNRESOLVED;
}
}
//.........这里部分代码省略.........
示例5: mcapi_initialize
void *receiver(void* data)
{
char buffer[NUM_MSGS];
int count = 0;
size_t recv_size;
mca_status_t status;
int i;
mcapi_param_t parms;
mcapi_info_t version;
/* create a node */
mcapi_initialize(DOMAIN,NODE+1,NULL,&parms,&version,&status);
if (status != MCAPI_SUCCESS) {
fprintf(stderr,"\nFAIL: Failed to initialize: %s\n",mcapi_display_status(status,status_buff,sizeof(status_buff)));
WRONG;
}
/* make recv endpoint */
recv_endpt = mcapi_endpoint_create(1,&status);
if (status != MCAPI_SUCCESS) {
fprintf(stderr,"\nFAIL: Failed to create recv endpoint: %s\n",mcapi_display_status(status,status_buff,sizeof(status_buff)));
WRONG;
}
/* do the receives */
for (count = 0; count < NUM_MSGS; count++) {
mcapi_msg_recv(recv_endpt,
buffer,
sizeof(buffer),
&recv_size,
&status);
if ((status != MCAPI_SUCCESS) && (TIMEOUT)) {
/* yield and then retry */
for (i = 0; i < TIMEOUT; i++) {
if (status != MCAPI_SUCCESS) {
fprintf(stderr,"\nWARNING: Recv failed: reason:%s recv_count:%d. Will yield and re-try.\n",mcapi_display_status(status,status_buff,sizeof(status_buff)),count);
sched_yield();
mcapi_msg_recv(recv_endpt,
buffer,
sizeof(buffer),
&recv_size,
&status);
}
if (status == MCAPI_SUCCESS) {
break;
}
}
}
if (status == MCAPI_SUCCESS) {
printf("count=%d, Received: [%s]\n",count,buffer);
} else {
fprintf(stderr,"\nFAIL: Recv failed: reason:%s recv_count:%d.\n",mcapi_display_status(status,status_buff,sizeof(status_buff)),count);
WRONG;
}
}
/* finalize */
mcapi_finalize(&status);
if (status != MCAPI_SUCCESS) {
fprintf(stderr,"\nFAIL: Failed to finalize: %s\n",mcapi_display_status(status,status_buff,sizeof(status_buff)));
WRONG;
}
return NULL;
}
示例6: malloc
/**
* Code for the consumer threads. They take the orders and process them. The
* argument to this function should be a null-terminated string representing the
* category name for this thread.
*/
void *consumer_thread(void *args) {
char *category, *input;
customer_t *customer;
order_t *order;
receipt_t *receipt;
// Get the category for this thread.
input = (char *) args;
category = (char *) malloc(strlen(input) + 1);
strcpy(category, input);
while (!is_done || !queue_isempty(queue)) {
// We wait until there is something in the queue
pthread_mutex_lock(&queue->mutex);
if (!is_done && queue_isempty(queue)) {
pthread_cond_wait(&queue->nonempty, &queue->mutex);
}
if (is_done && queue_isempty(queue)) {
// No more orders to process. Exit this thread.
pthread_mutex_unlock(&queue->mutex);
return NULL;
}
else if (queue_isempty(queue)) {
// The queue is empty again.
pthread_mutex_unlock(&queue->mutex);
sched_yield();
continue;
}
order = (order_t *) queue_peek(queue);
if (strcmp(order->category, category) != 0) {
// This book is not in our category.
pthread_mutex_unlock(&queue->mutex);
sched_yield();
}
else {
// Process the order.
order = (order_t *) queue_dequeue(queue);
customer = database_retrieve_customer(customerDatabase,
order->customer_id);
if (!customer) {
// Invalid customer ID
fprintf(stderr, "There is no customer in the database with"
"customer ID %d.\n", order->customer_id);
}
else {
receipt = receipt_create(order->title,
order->price,
customer->credit_limit - order->price);
if (customer->credit_limit < order->price) {
// Insufficient funds.
printf("%s has insufficient funds for a purchase.\n"
"\tBook: %s\n\tRemaining credit: $%.2f\n\n",
customer->name,
order->title,
customer->credit_limit);
queue_enqueue(customer->failed_orders, receipt);
}
else {
// Subtract price from remaining credit
customer->credit_limit -= order->price;
printf("Customer %s has made a successful purchase!\n"
"\tBook: %s\n\tPrice: $%.2f\n"
"\tRemaining credit: $%.2f\n\n",
customer->name,
order->title,
order->price,
customer->credit_limit);
queue_enqueue(customer->successful_orders, receipt);
}
}
order_destroy(order);
pthread_mutex_unlock(&queue->mutex);
}
}
free(category);
return NULL;
}
示例7: thread_fault
//.........这里部分代码省略.........
map_addr);
fflush(NULL);
}
}
/* As long as wait is set to TRUE, the thread that will be created will */
/* loop in its exec routine */
wait_thread = TRUE;
/* Create a few threads, ideally number of threads equals number of CPU'S */
/* so that we can assume that each thread will run on a single CPU in */
/* of SMP machines. Currently we will create NR_CPUS number of threads. */
th_args[1] = (long)map_addr;
th_args[2] = pagesize;
th_args[3] = fault_type;
do {
th_args[0] = thrd_ndx;
th_args[4] = (long)0;
/*************************************************************/
/* The way it was, args could be overwritten by subsequent uses
* of it before the called routine had a chance to fully initialize.
* This flag stops the overwrite until that routine gets to
* begin. At that point, it is done initializing and it is
* safe for the this thread to continue (which will change
* args).
* A basic race condition.
*/
thread_begin = TRUE;
if (pthread_create(&pthread_ids[thrd_ndx++], NULL, exec_func,
(void *)&th_args)) {
perror("map_and_thread(): pthread_create()");
thread_begin = FALSE;
free(empty_buf);
fflush(NULL);
remove_files(tmpfile, map_addr);
close(fd);
retinfo->status = FAILED;
return retinfo;
} else {
/***************************************************/
/* Yield until new thread is done with args.
*/
while (thread_begin)
sched_yield();
}
} while (thrd_ndx < num_thread);
if (verbose_print)
tst_resm(TINFO, "map_and_thread(): pthread_create() success");
wait_thread = FALSE;
/* suspend the execution of the calling thread till the execution of the */
/* other thread has been terminated. */
for (thrd_ndx = 0; thrd_ndx < NUMTHREAD; thrd_ndx++) {
if (pthread_join(pthread_ids[thrd_ndx], &th_status)) {
perror("map_and_thread(): pthread_join()");
free(empty_buf);
fflush(NULL);
remove_files(tmpfile, map_addr);
close(fd);
retinfo->status = FAILED;
return retinfo;
} else {
if ((long)th_status == 1) {
tst_resm(TINFO,
"thread [%ld] - process exited with errors",
(long)pthread_ids[thrd_ndx]);
free(empty_buf);
remove_files(tmpfile, map_addr);
close(fd);
exit(1);
}
}
}
/* remove the temporary file that was created. - clean up */
/* but dont try to remove special files. */
/***********************************************/
/* Was if !(remove_files()) ...
* If that routine succeeds, it returns SUCCESS, which
* happens to be 0. So if the routine succeeded, the
* above condition would indicate failure. This change
* fixes that.
*/
if (remove_files(tmpfile, map_addr) == FAILED) {
free(empty_buf);
retinfo->status = FAILED;
return retinfo;
}
free(empty_buf);
close(fd);
retinfo->status = SUCCESS;
return retinfo;
}
示例8: CmiYield
void CmiYield(void) { sched_yield(); }
示例9: yield
static void yield() {sched_yield();};
示例10: fork_parent
int fork_parent()
{
int p[2];
pid_t pid;
char buffer[READ_BUFFER];
int rr, status, result;
if (pipe(p)) {
return -1;
}
fflush(stderr);
pid = fork();
if(pid < 0){
return -1;
}
if(pid == 0){ /* in child - make pipe stderr and detach from terminal */
close(p[0]);
if (p[1] != STDERR_FILENO) {
if (dup2(p[1], STDERR_FILENO) != STDERR_FILENO) {
exit(EX_OSERR);
}
close(p[1]);
}
close(STDOUT_FILENO);
close(STDIN_FILENO);
/* TODO: could point STDIN and STDOUT at /dev/null */
setsid();
return 0;
}
/* in parent - read from pipe, exit when pipe closes */
close(p[1]);
do {
rr = read(p[0], buffer, READ_BUFFER);
switch (rr) {
case -1:
switch (errno) {
case EAGAIN:
case EINTR:
rr = 1;
break;
default:
fprintf(stderr, "unable to read error messages: %s\n", strerror(errno));
fflush(stderr);
break;
}
break;
case 0:
/* eof */
break;
default:
write(STDERR_FILENO, buffer, rr);
/* don't care if write fails, can't do anything about it */
break;
}
} while (rr > 0);
sched_yield();
result = 0;
if (waitpid(pid, &status, WNOHANG) > 0) { /* got a child */
if (WIFEXITED(status)) {
result = WEXITSTATUS(status);
fprintf(stderr, "exited with code %d\n", result);
} else if (WIFSIGNALED(status)) {
fprintf(stderr, "killed by signal %d\n", WTERMSIG(status));
fflush(stderr);
result = EX_SOFTWARE;
#if 0
/* mimic child - problematic, it may ovewrite the child core file */
result = WTERMSIG(status);
raise(result);
#endif
#if 0
} else if (WIFSTOPPED(status)) { /* too clever by half */
result = WSTOPSIG(status);
fprintf(stderr, "stopped by signal %d, restarting with %d\n", result, SIGCONT);
kill(pid, SIGCONT);
result = 0;
#endif
}
}
/* else child probably ok */
exit(result);
/* not reached */
return -1;
}
示例11: read_lines
//.........这里部分代码省略.........
continue;
}
{
size_t new_last_line_pos = last_line_pos + 1;
if (c == '\t') {
new_last_line_pos += 7;
new_last_line_pos &= (~7);
}
if ((int)new_last_line_pos >= w)
break;
last_line_pos = new_last_line_pos;
}
/* ok, we will eat this char */
readpos++;
if (c == '\n') {
terminated = 1;
last_line_pos = 0;
break;
}
/* NUL is substituted by '\n'! */
if (c == '\0') c = '\n';
*p++ = c;
*p = '\0';
} /* end of "read chars until we have a line" loop */
/* Corner case: linewrap with only "" wrapping to next line */
/* Looks ugly on screen, so we do not store this empty line */
if (!last_terminated && !current_line[0]) {
last_terminated = 1;
max_lineno++;
continue;
}
reached_eof:
last_terminated = terminated;
flines = xrealloc_vector(flines, 8, max_fline);
flines[max_fline] = (char*)xrealloc(MEMPTR(current_line), strlen(current_line) + 1 + 4) + 4;
LINENO(flines[max_fline]) = max_lineno;
if (terminated)
max_lineno++;
if (max_fline >= MAXLINES) {
eof_error = 0; /* Pretend we saw EOF */
break;
}
if (!(option_mask32 & FLAG_S)
? (max_fline > cur_fline + max_displayed_line)
: (max_fline >= cur_fline
&& max_lineno > LINENO(flines[cur_fline]) + max_displayed_line)
) {
#if !ENABLE_FEATURE_LESS_REGEXP
break;
#else
if (wanted_match >= num_matches) { /* goto_match called us */
fill_match_lines(old_max_fline);
old_max_fline = max_fline;
}
if (wanted_match < num_matches)
break;
#endif
}
if (eof_error <= 0) {
if (eof_error < 0) {
if (errno == EAGAIN) {
/* not yet eof or error, reset flag (or else
* we will hog CPU - select() will return
* immediately */
eof_error = 1;
} else {
print_statusline("read error");
}
}
#if !ENABLE_FEATURE_LESS_REGEXP
break;
#else
if (wanted_match < num_matches) {
break;
} else { /* goto_match called us */
time_t t = time(NULL);
if (t != last_time) {
last_time = t;
if (--seconds_p1 == 0)
break;
}
sched_yield();
goto again0; /* go loop again (max 2 seconds) */
}
#endif
}
max_fline++;
current_line = ((char*)xmalloc(w + 4)) + 4;
p = current_line;
last_line_pos = 0;
} /* end of "read lines until we reach cur_fline" loop */
fill_match_lines(old_max_fline);
#if ENABLE_FEATURE_LESS_REGEXP
/* prevent us from being stuck in search for a match */
wanted_match = -1;
#endif
#undef readbuf
}
示例12: kthread_mutex_lock
InterruptContext* Thread::handleSignal(InterruptContext* context) {
kthread_mutex_lock(&signalMutex);
assert(pendingSignals);
assert(signalPending);
// Choose the next unblocked pending signal.
PendingSignal* pending;
if (!sigismember(&signalMask, pendingSignals->siginfo.si_signo)) {
pending = pendingSignals;
pendingSignals = pending->next;
} else {
PendingSignal* currentSignal = pendingSignals;
while (currentSignal->next && sigismember(&signalMask,
currentSignal->next->siginfo.si_signo)) {
currentSignal = currentSignal->next;
}
assert(currentSignal->next);
pending = currentSignal->next;
currentSignal->next = pending->next;
}
siginfo_t siginfo = pending->siginfo;
delete pending;
updatePendingSignals();
kthread_mutex_unlock(&signalMutex);
struct sigaction action = process->sigactions[siginfo.si_signo];
assert(!(action.sa_handler == SIG_IGN || (action.sa_handler == SIG_DFL &&
sigismember(&defaultIgnoredSignals, siginfo.si_signo))));
if (action.sa_handler == SIG_DFL) {
process->terminateBySignal(siginfo);
sched_yield();
__builtin_unreachable();
}
uintptr_t frameAddress = (context->STACK_POINTER - sizeof(SignalStackFrame))
& ~0xF;
SignalStackFrame* frame = (SignalStackFrame*) frameAddress;
frame->siginfo = siginfo;
frame->ucontext.uc_link = nullptr;
frame->ucontext.uc_sigmask = signalMask;
frame->ucontext.uc_stack.ss_sp = nullptr;
frame->ucontext.uc_stack.ss_size = 0;
frame->ucontext.uc_stack.ss_flags = SS_DISABLE;
Registers::save(context, &frame->ucontext.uc_mcontext.__regs);
Registers::saveFpu(&frame->ucontext.uc_mcontext.__fpuEnv);
#ifdef __i386__
frame->signoParam = siginfo.si_signo;
frame->infoParam = &frame->siginfo;
frame->contextParam = &frame->ucontext;
context->eflags &= ~0x400; // Direction Flag
#elif defined(__x86_64__)
context->rdi = siginfo.si_signo;
context->rsi = (uintptr_t) &frame->siginfo;
context->rdx = (uintptr_t) &frame->ucontext;
context->rflags &= ~0x400; // Direction Flag
#else
# error "Signal handler parameters are unimplemented for this architecture."
#endif
uintptr_t* sigreturnPointer = (uintptr_t*) frameAddress - 1;
*sigreturnPointer = process->sigreturn;
context->INSTRUCTION_POINTER = (uintptr_t) action.sa_sigaction;
context->STACK_POINTER = (uintptr_t) sigreturnPointer;
signalMask |= action.sa_mask | _SIGSET(siginfo.si_signo);
return context;
}
示例13: sched_yield
void SysThread::yield()
{
sched_yield();
}
示例14: get_command
int
get_command(struct cfg_stable *cfs, int controlfd, struct rtpp_command *cmd)
{
char **ap;
char *cp;
int len, i;
if (cfs->umode == 0) {
for (;;) {
len = read(controlfd, cmd->buf, sizeof(cmd->buf) - 1);
if (len != -1 || (errno != EAGAIN && errno != EINTR))
break;
sched_yield();
}
} else {
cmd->rlen = sizeof(cmd->raddr);
len = recvfrom(controlfd, cmd->buf, sizeof(cmd->buf) - 1, 0,
sstosa(&cmd->raddr), &cmd->rlen);
}
if (len == -1) {
if (errno != EAGAIN && errno != EINTR)
rtpp_log_ewrite(RTPP_LOG_ERR, cfs->glog, "can't read from control socket");
return (-1);
}
cmd->buf[len] = '\0';
rtpp_log_write(RTPP_LOG_DBUG, cfs->glog, "received command \"%s\"", cmd->buf);
cp = cmd->buf;
cmd->argc = 0;
memset(cmd->argv, 0, sizeof(cmd->argv));
for (ap = cmd->argv; (*ap = rtpp_strsep(&cp, "\r\n\t ")) != NULL;)
if (**ap != '\0') {
cmd->argc++;
if (++ap >= &cmd->argv[10])
break;
}
cmd->cookie = NULL;
if (cmd->argc < 1 || (cfs->umode != 0 && cmd->argc < 2)) {
rtpp_log_write(RTPP_LOG_ERR, cfs->glog, "command syntax error");
reply_error(cfs, controlfd, cmd, 0);
return (0);
}
/* Stream communication mode doesn't use cookie */
if (cfs->umode != 0) {
cmd->cookie = cmd->argv[0];
for (i = 1; i < cmd->argc; i++)
cmd->argv[i - 1] = cmd->argv[i];
cmd->argc--;
cmd->argv[cmd->argc] = NULL;
} else {
cmd->cookie = NULL;
}
return (cmd->argc);
}
示例15: waitsigend
/***** The next function can return only when the sigthr has terminated.
* This avoids the signal thread try to kill a terminated thread. */
void waitsigend(cell_t * c)
{
while ( c->sigok == 0 )
{ sched_yield(); }
}