本文整理汇总了C++中sched_yield函数的典型用法代码示例。如果您正苦于以下问题:C++ sched_yield函数的具体用法?C++ sched_yield怎么用?C++ sched_yield使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sched_yield函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
//.........这里部分代码省略.........
开发者ID:lattera,项目名称:glibc,代码行数:101,代码来源:test-11.c
示例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()){
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:openimscore-svn,代码行数:101,代码来源:timer.c
示例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);
}
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:66,代码来源:stm.o.c
示例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;
}
}
//.........这里部分代码省略.........
开发者ID:1587,项目名称:ltp,代码行数:101,代码来源:2-2.c
示例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;
}
开发者ID:jgphpc,项目名称:OpenMP_MCA_Project,代码行数:72,代码来源:msg3.c
示例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;
}
开发者ID:ksuarz,项目名称:multithreading,代码行数:86,代码来源:bookorder.c
示例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;
}
开发者ID:LeqiaoP1,项目名称:ltp,代码行数:101,代码来源:mmstress.c
示例8: CmiYield
void CmiYield(void) { sched_yield(); }
开发者ID:luyukunphy,项目名称:namd,代码行数:1,代码来源:machine-smp.c
示例9: yield
static void yield() {sched_yield();};
开发者ID:andrewleech,项目名称:firebird,代码行数:1,代码来源:threadtest.cpp
示例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;
}
开发者ID:BlastTNG,项目名称:flight,代码行数:96,代码来源:fork-parent.c
示例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
}
开发者ID:Cheezzolo123,项目名称:MonteDroid,代码行数:101,代码来源:less.c
示例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;
}
开发者ID:dennis95,项目名称:dennix,代码行数:75,代码来源:signal.cpp
示例13: sched_yield
void SysThread::yield()
{
sched_yield();
}
开发者ID:KlemensEngel,项目名称:oorexxforandroid,代码行数:4,代码来源:SysThread.cpp
示例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);
}
开发者ID:sambatyon,项目名称:rtpproxy,代码行数:68,代码来源:rtpp_command.c
示例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(); }
}
开发者ID:chathhorn,项目名称:posixtestsuite,代码行数:7,代码来源:stress.c
示例16: yieldThread
void
yieldThread(void)
{
sched_yield();
return;
}
开发者ID:fryguybob,项目名称:ghc,代码行数:6,代码来源:OSThreads.c
示例17: main
/******
* Last but not least, the main function
*/
int main(int argc, char * argv[])
{
/* Main is responsible for :
* the mutex attributes initializing
* the creation of the cells
* the destruction of everything on SIGUSR1 reception
*/
int ret;
int i;
struct sigaction sa;
unsigned long long globopcnt=0, globsigcnt=0;
#ifndef WITHOUT_XOPEN
int sz = 2 + (sizeof(types) / sizeof(int));
#else
int sz = 2;
#endif
pthread_mutexattr_t ma[sz-1];
pthread_mutexattr_t *pma[sz];
cell_t data[sz * N * SCALABILITY_FACTOR];
pma[sz-1] = NULL;
#if VERBOSE > 0
output("Mutex lock / unlock stress sample is starting\n");
output("Kill with SIGUSR1 to stop the process\n");
output("\t kill -USR1 <pid>\n\n");
#endif
/* Initialize the mutex attributes */
for (i=0; i<sz-1; i++)
{
pma[i] = &ma[i];
ret = pthread_mutexattr_init(pma[i]);
if (ret != 0)
{ UNRESOLVED(ret, "Unable to init a mutex attribute object"); }
#ifndef WITHOUT_XOPEN /* we have the mutex attribute types */
if (i != 0)
{
ret = pthread_mutexattr_settype(pma[i], types[i-1]);
if (ret != 0)
{
UNRESOLVED(ret, "Unable to set type of a mutex attribute object");
}
}
#endif
}
#if VERBOSE > 1
output("%i mutex attribute objects were initialized\n", sz - 1);
#endif
/* Initialize the thread-local-data key */
ret = pthread_key_create(&_c, NULL);
if (ret != 0)
{ UNRESOLVED(ret, "Unable to initialize TLD key"); }
#if VERBOSE > 1
output("TLD key initialized\n");
#endif
/* Register the signal handler for SIGUSR1 */
sigemptyset (&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = globalsig;
if ((ret = sigaction (SIGUSR1, &sa, NULL)))
{ UNRESOLVED(ret, "Unable to register signal handler"); }
/* Register the signal handler for SIGUSR2 */
sa.sa_handler = sighdl;
if ((ret = sigaction (SIGUSR2, &sa, NULL)))
{ UNRESOLVED(ret, "Unable to register signal handler"); }
/* Start every threads */
#if VERBOSE > 0
output("%i cells of 10 threads are being created...\n", sz * N * SCALABILITY_FACTOR);
#endif
for (i=0; i< sz * N * SCALABILITY_FACTOR; i++)
cell_init(i, &data[i], pma[i % sz]);
#if VERBOSE > 0
output("All threads created and running.\n");
#endif
/* We stay here while not interrupted */
do { sched_yield(); }
while (do_it);
#if VERBOSE > 0
output("Starting to join the threads...\n");
#endif
/* Everybody is stopping, we must join them, and destroy the cell data */
for (i=0; i< sz * N * SCALABILITY_FACTOR; i++)
cell_fini(i, &data[i], &globopcnt, &globsigcnt);
/* Destroy the mutex attributes objects */
for (i=0; i<sz-1; i++)
{
//.........这里部分代码省略.........
开发者ID:chathhorn,项目名称:posixtestsuite,代码行数:101,代码来源:stress.c
示例18: TEST_BEGIN
void *POSIX_Init(
void *argument
)
{
struct timespec tr;
int status;
int priority;
pthread_t thread_id;
struct utsname uts;
TEST_BEGIN();
/* print some system information */
puts( "Init: uname - EFAULT (invalid uts pointer argument)" );
status = uname( NULL );
rtems_test_assert( status == -1 );
rtems_test_assert( errno == EFAULT );
status = uname( &uts );
rtems_test_assert( !status );
printf( "Init: uts.sysname: %s\n", uts.sysname );
printf( "Init: uts.nodename: %s\n", uts.nodename );
printf( "Init: uts.release: %s\n", uts.release );
printf( "Init: uts.version: %s\n", uts.version );
printf( "Init: uts.machine: %s\n", uts.machine );
puts("");
/* get id of this thread */
Init_id = pthread_self();
printf( "Init: ID is 0x%08" PRIxpthread_t "\n", Init_id );
/* exercise get minimum priority */
priority = sched_get_priority_min( SCHED_FIFO );
printf( "Init: sched_get_priority_min (SCHED_FIFO) -- %d\n", priority );
rtems_test_assert( priority != -1 );
puts( "Init: sched_get_priority_min -- EINVAL (invalid policy)" );
priority = sched_get_priority_min( -1 );
rtems_test_assert( priority == -1 );
rtems_test_assert( errno == EINVAL );
/* exercise get maximum priority */
priority = sched_get_priority_max( SCHED_FIFO );
printf( "Init: sched_get_priority_max (SCHED_FIFO) -- %d\n", priority );
rtems_test_assert( priority != -1 );
puts( "Init: sched_get_priority_max -- EINVAL (invalid policy)" );
priority = sched_get_priority_max( -1 );
rtems_test_assert( priority == -1 );
rtems_test_assert( errno == EINVAL );
puts( "Init: sched_rr_get_interval -- ESRCH (invalid PID)" );
status = sched_rr_get_interval( 4, &tr );
rtems_test_assert( status == -1 );
rtems_test_assert( errno == ESRCH );
puts( "Init: sched_rr_get_interval -- EINVAL (invalid interval pointer)" );
status = sched_rr_get_interval( getpid(), NULL );
rtems_test_assert( status == -1 );
rtems_test_assert( errno == EINVAL );
/* print the round robin time quantum */
status = sched_rr_get_interval( getpid(), &tr );
printf(
"Init: Round Robin quantum is %" PRIdtime_t " seconds, %ld nanoseconds\n",
tr.tv_sec,
tr.tv_nsec
);
rtems_test_assert( !status );
/* create a thread */
puts( "Init: pthread_create - SUCCESSFUL" );
status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
rtems_test_assert( !status );
/* too may threads error */
puts( "Init: pthread_create - EAGAIN (too many threads)" );
status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL );
rtems_test_assert( status == EAGAIN );
puts( "Init: sched_yield to Task_1" );
status = sched_yield();
rtems_test_assert( !status );
/* switch to Task_1 */
/* exit this thread */
puts( "Init: pthread_exit" );
pthread_exit( NULL );
/* switch to Task_1 */
//.........这里部分代码省略.........
开发者ID:AlexShiLucky,项目名称:rtems,代码行数:101,代码来源:init.c
示例19: __SwitchToThread
bool __SwitchToThread(uint32_t dwSleepMSec, uint32_t dwSwitchCount)
{
return sched_yield() == 0;
}
开发者ID:0-wiz-0,项目名称:coreclr,代码行数:4,代码来源:gcenv.unix.cpp
示例20: Debug_Yield
void
Debug_Yield(void)
{
unsigned int rand = rand_r(&randYieldSeed) % 100;
if (rand < yieldPercent) sched_yield();
}
开发者ID:JavierPalomares90,项目名称:CS110,代码行数:6,代码来源:debug.c
注:本文中的sched_yield函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论