本文整理汇总了C++中pthread_attr_setschedparam函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_attr_setschedparam函数的具体用法?C++ pthread_attr_setschedparam怎么用?C++ pthread_attr_setschedparam使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_attr_setschedparam函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: cond_test
void cond_test(void)
{
pthread_t waiter;
pthread_t signaler;
pthread_attr_t attr;
#ifdef SDCC
pthread_addr_t result;
#endif
struct sched_param sparam;
int prio_min;
int prio_max;
int prio_mid;
int status;
/* Initialize the mutex */
printf("cond_test: Initializing mutex\n");
status = pthread_mutex_init(&mutex, NULL);
if (status != 0)
{
printf("cond_test: ERROR pthread_mutex_init failed, status=%d\n", status);
}
/* Initialize the condition variable */
printf("cond_test: Initializing cond\n");
status = pthread_cond_init(&cond, NULL);
if (status != 0)
{
printf("cond_test: ERROR pthread_condinit failed, status=%d\n", status);
}
/* Start the waiter thread at higher priority */
printf("cond_test: Starting waiter\n");
status = pthread_attr_init(&attr);
if (status != 0)
{
printf("cond_test: pthread_attr_init failed, status=%d\n", status);
}
prio_min = sched_get_priority_min(SCHED_FIFO);
prio_max = sched_get_priority_max(SCHED_FIFO);
prio_mid = (prio_min + prio_max) / 2;
sparam.sched_priority = prio_mid;
status = pthread_attr_setschedparam(&attr,&sparam);
if (status != OK)
{
printf("cond_test: pthread_attr_setschedparam failed, status=%d\n", status);
}
else
{
printf("cond_test: Set thread 1 priority to %d\n", sparam.sched_priority);
}
status = pthread_create(&waiter, &attr, thread_waiter, NULL);
if (status != 0)
{
printf("cond_test: pthread_create failed, status=%d\n", status);
}
printf("cond_test: Starting signaler\n");
status = pthread_attr_init(&attr);
if (status != 0)
{
printf("cond_test: pthread_attr_init failed, status=%d\n", status);
}
sparam.sched_priority = (prio_min + prio_mid) / 2;
status = pthread_attr_setschedparam(&attr,&sparam);
if (status != OK)
{
printf("cond_test: pthread_attr_setschedparam failed, status=%d\n", status);
}
else
{
printf("cond_test: Set thread 2 priority to %d\n", sparam.sched_priority);
}
status = pthread_create(&signaler, &attr, thread_signaler, NULL);
if (status != 0)
{
printf("cond_test: pthread_create failed, status=%d\n", status);
}
/* Wait for the threads to stop */
#ifdef SDCC
pthread_join(signaler, &result);
#else
pthread_join(signaler, NULL);
#endif
printf("cond_test: signaler terminated, now cancel the waiter\n");
pthread_detach(waiter);
pthread_cancel(waiter);
printf("cond_test: \tWaiter\tSignaler\n");
printf("cond_test: Loops\t%d\t%d\n", waiter_nloops, signaler_nloops);
printf("cond_test: Errors\t%d\t%d\n", waiter_nerrors, signaler_nerrors);
//.........这里部分代码省略.........
开发者ID:CompagnieDesLampadaires,项目名称:terrarium_2015,代码行数:101,代码来源:cond.c
示例2: WXUNUSED
wxThreadError wxThread::Create(unsigned int WXUNUSED(stackSize))
{
if ( m_internal->GetState() != STATE_NEW )
{
// don't recreate thread
return wxTHREAD_RUNNING;
}
// set up the thread attribute: right now, we only set thread priority
pthread_attr_t attr;
pthread_attr_init(&attr);
#ifdef HAVE_THREAD_PRIORITY_FUNCTIONS
int policy;
if ( pthread_attr_getschedpolicy(&attr, &policy) != 0 )
{
wxLogError(_("Cannot retrieve thread scheduling policy."));
}
#ifdef __VMS__
/* the pthread.h contains too many spaces. This is a work-around */
# undef sched_get_priority_max
#undef sched_get_priority_min
#define sched_get_priority_max(_pol_) \
(_pol_ == SCHED_OTHER ? PRI_FG_MAX_NP : PRI_FIFO_MAX)
#define sched_get_priority_min(_pol_) \
(_pol_ == SCHED_OTHER ? PRI_FG_MIN_NP : PRI_FIFO_MIN)
#endif
int max_prio = sched_get_priority_max(policy),
min_prio = sched_get_priority_min(policy),
prio = m_internal->GetPriority();
if ( min_prio == -1 || max_prio == -1 )
{
wxLogError(_("Cannot get priority range for scheduling policy %d."),
policy);
}
else if ( max_prio == min_prio )
{
if ( prio != WXTHREAD_DEFAULT_PRIORITY )
{
// notify the programmer that this doesn't work here
wxLogWarning(_("Thread priority setting is ignored."));
}
//else: we have default priority, so don't complain
// anyhow, don't do anything because priority is just ignored
}
else
{
struct sched_param sp;
if ( pthread_attr_getschedparam(&attr, &sp) != 0 )
{
wxFAIL_MSG(_T("pthread_attr_getschedparam() failed"));
}
sp.sched_priority = min_prio + (prio*(max_prio - min_prio))/100;
if ( pthread_attr_setschedparam(&attr, &sp) != 0 )
{
wxFAIL_MSG(_T("pthread_attr_setschedparam(priority) failed"));
}
}
#endif // HAVE_THREAD_PRIORITY_FUNCTIONS
#ifdef HAVE_PTHREAD_ATTR_SETSCOPE
// this will make the threads created by this process really concurrent
if ( pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM) != 0 )
{
wxFAIL_MSG(_T("pthread_attr_setscope(PTHREAD_SCOPE_SYSTEM) failed"));
}
#endif // HAVE_PTHREAD_ATTR_SETSCOPE
// VZ: assume that this one is always available (it's rather fundamental),
// if this function is ever missing we should try to use
// pthread_detach() instead (after thread creation)
if ( m_isDetached )
{
if ( pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0 )
{
wxFAIL_MSG(_T("pthread_attr_setdetachstate(DETACHED) failed"));
}
// never try to join detached threads
m_internal->Detach();
}
//else: threads are created joinable by default, it's ok
// create the new OS thread object
int rc = pthread_create
(
m_internal->GetIdPtr(),
&attr,
wxPthreadStart,
(void *)this
);
if ( pthread_attr_destroy(&attr) != 0 )
{
//.........这里部分代码省略.........
开发者ID:project-renard-survey,项目名称:chandler,代码行数:101,代码来源:threadpsx.cpp
示例3: nxtext_muinitialize
static inline int nxtext_muinitialize(void)
{
struct sched_param param;
pthread_t thread;
pid_t servrid;
int ret;
/* Set the client task priority */
param.sched_priority = CONFIG_EXAMPLES_NXTEXT_CLIENTPRIO;
ret = sched_setparam(0, ¶m);
if (ret < 0)
{
printf("nxtext_initialize: sched_setparam failed: %d\n" , ret);
g_exitcode = NXEXIT_SCHEDSETPARAM;
return ERROR;
}
/* Start the server task */
printf("nxtext_initialize: Starting nxtext_server task\n");
servrid = task_create("NX Server", CONFIG_EXAMPLES_NXTEXT_SERVERPRIO,
CONFIG_EXAMPLES_NXTEXT_STACKSIZE, nxtext_server, NULL);
if (servrid < 0)
{
printf("nxtext_initialize: Failed to create nxtext_server task: %d\n", errno);
g_exitcode = NXEXIT_TASKCREATE;
return ERROR;
}
/* Wait a bit to let the server get started */
sleep(1);
/* Connect to the server */
g_hnx = nx_connect();
if (g_hnx)
{
pthread_attr_t attr;
/* Start a separate thread to listen for server events. This is probably
* the least efficient way to do this, but it makes this example flow more
* smoothly.
*/
(void)pthread_attr_init(&attr);
param.sched_priority = CONFIG_EXAMPLES_NXTEXT_LISTENERPRIO;
(void)pthread_attr_setschedparam(&attr, ¶m);
(void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NXTEXT_STACKSIZE);
ret = pthread_create(&thread, &attr, nxtext_listener, NULL);
if (ret != 0)
{
printf("nxtext_initialize: pthread_create failed: %d\n", ret);
g_exitcode = NXEXIT_PTHREADCREATE;
return ERROR;
}
/* Don't return until we are connected to the server */
while (!g_connected)
{
/* Wait for the listener thread to wake us up when we really
* are connected.
*/
(void)sem_wait(&g_semevent);
}
}
else
{
printf("nxtext_initialize: nx_connect failed: %d\n", errno);
g_exitcode = NXEXIT_NXCONNECT;
return ERROR;
}
return OK;
}
开发者ID:JforGitHub,项目名称:thingsee-sdk,代码行数:78,代码来源:nxtext_main.c
示例4: main
int main (int ac, char **av)
{
int err;
char *cp, *progname = (char*)basename(av[0]), *rtdm_driver;
struct sched_param param_square = {.sched_priority = 99 };
struct sched_param param_irq = {.sched_priority = 98 };
pthread_attr_t thattr_square, thattr_irq;
period_ns = PERIOD; /* ns */
signal(SIGINT, cleanup_upon_sig);
signal(SIGTERM, cleanup_upon_sig);
signal(SIGHUP, cleanup_upon_sig);
signal(SIGALRM, cleanup_upon_sig);
while (--ac) {
if ((cp = *++av) == NULL)
break;
if (*cp == '-' && *++cp) {
switch(*cp) {
case 'p' :
period_ns = (unsigned long)atoi(*++av);
break;
case 'r' :
rtdm_driver = *++av;
break;
default:
usage(progname);
break;
}
}
else
break;
}
// Display every 2 sec
loop_prt = 2000000000 / period_ns;
printf ("Using driver \"%s\" and period %d ns\n", rtdm_driver, period_ns);
// Avoid paging: MANDATORY for RT !!
mlockall(MCL_CURRENT|MCL_FUTURE);
// Init rt_printf() system
rt_print_auto_init(1);
// Open RTDM driver
if ((fd = rt_dev_open(rtdm_driver, 0)) < 0) {
perror("rt_open");
exit(EXIT_FAILURE);
}
// Thread attributes
pthread_attr_init(&thattr_square);
// Joinable
pthread_attr_setdetachstate(&thattr_square, PTHREAD_CREATE_JOINABLE);
// Priority, set priority to 99
pthread_attr_setinheritsched(&thattr_square, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&thattr_square, SCHED_FIFO);
pthread_attr_setschedparam(&thattr_square, ¶m_square);
// Create thread(s)
err = pthread_create(&thid_square, &thattr_square, &thread_square, NULL);
if (err)
{
fprintf(stderr,"square: failed to create square thread, code %d\n",err);
return 0;
}
// Thread attributes
pthread_attr_init(&thattr_irq);
// Priority, set priority to 98
pthread_attr_setinheritsched(&thattr_irq, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&thattr_irq, SCHED_FIFO);
pthread_attr_setschedparam(&thattr_irq, ¶m_irq);
err = pthread_create(&thid_irq, &thattr_irq, &thread_irq, NULL);
if (err)
{
fprintf(stderr,"square: failed to create IRQ thread, code %d\n",err);
return 0;
}
pause();
return 0;
}
开发者ID:pficheux,项目名称:raspberry_pi,代码行数:94,代码来源:xenomai_rpi_rtdm_gpio.c
示例5: nsh_parse
//.........这里部分代码省略.........
nsh_release(bkgvtbl);
goto errout;
}
/* Determine the priority to execute the command */
if (vtbl->np.np_nice != 0)
{
int priority = param.sched_priority - vtbl->np.np_nice;
if (vtbl->np.np_nice < 0)
{
int max_priority = sched_get_priority_max(SCHED_NSH);
if (priority > max_priority)
{
priority = max_priority;
}
}
else
{
int min_priority = sched_get_priority_min(SCHED_NSH);
if (priority < min_priority)
{
priority = min_priority;
}
}
param.sched_priority = priority;
}
/* Set up the thread attributes */
(void)pthread_attr_init(&attr);
(void)pthread_attr_setschedpolicy(&attr, SCHED_NSH);
(void)pthread_attr_setschedparam(&attr, ¶m);
/* Execute the command as a separate thread at the appropriate priority */
ret = pthread_create(&thread, &attr, nsh_child, (pthread_addr_t)args);
if (ret != 0)
{
nsh_output(vtbl, g_fmtcmdfailed, cmd, "pthread_create", NSH_ERRNO_OF(ret));
nsh_releaseargs(args);
nsh_release(bkgvtbl);
goto errout;
}
nsh_output(vtbl, "%s [%d:%d]\n", cmd, thread, param.sched_priority);
}
else
#endif
{
uint8_t save[SAVE_SIZE];
/* Handle redirection of output via a file descriptor */
if (vtbl->np.np_redirect)
{
nsh_redirect(vtbl, fd, save);
}
/* Then execute the command in "foreground" -- i.e., while the user waits
* for the next prompt. nsh_execute will return:
*
* -1 (ERRROR) if the command was unsuccessful
* 0 (OK) if the command was successful
*/
开发者ID:NikiRegina,项目名称:Firmware,代码行数:67,代码来源:nsh_parse.c
示例6: PaUnixThread_New
PaError PaUnixThread_New( PaUnixThread* self, void* (*threadFunc)( void* ), void* threadArg, PaTime waitForChild,
int rtSched )
{
PaError result = paNoError;
pthread_attr_t attr;
int started = 0;
memset( self, 0, sizeof (PaUnixThread) );
PaUnixMutex_Initialize( &self->mtx );
PA_ASSERT_CALL( pthread_cond_init( &self->cond, NULL ), 0 );
self->parentWaiting = 0 != waitForChild;
/* Spawn thread */
/* Temporarily disabled since we should test during configuration for presence of required mman.h header */
#if 0
#if defined _POSIX_MEMLOCK && (_POSIX_MEMLOCK != -1)
if( rtSched )
{
if( mlockall( MCL_CURRENT | MCL_FUTURE ) < 0 )
{
int savedErrno = errno; /* In case errno gets overwritten */
assert( savedErrno != EINVAL ); /* Most likely a programmer error */
PA_UNLESS( (savedErrno == EPERM), paInternalError );
PA_DEBUG(( "%s: Failed locking memory\n", __FUNCTION__ ));
}
else
PA_DEBUG(( "%s: Successfully locked memory\n", __FUNCTION__ ));
}
#endif
#endif
PA_UNLESS( !pthread_attr_init( &attr ), paInternalError );
/* Priority relative to other processes */
PA_UNLESS( !pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM ), paInternalError );
PA_UNLESS( !pthread_create( &self->thread, &attr, threadFunc, threadArg ), paInternalError );
started = 1;
if( rtSched )
{
#if 0
if( self->useWatchdog )
{
int err;
struct sched_param wdSpm = { 0 };
/* Launch watchdog, watchdog sets callback thread priority */
int prio = PA_MIN( self->rtPrio + 4, sched_get_priority_max( SCHED_FIFO ) );
wdSpm.sched_priority = prio;
PA_UNLESS( !pthread_attr_init( &attr ), paInternalError );
PA_UNLESS( !pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED ), paInternalError );
PA_UNLESS( !pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM ), paInternalError );
PA_UNLESS( !pthread_attr_setschedpolicy( &attr, SCHED_FIFO ), paInternalError );
PA_UNLESS( !pthread_attr_setschedparam( &attr, &wdSpm ), paInternalError );
if( (err = pthread_create( &self->watchdogThread, &attr, &WatchdogFunc, self )) )
{
PA_UNLESS( err == EPERM, paInternalError );
/* Permission error, go on without realtime privileges */
PA_DEBUG(( "Failed bumping priority\n" ));
}
else
{
int policy;
self->watchdogRunning = 1;
PA_ENSURE_SYSTEM( pthread_getschedparam( self->watchdogThread, &policy, &wdSpm ), 0 );
/* Check if priority is right, policy could potentially differ from SCHED_FIFO (but that's alright) */
if( wdSpm.sched_priority != prio )
{
PA_DEBUG(( "Watchdog priority not set correctly (%d)\n", wdSpm.sched_priority ));
PA_ENSURE( paInternalError );
}
}
}
else
#endif
PA_ENSURE( BoostPriority( self ) );
{
int policy;
struct sched_param spm;
pthread_getschedparam(self->thread, &policy, &spm);
}
}
if( self->parentWaiting )
{
PaTime till;
struct timespec ts;
int res = 0;
PaTime now;
PA_ENSURE( PaUnixMutex_Lock( &self->mtx ) );
/* Wait for stream to be started */
now = PaUtil_GetTime();
till = now + waitForChild;
while( self->parentWaiting && !res )
//.........这里部分代码省略.........
开发者ID:jinhoou,项目名称:kaden_voice,代码行数:101,代码来源:pa_unix_util.c
示例7: soundio_os_thread_create
int soundio_os_thread_create(
void (*run)(void *arg), void *arg,
void (*emit_rtprio_warning)(void),
struct SoundIoOsThread ** out_thread)
{
*out_thread = NULL;
struct SoundIoOsThread *thread = ALLOCATE(struct SoundIoOsThread, 1);
if (!thread) {
soundio_os_thread_destroy(thread);
return SoundIoErrorNoMem;
}
thread->run = run;
thread->arg = arg;
#if defined(SOUNDIO_OS_WINDOWS)
thread->handle = CreateThread(NULL, 0, run_win32_thread, thread, 0, &thread->id);
if (!thread->handle) {
soundio_os_thread_destroy(thread);
return SoundIoErrorSystemResources;
}
if (emit_rtprio_warning) {
if (!SetThreadPriority(thread->handle, THREAD_PRIORITY_TIME_CRITICAL)) {
emit_rtprio_warning();
}
}
#else
int err;
if ((err = pthread_attr_init(&thread->attr))) {
soundio_os_thread_destroy(thread);
return SoundIoErrorNoMem;
}
thread->attr_init = true;
if (emit_rtprio_warning) {
int max_priority = sched_get_priority_max(SCHED_FIFO);
if (max_priority == -1) {
soundio_os_thread_destroy(thread);
return SoundIoErrorSystemResources;
}
if ((err = pthread_attr_setschedpolicy(&thread->attr, SCHED_FIFO))) {
soundio_os_thread_destroy(thread);
return SoundIoErrorSystemResources;
}
struct sched_param param;
param.sched_priority = max_priority;
if ((err = pthread_attr_setschedparam(&thread->attr, ¶m))) {
soundio_os_thread_destroy(thread);
return SoundIoErrorSystemResources;
}
}
if ((err = pthread_create(&thread->id, &thread->attr, run_pthread, thread))) {
if (err == EPERM && emit_rtprio_warning) {
emit_rtprio_warning();
err = pthread_create(&thread->id, NULL, run_pthread, thread);
}
if (err) {
soundio_os_thread_destroy(thread);
return SoundIoErrorNoMem;
}
}
thread->running = true;
#endif
*out_thread = thread;
return 0;
}
开发者ID:IceDragon200,项目名称:libsoundio,代码行数:72,代码来源:os.c
示例8: ModuleResize
//.........这里部分代码省略.........
cleanup(EXIT_FAILURE);
}
/* Set the thread to be fifo real time scheduled */
if(pthread_attr_setschedpolicy(&attr, SCHED_FIFO)) {
ERR("Failed to set FIFO scheduling policy\n");
cleanup(EXIT_FAILURE);
}
/* Create the capture fifos */
captureEnv.to_video_c = Fifo_create(&fAttrs);
captureEnv.from_video_c = Fifo_create(&fAttrs);
captureEnv.to_resize_c = Fifo_create(&fAttrs);
captureEnv.from_resize_c = Fifo_create(&fAttrs);
if(captureEnv.to_video_c == NULL || captureEnv.from_video_c == NULL ||
captureEnv.to_resize_c == NULL || captureEnv.from_resize_c == NULL) {
ERR("Failed to open display fifos\n");
cleanup(EXIT_FAILURE);
}
LowRateResize.to_videoresize_c = Fifo_create(&fAttrs);
LowRateResize.from_videoresize_c = Fifo_create(&fAttrs);
if(LowRateResize.to_videoresize_c == NULL || LowRateResize.from_videoresize_c == NULL) {
ERR("Failed to open Resize fifos\n");
cleanup(EXIT_FAILURE);
}
/* Set the capture thread priority */
schedParam.sched_priority = CAPTURE_THREAD_PRIORITY;
if(pthread_attr_setschedparam(&attr, &schedParam)) {
ERR("Failed to set scheduler parameters\n");
cleanup(EXIT_FAILURE);
}
/* Create the capture thread */
captureEnv.hRendezvousInit = hRendezvousInit;
captureEnv.hRendezvousCleanup = hRendezvousCleanup;
DEBUG(DL_DEBUG, "captureThrFxn thread!!!!\n");
if(pthread_create(&captureThread, &attr, captureThrFxn, &captureEnv)) {
ERR("Failed to create capture thread\n");
cleanup(EXIT_FAILURE);
}
/* Create the writer fifos */
writerEnv.to_video_c = Fifo_create(&fAttrs);
writerEnv.from_video_c = Fifo_create(&fAttrs);
writerLowRateEnv.to_writelow_c = Fifo_create(&fAttrs);
writerLowRateEnv.from_writelow_c = Fifo_create(&fAttrs);
if(writerEnv.to_video_c == NULL || writerEnv.from_video_c == NULL ||
writerLowRateEnv.to_writelow_c == NULL || writerLowRateEnv.from_writelow_c == NULL) {
ERR("Failed to open display fifos\n");
cleanup(EXIT_FAILURE);
}
initMask |= CAPTURETHREADCREATED ;
/*detect thread*/
detectEnv.hRendezvousInit = hRendezvousInit;
detectEnv.hRendezvousCleanup = hRendezvousCleanup;
开发者ID:Lichanglu,项目名称:ENC-1260,代码行数:66,代码来源:main.c
示例9: px4_task_spawn_cmd
//.........这里部分代码省略.........
if (stack_size < PTHREAD_STACK_MIN) {
stack_size = PTHREAD_STACK_MIN;
}
rv = pthread_attr_setstacksize(&attr, PX4_STACK_ADJUSTED(stack_size));
if (rv != 0) {
PX4_ERR("pthread_attr_setstacksize to %d returned error (%d)", stack_size, rv);
pthread_attr_destroy(&attr);
free(taskdata);
return (rv < 0) ? rv : -rv;
}
#endif
rv = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
if (rv != 0) {
PX4_ERR("px4_task_spawn_cmd: failed to set inherit sched");
pthread_attr_destroy(&attr);
free(taskdata);
return (rv < 0) ? rv : -rv;
}
rv = pthread_attr_setschedpolicy(&attr, scheduler);
if (rv != 0) {
PX4_ERR("px4_task_spawn_cmd: failed to set sched policy");
pthread_attr_destroy(&attr);
free(taskdata);
return (rv < 0) ? rv : -rv;
}
#ifdef __PX4_CYGWIN
/* Priorities on Windows are defined a lot differently */
priority = SCHED_PRIORITY_DEFAULT;
#endif
param.sched_priority = priority;
rv = pthread_attr_setschedparam(&attr, ¶m);
if (rv != 0) {
PX4_ERR("px4_task_spawn_cmd: failed to set sched param");
pthread_attr_destroy(&attr);
free(taskdata);
return (rv < 0) ? rv : -rv;
}
pthread_mutex_lock(&task_mutex);
px4_task_t taskid = 0;
for (i = 0; i < PX4_MAX_TASKS; ++i) {
if (!taskmap[i].isused) {
taskmap[i].name = name;
taskmap[i].isused = true;
taskid = i;
break;
}
}
if (i >= PX4_MAX_TASKS) {
pthread_attr_destroy(&attr);
pthread_mutex_unlock(&task_mutex);
free(taskdata);
return -ENOSPC;
}
rv = pthread_create(&taskmap[taskid].pid, &attr, &entry_adapter, (void *) taskdata);
if (rv != 0) {
if (rv == EPERM) {
//printf("WARNING: NOT RUNING AS ROOT, UNABLE TO RUN REALTIME THREADS\n");
rv = pthread_create(&taskmap[taskid].pid, nullptr, &entry_adapter, (void *) taskdata);
if (rv != 0) {
PX4_ERR("px4_task_spawn_cmd: failed to create thread %d %d\n", rv, errno);
taskmap[taskid].isused = false;
pthread_attr_destroy(&attr);
pthread_mutex_unlock(&task_mutex);
free(taskdata);
return (rv < 0) ? rv : -rv;
}
} else {
pthread_attr_destroy(&attr);
pthread_mutex_unlock(&task_mutex);
free(taskdata);
return (rv < 0) ? rv : -rv;
}
}
pthread_attr_destroy(&attr);
pthread_mutex_unlock(&task_mutex);
return taskid;
}
开发者ID:AlexisTM,项目名称:Firmware,代码行数:101,代码来源:px4_posix_tasks.cpp
示例10: timedwait_test
void timedwait_test(void)
{
pthread_t waiter;
pthread_attr_t attr;
struct sched_param sparam;
void *result;
int prio_max;
int status;
/* Initialize the mutex */
printf("thread_waiter: Initializing mutex\n");
status = pthread_mutex_init(&mutex, NULL);
if (status != 0) {
printf("timedwait_test: ERROR pthread_mutex_init failed, status=%d\n", status);
}
/* Initialize the condition variable */
printf("timedwait_test: Initializing cond\n");
status = pthread_cond_init(&cond, NULL);
if (status != 0) {
printf("timedwait_test: ERROR pthread_condinit failed, status=%d\n", status);
}
/* Start the waiter thread at higher priority */
printf("timedwait_test: Starting waiter\n");
status = pthread_attr_init(&attr);
if (status != 0) {
printf("timedwait_test: pthread_attr_init failed, status=%d\n", status);
}
prio_max = sched_get_priority_max(SCHED_FIFO);
status = sched_getparam(getpid(), &sparam);
if (status != 0) {
printf("timedwait_test: sched_getparam failed\n");
sparam.sched_priority = PTHREAD_DEFAULT_PRIORITY;
}
sparam.sched_priority = (prio_max + sparam.sched_priority) / 2;
status = pthread_attr_setschedparam(&attr, &sparam);
if (status != OK) {
printf("timedwait_test: pthread_attr_setschedparam failed, status=%d\n", status);
} else {
printf("timedwait_test: Set thread 2 priority to %d\n", sparam.sched_priority);
}
status = pthread_create(&waiter, &attr, thread_waiter, NULL);
if (status != 0) {
printf("timedwait_test: pthread_create failed, status=%d\n", status);
}
printf("timedwait_test: Joining\n");
FFLUSH();
status = pthread_join(waiter, &result);
if (status != 0) {
printf("timedwait_test: ERROR pthread_join failed, status=%d\n", status);
} else {
printf("timedwait_test: waiter exited with result=%p\n", result);
}
}
开发者ID:carhero,项目名称:TizenRT,代码行数:62,代码来源:timedwait.c
示例11: parsecfg
//.........这里部分代码省略.........
logprintf(MLOG_FATAL, "Node has no name\n");
if (!strcmp(node->name, "audio")) {
audio = node;
continue;
}
if (!strcmp(node->name, "ptt")) {
ptt = node;
continue;
}
if (!strcmp(node->name, "chaccess")) {
getparam(doc, node, chaccparams, par);
if (par[0])
state->chacc.txdelay = strtoul(par[0], NULL, 0);
if (par[1])
state->chacc.slottime = strtoul(par[1], NULL, 0);
if (par[2])
state->chacc.ppersist = strtoul(par[2], NULL, 0);
if (par[3])
state->chacc.fullduplex = !!strtoul(par[3], NULL, 0);
if (par[4])
state->chacc.txtail = strtoul(par[4], NULL, 0);
continue;
}
if (!strcmp(node->name, "channel")) {
if (node->children)
parsechannel(doc, node->children, state, &samplerate);
continue;
}
logprintf(MLOG_ERROR, "unknown node \"%s\"\n", node->name);
}
/* find audio mode */
mode = 0;
for (chan = state->channels; chan; chan = chan->next) {
if (chan->demod && chan->demod->demodulate)
mode |= IO_RDONLY;
if (chan->mod && chan->mod->modulate)
mode |= IO_WRONLY;
}
if (!state->channels || !mode) {
logprintf(MLOG_ERROR, "no channels configured\n");
return -1;
}
/* open PTT */
getparam(doc, ptt, pttparams, par);
if (pttinit(&state->ptt, par))
logprintf(MLOG_ERROR, "cannot start PTT output\n");
/* open audio */
getparam(doc, audio, ioparam_type, par);
if (par[0] && !strcmp(par[0], ioparam_type[0].u.c.combostr[1])) {
getparam(doc, audio, ioparams_filein, par);
state->audioio = ioopen_filein(&samplerate, IO_RDONLY, par);
if (schedrr)
*schedrr = 0;
} else if (par[0] && !strcmp(par[0], ioparam_type[0].u.c.combostr[2])) {
getparam(doc, audio, ioparams_sim, par);
state->audioio = ioopen_sim(&samplerate, IO_RDWR, par);
if (schedrr)
*schedrr = 0;
#ifdef HAVE_ALSA
} else if (par[0] && !strcmp(par[0], ioparam_type[0].u.c.combostr[3])) {
getparam(doc, audio, ioparams_alsasoundcard, par);
state->audioio = ioopen_alsasoundcard(&samplerate, mode, par);
#endif /* HAVE_ALSA */
} else {
getparam(doc, audio, ioparams_soundcard, par);
state->audioio = ioopen_soundcard(&samplerate, mode, par);
}
if (!state->audioio)
logprintf(MLOG_FATAL, "cannot start audio\n");
for (chan = state->channels; chan; chan = chan->next) {
if (chan->demod) {
chan->demod->init(chan->demodstate, samplerate, &chan->rxbitrate);
if (pthread_attr_init(&rxattr))
logerr(MLOG_FATAL, "pthread_attr_init");
/* needed on FreeBSD, according to [email protected] */
if (pthread_attr_getstacksize(&rxattr, &stacksize))
logerr(MLOG_ERROR, "pthread_attr_getstacksize");
else if (stacksize < 256*1024)
if (pthread_attr_setstacksize(&rxattr, 256*1024))
logerr(MLOG_ERROR, "pthread_attr_setstacksize");
#ifdef HAVE_SCHED_H
if (schedrr && *schedrr) {
struct sched_param schp;
memset(&schp, 0, sizeof(schp));
schp.sched_priority = sched_get_priority_min(SCHED_RR)+1;
if (pthread_attr_setschedpolicy(&rxattr, SCHED_RR))
logerr(MLOG_ERROR, "pthread_attr_setschedpolicy");
if (pthread_attr_setschedparam(&rxattr, &schp))
logerr(MLOG_ERROR, "pthread_attr_setschedparam");
}
#endif /* HAVE_SCHED_H */
if (pthread_create(&chan->rxthread, &rxattr, demodthread, chan))
logerr(MLOG_FATAL, "pthread_create");
pthread_attr_destroy(&rxattr);
}
if (chan->mod)
chan->mod->init(chan->modstate, samplerate);
}
return 0;
}
开发者ID:epall,项目名称:soundmodem,代码行数:101,代码来源:main.c
示例12: Start
int Start(bool realtime)
{
pthread_attr_t attributes;
struct sched_param rt_param;
pthread_attr_init(&attributes);
int priority = 60; // TODO
int res;
if (realtime) {
fRealTime = true;
}else {
fRealTime = getenv("OMP_REALTIME") ? strtol(getenv("OMP_REALTIME"), NULL, 10) : true;
}
if ((res = pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_JOINABLE))) {
printf("Cannot request joinable thread creation for real-time thread res = %d err = %s\n", res, strerror(errno));
return -1;
}
if ((res = pthread_attr_setscope(&attributes, PTHREAD_SCOPE_SYSTEM))) {
printf("Cannot set scheduling scope for real-time thread res = %d err = %s\n", res, strerror(errno));
return -1;
}
if (realtime) {
if ((res = pthread_attr_setinheritsched(&attributes, PTHREAD_EXPLICIT_SCHED))) {
printf("Cannot request explicit scheduling for RT thread res = %d err = %s\n", res, strerror(errno));
return -1;
}
if ((res = pthread_attr_setschedpolicy(&attributes, JACK_SCHED_POLICY))) {
printf("Cannot set RR scheduling class for RT thread res = %d err = %s\n", res, strerror(errno));
return -1;
}
memset(&rt_param, 0, sizeof(rt_param));
rt_param.sched_priority = priority;
if ((res = pthread_attr_setschedparam(&attributes, &rt_param))) {
printf("Cannot set scheduling priority for RT thread res = %d err = %s\n", res, strerror(errno));
return -1;
}
} else {
if ((res = pthread_attr_setinheritsched(&attributes, PTHREAD_INHERIT_SCHED))) {
printf("Cannot request explicit scheduling for RT thread res = %d err = %s\n", res, strerror(errno));
return -1;
}
}
if ((res = pthread_attr_setstacksize(&attributes, THREAD_STACK))) {
printf("Cannot set thread stack size res = %d err = %s\n", res, strerror(errno));
return -1;
}
if ((res = pthread_create(&fThread, &attributes, ThreadHandler, this))) {
printf("Cannot create thread res = %d err = %s\n", res, strerror(errno));
return -1;
}
// Set affinity
set_affinity(fThread, fNumThread + 1);
pthread_attr_destroy(&attributes);
return 0;
}
开发者ID:onukore,项目名称:radium,代码行数:69,代码来源:scheduler.cpp
示例13: memset
//rtems_task Init(rtems_task_argument Argument)
void *POSIX_Init(void *argument)
{
pthread_attr_t threadAttr;
pthread_t theThread;
struct sched_param sched_param;
size_t stack_size;
int result;
char data[1000];
memset(data, 1, sizeof(data));
/* Set the TOD clock, so that gettimeofday() will work */
rtems_time_of_day fakeTime = { 2006, 3, 15, 17, 30, 0, 0 };
if (RTEMS_SUCCESSFUL != rtems_clock_set(&fakeTime))
{
assert(0);
}
/* Bring up the network stack so we can run the socket tests. */
initialize_network();
/* Start a POSIX thread for pjlib_test_main(), since that's what it
* thinks it is running in.
*/
/* Initialize attribute */
TEST( pthread_attr_init(&threadAttr) );
/* Looks like the rest of the attributes must be fully initialized too,
* or otherwise pthread_create will return EINVAL.
*/
/* Specify explicit scheduling request */
TEST( pthread_attr_setinheritsched(&threadAttr, PTHREAD_EXPLICIT_SCHED));
/* Timeslicing is needed by thread test, and this is accomplished by
* SCHED_RR.
*/
TEST( pthread_attr_setschedpolicy(&threadAttr, SCHED_RR));
/* Set priority */
TEST( pthread_attr_getschedparam(&threadAttr, &sched_param));
sched_param.sched_priority = NETWORK_STACK_PRIORITY - 10;
TEST( pthread_attr_setschedparam(&threadAttr, &sched_param));
/* Must have sufficient stack size (large size is needed by
* logger, because default settings for logger is to use message buffer
* from the stack).
*/
TEST( pthread_attr_getstacksize(&threadAttr, &stack_size));
if (stack_size < 8192)
TEST( pthread_attr_setstacksize(&threadAttr, 8192));
/* Create the thread for application */
result = pthread_create(&theThread, &threadAttr, &pjlib_test_main, NULL);
if (result != 0) {
my_perror(PJ_STATUS_FROM_OS(result),
"Error creating pjlib_test_main thread");
assert(!"Error creating main thread");
}
return NULL;
}
开发者ID:0x0B501E7E,项目名称:pjproject,代码行数:67,代码来源:main_rtems.c
示例14: rsrtInit
/* globally initialze the runtime system
* NOTE: this is NOT thread safe and must not be called concurrently. If that
* ever poses a problem, we may use proper mutex calls - not considered needed yet.
* If ppErrObj is provided, it receives a char pointer to the name of the object that
* caused the problem (if one occured). The caller must never free this pointer. If
* ppErrObj is NULL, no such information will be provided. pObjIF is the pointer to
* the "obj" object interface, which may be used to query any other rsyslog objects.
* rgerhards, 2008-04-16
*/
rsRetVal
rsrtInit(char **ppErrObj, obj_if_t *pObjIF)
{
DEFiRet;
if(iRefCount == 0) {
/* init runtime only if not yet done */
#ifdef HAVE_PTHREAD_SETSCHEDPARAM
CHKiRet(pthread_getschedparam(pthread_self(),
&default_thr_sched_policy,
&default_sched_param));
CHKiRet(pthread_attr_init(&default_thread_attr));
CHKiRet(pthread_attr_setschedpolicy(&default_thread_attr,
default_thr_sched_policy));
CHKiRet(pthread_attr_setschedparam(&default_thread_attr,
&default_sched_param));
CHKiRet(pthread_attr_setinheritsched(&default_thread_attr,
PTHREAD_EXPLICIT_SCHED));
#endif
if(ppErrObj != NULL) *ppErrObj = "obj";
CHKiRet(objClassInit(NULL)); /* *THIS* *MUST* always be the first class initilizer being called! */
CHKiRet(objGetObjInterface(pObjIF)); /* this provides the root pointer for all other queries */
/* initialize core classes. We must be very careful with the order of events. Some
* classes use others and if we do not initialize them in the right order, we may end
* up with an invalid call. The most important thing that can happen is that an error
* is detected and needs to be logged, wich in turn requires a broader number of classes
* to be available. The solution is that we take care in the order of calls AND use a
* class immediately after it is initialized. And, of course, we load those classes
* first that we use ourselfs... -- rgerhards, 2008-03-07
*/
if(ppErrObj != NULL) *ppErrObj = "statsobj";
CHKiRet(statsobjClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "prop";
CHKiRet(propClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "glbl";
CHKiRet(glblClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "msg";
CHKiRet(msgClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "ruleset";
CHKiRet(rulesetClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "wti";
CHKiRet(wtiClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "wtp";
CHKiRet(wtpClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "queue";
CHKiRet(qqueueClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "conf";
CHKiRet(confClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "parser";
CHKiRet(parserClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "strgen";
CHKiRet(strgenClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "rsconf";
CHKiRet(rsconfClassInit(NULL));
/* dummy "classes" */
if(ppErrObj != NULL) *ppErrObj = "str";
CHKiRet(strInit());
}
++iRefCount;
dbgprintf("rsyslog runtime initialized, version %s, current users %d\n", VERSION, iRefCount);
finalize_it:
RETiRet;
}
开发者ID:TheodoreLizard,项目名称:rsyslog,代码行数:76,代码来源:rsyslog.c
示例15: puts
void *POSIX_Init(
void *argument
)
{
int i;
int status;
pthread_t threadId;
pthread_attr_t attr;
struct sched_param param;
puts( "\n\n*** POSIX TIME TEST @[email protected] ***" );
/*
* Deliberately create the XXX BEFORE the threads. This way the
* threads should preempt this thread and block as they are created.
*/
status = 0; /* XXX create resource */
rtems_test_assert( status == 0 );
/*
* Obtain the XXX so the threads will block.
*/
status = 0; /* XXX lock resource to ensure thread blocks */
rtems_test_assert( status == 0 );
/*
* Now lower our priority
*/
status = pthread_attr_init( &attr );
rtems_test_assert( status == 0 );
status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
rtems_test_assert( status == 0 );
status = pthread_attr_setschedpolicy( &attr, SCHED_RR );
rtems_test_assert( status == 0 );
param.sched_priority = 2;
status = pthread_attr_setschedparam( &attr, ¶m );
rtems_test_assert( status == 0 );
/*
* And create rest of threads as more important than we are. They
* will preempt us as they are created and block.
*/
for ( i=0 ; i < OPERATION_COUNT ; i++ ) {
param.sched_priority = 3 + i;
status = pthread_attr_setschedparam( &attr, ¶m );
rtems_test_assert( status == 0 );
status = pthread_create(
&threadId,
&attr,
(i == OPERATION_COUNT - 1) ? Low : Middle,
NULL
);
rtems_test_assert( status == 0 );
}
/*
* Now start the timer which will be stopped in Low
*/
benchmark_timer_initialize();
status = 0; /* XXX release the resource. Threads unblock and preempt */
/* thread switch occurs */
/* should never return */
rtems_test_assert( FALSE );
return NULL;
}
开发者ID:alex-sever-h,项目名称:rtems-testing,代码行数:72,代码来源:init.c
示例16: px4_task_spawn_cmd
px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int stack_size, px4_main_t entry, char * const argv[])
{
int rv;
int argc = 0;
int i;
unsigned int len = 0;
unsigned long offset;
unsigned long structsize;
char * p = (char *)argv;
pthread_t task;
pthread_attr_t attr;
struct sched_param param;
// Calculate argc
while (p != (char *)0) {
p = argv[argc];
if (p == (char *)0)
break;
++argc;
len += strlen(p)+1;
}
structsize = sizeof(pthdata_t)+(argc+1)*sizeof(char *);
pthdata_t *taskdata;
// not safe to pass stack data to the thread creation
taskdata = (pthdata_t *)malloc(structsize+len);
offset = ((unsigned long)taskdata)+structsize;
taskdata->entry = entry;
taskdata->argc = argc;
for (i=0; i<argc; i++) {
printf("arg %d %s\n", i, argv[i]);
taskdata->argv[i] = (char *)offset;
strcpy((char *)offset, argv[i]);
offset+=strlen(argv[i])+1;
}
// Must add NULL at end of argv
taskdata->argv[argc] = (char *)0;
rv = pthread_attr_init(&attr);
if (rv != 0) {
PX4_WARN("px4_task_spawn_cmd: failed to init thread attrs");
return (rv < 0) ? rv : -rv;
}
rv = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLI
|
请发表评论