• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ pthread_attr_setinheritsched函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中pthread_attr_setinheritsched函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_attr_setinheritsched函数的具体用法?C++ pthread_attr_setinheritsched怎么用?C++ pthread_attr_setinheritsched使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pthread_attr_setinheritsched函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: thread_create

Thread_t thread_create(int prio, int sched, ThreadFunc_t func, void *arg)
{
#define n_static 256
  static struct ThreadArgs args_hack[n_static];
  static unsigned hack_idx = 0;
  struct ThreadArgs *args = &args_hack[hack_idx++%n_static];  
#undef n_static
  pthread_t thr;
  pthread_attr_t attr;
#ifndef __KERNEL__
  if (sched == Default && geteuid() == 0) sched = RR;
  else if (sched == Default) sched = Other;
#else
  if (sched == Default) sched = RR;
#endif
  if (prio < thread_prio_min(sched)) prio = thread_prio_min(sched);
  if (prio > thread_prio_max(sched)) prio = thread_prio_max(sched);
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  if (sched != Inherit) {
    struct sched_param sp;
    sched = scheduler_translate(sched);
    pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
    pthread_attr_setschedpolicy(&attr, sched);
    sp.sched_priority = prio;
    pthread_attr_setschedparam(&attr, &sp);
  } else if (sched == Inherit) {
    pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
  }
#ifdef RTLINUX
  pthread_attr_setfp_np(&attr, 1);
#endif
  args->func = func;
  args->arg = arg;
  (void) prio; /* TODO: implement priorities.. */
  if (pthread_create(&thr, &attr, thread_wrapper, args)) 
    /* TODO handle errors here.. */
    return NULL;
  pthread_attr_destroy(&attr);
  return (Thread_t)thr;
}
开发者ID:ruby6117,项目名称:ccode,代码行数:41,代码来源:SysDep.c


示例2: pthread_attr_setinheritsched

/**
 *  Starts the thread. This method will signal to start the thread and
 *  return immediately. Note that the thread might not yet run when this
 *  method returns! The abstract method Main() is the entry point for the
 *  new thread. You have to implement the Main() method in your subclass.
 *
 *  @see StartThread()
 */
int Thread::SignalStartThread() {
    // prepare the thread properties
    int res = pthread_attr_setinheritsched(&__thread_attr, PTHREAD_EXPLICIT_SCHED);
    if (res) {
        std::cerr << "Thread creation failed: Could not inherit thread properties."
                  << std::endl << std::flush;
        RunningCondition.Set(false);
        return res;
    }
    res = pthread_attr_setdetachstate(&__thread_attr, PTHREAD_CREATE_JOINABLE);
    if (res) {
        std::cerr << "Thread creation failed: Could not request a joinable thread."
                  << std::endl << std::flush;
        RunningCondition.Set(false);
        return res;
    }
    res = pthread_attr_setscope(&__thread_attr, PTHREAD_SCOPE_SYSTEM);
    if (res) {
        std::cerr << "Thread creation failed: Could not request system scope for thread scheduling."
                  << std::endl << std::flush;
        RunningCondition.Set(false);
        return res;
    }
    res = pthread_attr_setstacksize(&__thread_attr, MIN_STACK_SIZE);
    if (res) {
        std::cerr << "Thread creation failed: Could not set minimum stack size."
                  << std::endl << std::flush;
        RunningCondition.Set(false);
        return res;
    }
    // Create and run the thread
    res = pthread_create(&this->__thread_id, &__thread_attr, __pthread_launcher, this);
    switch (res) {
        case 0: // Success
            break;
        case EAGAIN:
            std::cerr << "Thread creation failed: System doesn't allow to create another thread."
                      << std::endl << std::flush;
            RunningCondition.Set(false);
            break;
        case EPERM:
            std::cerr << "Thread creation failed: You're lacking permisssions to set required scheduling policy and parameters."
                      << std::endl << std::flush;
            RunningCondition.Set(false);
            break;
        default:
            std::cerr << "Thread creation failed: Unknown cause."
                      << std::endl << std::flush;
            RunningCondition.Set(false);
            break;
    }
    return res;
}
开发者ID:svn2github,项目名称:linuxsampler,代码行数:61,代码来源:Thread.cpp


示例3: start_interrupt_source

int start_interrupt_source( int intr )
{
    pthread_attr_t      pattr;
    struct sched_param  param;

    pthread_attr_init( &pattr );
    param.sched_priority = 15;
    pthread_attr_setschedparam( &pattr, &param );
    pthread_attr_setinheritsched( &pattr, PTHREAD_EXPLICIT_SCHED );

    return pthread_create( NULL, NULL, interrupt_thread, (void *)intr );
}
开发者ID:vocho,项目名称:openqnx,代码行数:12,代码来源:sources.c


示例4: main

int main()
{
	pthread_t new_th;
	pthread_attr_t attr;
	int rc;
	struct sched_param sp;

	/* Initialize attr */
	rc = pthread_attr_init(&attr);
	if (rc != 0) {
		printf(ERROR_PREFIX "pthread_attr_init");
		exit(PTS_UNRESOLVED);
	}

	rc = pthread_attr_setschedpolicy(&attr, policy);
	if (rc != 0) {
		printf(ERROR_PREFIX "pthread_attr_setschedpolicy");
		exit(PTS_UNRESOLVED);
	}

	sp.sched_priority = 1;
	rc = pthread_attr_setschedparam(&attr, &sp);
	if (rc != 0) {
		printf(ERROR_PREFIX "pthread_attr_setschedparam");
		exit(PTS_UNRESOLVED);
	}

	int insched = PTHREAD_EXPLICIT_SCHED;
	rc = pthread_attr_setinheritsched(&attr, insched);
	if (rc != 0) {
		printf(ERROR_PREFIX "pthread_attr_setinheritsched");
		exit(PTS_UNRESOLVED);
	}

	rc = pthread_create(&new_th, &attr, thread_func, NULL);
	if (rc != 0) {
		printf("Error at pthread_create(): %s\n", strerror(rc));
		exit(PTS_UNRESOLVED);
	}

	rc = pthread_join(new_th, NULL);
	if (rc != 0) {
		printf(ERROR_PREFIX "pthread_join");
		exit(PTS_UNRESOLVED);
	}
	rc = pthread_attr_destroy(&attr);
	if (rc != 0) {
		printf(ERROR_PREFIX "pthread_attr_destroy");
		exit(PTS_UNRESOLVED);
	}
	printf("Test PASSED\n");
	return PTS_PASS;
}
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:53,代码来源:2-2.c


示例5: start_timer_source

int start_timer_source( void )
{
    pthread_attr_t      pattr;
    struct sched_param  param;

    pthread_attr_init( &pattr );
    param.sched_priority = 10;
    pthread_attr_setschedparam( &pattr, &param );
    pthread_attr_setinheritsched( &pattr, PTHREAD_EXPLICIT_SCHED );

    return pthread_create( NULL, &pattr, timer_thread, NULL );
}
开发者ID:vocho,项目名称:openqnx,代码行数:12,代码来源:sources.c


示例6: startThread

int startThread(Thread* thrd)
{
	struct sched_param schedp;
	pthread_condattr_t condattr;
	int retc, policy, inherit;

	printf("Start thread priority %d\n", thrd->priority);
	if (pthread_attr_init(&(thrd->attr)) != 0) {
		printf("Attr init failed");
		exit(2);
	}
	thrd->flags = 0;
	memset(&schedp, 0, sizeof(schedp));
	schedp.sched_priority = thrd->priority;
	policy = thrd->policy;

	if (pthread_attr_setschedpolicy(&(thrd->attr), policy) != 0) {
		printf("Can't set policy %d\n", policy);
	}
	if (pthread_attr_getschedpolicy(&(thrd->attr), &policy) != 0) {
		printf("Can't get policy\n");
	} else {
		printf("Policy in attribs is %d\n", policy);
	}
	if (pthread_attr_setschedparam(&(thrd->attr), &schedp) != 0) {
		printf("Can't set params");
	}
	if (pthread_attr_getschedparam(&(thrd->attr), &schedp) != 0) {
		printf("Can't get params");
	} else {
		printf("Priority in attribs is %d\n", schedp.sched_priority);
	}
	if (pthread_attr_setinheritsched(&(thrd->attr), PTHREAD_EXPLICIT_SCHED) != 0) {
		printf("Can't set inheritsched\n");
	}
	if (pthread_attr_getinheritsched(&(thrd->attr), &inherit) != 0) {
		printf("Can't get inheritsched\n");
	} else {
		printf("inherit sched in attribs is %d\n", inherit);
	}
	if ((retc = pthread_mutex_init(&(thrd->mutex), NULL)) != 0) {
		printf("Failed to init mutex: %d\n", retc);
	}
	if (pthread_condattr_init(&condattr) != 0) {
		printf("Failed to init condattr\n");
	}
	if (pthread_cond_init(&(thrd->cond), &condattr) != 0) {
		printf("Failed to init cond\n");
	}
	retc = pthread_create(&(thrd->pthread),&(thrd->attr), thrd->func, thrd);
	printf("Create returns %d\n\n", retc);
	return retc;
}
开发者ID:shubmit,项目名称:shub-ltp,代码行数:53,代码来源:testpi-3.c


示例7: sizeof

thread_type *thread_create_c(char *name, void *(*start_routine)(void *),
        void *arg, int detached, int line, char *file)
{
    int ok = 1;
    thread_type *thread = NULL;
    thread_start_t *start = NULL;
    pthread_attr_t attr;

    thread = (thread_type *)acalloc(1, sizeof(thread_type));
    do {
        start = (thread_start_t *)acalloc(1, sizeof(thread_start_t));
        if (pthread_attr_init (&attr) < 0)
            break;

        thread->line = line;
        thread->file = strdup(file);

        _mutex_lock (&_threadtree_mutex);
        thread->thread_id = _next_thread_id++;
        _mutex_unlock (&_threadtree_mutex);

        thread->name = strdup(name);
        thread->create_time = time(NULL);

        start->start_routine = start_routine;
        start->arg = arg;
        start->thread = thread;

        pthread_attr_setstacksize (&attr, 512*1024);
        pthread_attr_setinheritsched (&attr, PTHREAD_INHERIT_SCHED);
        if (detached)
        {
            pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
            thread->detached = 1;
        }

        if (pthread_create (&thread->sys_thread, &attr, _start_routine, start) == 0)
        {
            pthread_attr_destroy (&attr);
            return thread;
        }
        else
            pthread_attr_destroy (&attr);
    }
    while (0);

#ifdef THREAD_DEBUG
    LOG_ERROR("Could not create new thread %s", name);
#endif
    if (start) free (start);
    if (thread) free (thread);
    return NULL;
}
开发者ID:xaiki,项目名称:IceCast,代码行数:53,代码来源:thread.c


示例8: main

int main(int argc, char* argv[])
{
    //pthread_t threads[4];
    printf("Start des Beispiels \n");
    //printf("Argumente verfuegbar: ARGC\n", 3*argc);
    p_rb -> p_in = p_start;
    p_rb -> p_out = p_start;
    p_rb -> count = 0;
    printf("Counter value %d\n", p_rb ->count);

    pthread_attr_t my_thread_attr; // Thread Attribut
    struct sched_param my_prio;
    pthread_attr_init(&my_thread_attr);
    pthread_attr_setinheritsched(&my_thread_attr, PTHREAD_EXPLICIT_SCHED); // Freigabe der Parameteränd.
    pthread_attr_setschedpolicy(&my_thread_attr, SCHED_FIFO);
    my_prio.sched_priority = 10; // Priority ändern
    pthread_attr_setschedparam(&my_thread_attr, &my_prio);

    // Threads erstellen
    pthread_create(&threads[2], NULL, control, (void *)&thread_id[2]);
    pthread_create(&threads[0], NULL, p_1_w, (void *)thread_id);
    pthread_create(&threads[1], NULL, p_2_w, (void *)&thread_id[1]);
    pthread_create(&threads[3], NULL, consumer, (void *)&thread_id[3]);

        // Controller join und status abfangen
        pthread_join(threads[2], &status);
        // Wenn erfolgreich beendet
        if (status == 0) {
            printf("Control join erfolgreich!\n");
            pthread_cond_signal(&p1_unlock); // signal für das Freigeben, wenn p1 gestoppt ist.
            pthread_cond_signal(&p2_unlock); // signal für das Freigeben, wenn p2 gestoppt ist.
            pthread_cond_signal(&c_unlock); // signal für das Freigeben, wenn c gestoppt ist.
            pthread_cancel(threads[0]); // beenden
            pthread_cancel(threads[1]); // beenden
            pthread_cancel(threads[3]); // beenden
        }

    //for(i = 0; i<4; i++) {
        result[0] = pthread_join(threads[0], NULL); // &status
        result[1] = pthread_join(threads[1], NULL); // &status
        result[3] = pthread_join(threads[3], NULL); // &status
    //printf("Exit status: %d\n", *(int *)status); // Speicherzugriffsfehler
        //result[i] = *(int *)status;
    //}

	// vosichthalber vor dem Join ein Signal für den jeweiligen Thread mit condtion schicken.
    printf("Ende nach Join der Threads\n");
    //printf("Control Thread returns: %d\n",result[2]);
    printf("Producer_1 Thread returns: %d\n",result[0]);
    printf("Producer_2 Thread returns: %d\n",result[1]);
    printf("Consumer Thread returns: %d\n",result[3]);
    return 0;
}
开发者ID:CasaSky,项目名称:BSP,代码行数:53,代码来源:Aufgabe2.c


示例9: run_iddp

static int run_iddp(struct smokey_test *t, int argc, char *const argv[])
{
	struct sched_param svparam = {.sched_priority = 71 };
	struct sched_param clparam = {.sched_priority = 70 };
	pthread_attr_t svattr, clattr;
	int s;

	s = socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_IDDP);
	if (s < 0) {
		if (errno == EAFNOSUPPORT)
			return -ENOSYS;
	} else
		close(s);

	pthread_attr_init(&svattr);
	pthread_attr_setdetachstate(&svattr, PTHREAD_CREATE_JOINABLE);
	pthread_attr_setinheritsched(&svattr, PTHREAD_EXPLICIT_SCHED);
	pthread_attr_setschedpolicy(&svattr, SCHED_FIFO);
	pthread_attr_setschedparam(&svattr, &svparam);

	errno = pthread_create(&svtid, &svattr, &server, NULL);
	if (errno)
		fail("pthread_create");

	pthread_attr_init(&clattr);
	pthread_attr_setdetachstate(&clattr, PTHREAD_CREATE_JOINABLE);
	pthread_attr_setinheritsched(&clattr, PTHREAD_EXPLICIT_SCHED);
	pthread_attr_setschedpolicy(&clattr, SCHED_FIFO);
	pthread_attr_setschedparam(&clattr, &clparam);

	errno = pthread_create(&cltid, &clattr, &client, NULL);
	if (errno)
		fail("pthread_create");

	pthread_join(cltid, NULL);
	pthread_cancel(svtid);
	pthread_join(svtid, NULL);

	return 0;
}
开发者ID:ChunHungLiu,项目名称:xenomai,代码行数:40,代码来源:iddp.c


示例10: le_mem_ForceAlloc

//--------------------------------------------------------------------------------------------------
static ThreadObj_t* CreateThread
(
    const char*             name,       ///< [in] Name of the thread.
    le_thread_MainFunc_t    mainFunc,   ///< [in] The thread's main function.
    void*                   context     ///< [in] Value to pass to mainFunc when it is called.
)
{
    // Create a new thread object.
    ThreadObj_t* threadPtr = le_mem_ForceAlloc(ThreadPool);

    // Copy the name.  We will make the names unique by adding the thread ID later so we allow any
    // string as the name.
    LE_WARN_IF(le_utf8_Copy(threadPtr->name, name, sizeof(threadPtr->name), NULL) == LE_OVERFLOW,
               "Thread name '%s' has been truncated to '%s'.",
               name,
               threadPtr->name);

    // Initialize the pthreads attribute structure.
    LE_ASSERT(pthread_attr_init(&(threadPtr->attr)) == 0);

    // Make sure when we create the thread it takes it attributes from the attribute object,
    // as opposed to inheriting them from its parent thread.
    if (pthread_attr_setinheritsched(&(threadPtr->attr), PTHREAD_EXPLICIT_SCHED) != 0)
    {
        LE_CRIT("Could not set scheduling policy inheritance for thread '%s'.", name);
    }

    // By default, Legato threads are not joinable (they are detached).
    if (pthread_attr_setdetachstate(&(threadPtr->attr), PTHREAD_CREATE_DETACHED) != 0)
    {
        LE_CRIT("Could not set the detached state for thread '%s'.", name);
    }

    threadPtr->isJoinable = false;
    threadPtr->isStarted = false;
    threadPtr->mainFunc = mainFunc;
    threadPtr->context = context;
    threadPtr->destructorList = LE_SLS_LIST_INIT;
    threadPtr->threadHandle = 0;

    memset(&threadPtr->mutexRec, 0, sizeof(threadPtr->mutexRec));
    memset(&threadPtr->semaphoreRec, 0, sizeof(threadPtr->semaphoreRec));
    memset(&threadPtr->eventRec, 0, sizeof(threadPtr->eventRec));
    memset(&threadPtr->timerRec, 0, sizeof(threadPtr->timerRec));

    // Create a safe reference for this object.
    Lock();
    threadPtr->safeRef = le_ref_CreateRef(ThreadRefMap, threadPtr);
    Unlock();

    return threadPtr;
}
开发者ID:mbarazzouq,项目名称:legato-af,代码行数:53,代码来源:thread.c


示例11: main

int main(void)
{
	pthread_t tid;
	int ret;
	pthread_attr_t attr;
	int policy, inher;
	struct sched_param param;

	policy = SCHED_FIFO;
	param.sched_priority = 99;


	pthread_attr_init(&attr);
	
	pthread_attr_getinheritsched(&attr, &inher);
	if (inher == PTHREAD_INHERIT_SCHED)
		printf("Can't change sched policy!\n");
	else if (inher == PTHREAD_EXPLICIT_SCHED)	
		printf("Can change sched policy!\n");
#if 1
	pthread_attr_setinheritsched(&attr, 
		PTHREAD_EXPLICIT_SCHED);

	ret = pthread_attr_setschedpolicy(&attr, policy);
	if (ret) {
		printf("set policy:%s\n",
			strerror(ret));
		exit(1);
	}

	ret = pthread_attr_setschedparam(&attr, &param);
	if (ret) {
		printf("set policy:%s\n",
			strerror(ret));
		exit(1);
	}
#endif
	ret = pthread_create(&tid, &attr,
		thread_handler, NULL);
	if (ret) {
		printf("pthread_create:%s\n",
			strerror(ret));
		exit(1);	
	}
	struct timeval priv, next;
	gettimeofday(&priv, NULL);
	do_prime(300000007);
	gettimeofday(&next, NULL);

	testTime(&priv, &next);
	pthread_exit(NULL);
}
开发者ID:guolilong2012,项目名称:study,代码行数:52,代码来源:sched_attr.c


示例12: main

int main(int argc, char *argv[]) {
	struct hostent *hp;
	int flags;
	struct timeval tv;
	struct stun_state st;
        pthread_attr_t attr;
        pthread_t thread;

	gettimeofday(&tv, 0);
	srandom(tv.tv_sec + tv.tv_usec);

	hp=gethostbyname(argv[1]);
	memcpy(&stunserver.sin_addr, hp->h_addr, sizeof(stunserver.sin_addr));
	stunserver.sin_port = htons(3478);

	st.sock=socket(PF_INET,SOCK_DGRAM,0);
	flags = fcntl(st.sock, F_GETFL);
	fcntl(st.sock, F_SETFL, flags | O_NONBLOCK);

	st.bindaddr.sin_family=AF_INET;
	st.bindaddr.sin_addr.s_addr=inet_addr(argv[2]);
	st.bindaddr.sin_port=htons((random() % (65535-1023))+1023);
	bind(st.sock,(struct sockaddr *)&st.bindaddr,sizeof(struct sockaddr_in));

	pthread_attr_init(&attr);
	pthread_attr_setschedpolicy(&attr, SCHED_RR);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
	pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
	pthread_create(&thread, &attr, data_thread, &st);

	stun_send(STUN_BINDREQ,&st,NULL,0,0);

	while(1) {
		usleep(20000);
		gettimeofday(&tv,0);
		if ((tv.tv_sec*1000000+tv.tv_usec)-(st.laststun.tv_sec*1000000+st.laststun.tv_usec) > atoi(argv[3])*1000) {
			if ((st.result & STUN_NAT_SYMN) && (st.pcnt == 1)) {
				stun_send(STUN_BINDREQ,&st,NULL,0,2);
			} else {
				if (st.result < STUN_NAT_OPEN)
					printf("NEW IP:%s:%i Result: %i\n",inet_ntoa(st.bindaddr.sin_addr),ntohs(st.bindaddr.sin_port),st.result);
				else
					printf("NEW IP:%s:%i Result: %i\n",inet_ntoa(st.maddr.sin_addr),ntohs(st.maddr.sin_port),st.result);
				break;
			}
		}
	}
	pthread_attr_destroy(&attr);
	shutdown(st.sock,SHUT_RDWR);

	exit(0);
}
开发者ID:Distrotech,项目名称:stun-c,代码行数:52,代码来源:stun.c


示例13: init_priority

void init_priority(pthread_attr_t * attr, int priority)
{
    struct sched_param sched = {0};
    // 1-99, 99 is max, above 49 could starve sockets?
    // according to SOEM sample code
    sched.sched_priority = priority;
    // need EXPLICIT_SCHED or the default is
    // INHERIT_SCHED from parent process
    assert(pthread_attr_init(attr) == 0);
    assert(pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED) == 0);
    assert(pthread_attr_setschedpolicy(attr, SCHED_FIFO) == 0);
    assert(pthread_attr_setschedparam(attr, &sched) == 0);
}
开发者ID:ronaldomercado,项目名称:ethercat,代码行数:13,代码来源:rttest.c


示例14: test

int test( void )
{
  pthread_attr_t  attr;
  int             inheritsched;
  int             result;

  inheritsched = PTHREAD_INHERIT_SCHED;
  inheritsched = PTHREAD_EXPLICIT_SCHED;

  result = pthread_attr_setinheritsched( &attr, inheritsched );

  return result;
}
开发者ID:0871087123,项目名称:rtems,代码行数:13,代码来源:pthread15.c


示例15: start_syspoll_source

int start_syspoll_source( void )
{
    pthread_attr_t      pattr;
    struct sched_param  param;

    pthread_attr_init( &pattr );
    param.sched_priority = 11;
    pthread_attr_setschedparam( &pattr, &param );
    pthread_attr_setinheritsched( &pattr, PTHREAD_EXPLICIT_SCHED );
    pthread_attr_setstacksize( &pattr, 16*1024 );

    return pthread_create( NULL, NULL, syspoll_thread, NULL );
}
开发者ID:vocho,项目名称:openqnx,代码行数:13,代码来源:sources.c


示例16: sc_tecreate

int sc_tecreate(void (*entry) (void *),
		int tid,
		int prio,
		int mode,
		u_long ustacksz,
		u_long sstacksz __attribute__ ((unused)),
		char *paddr, u_long psize, int *errp)
{
	struct vrtx_task_iargs iargs;
	struct sched_param param;
	pthread_attr_t thattr;
	int err, policy;
	pthread_t thid;

	/* Migrate this thread to the Linux domain since we are about to
	   issue a series of regular kernel syscalls in order to create
	   the new Linux thread, which in turn will be mapped to a VRTX
	   shadow. */

	XENOMAI_SYSCALL1(__xn_sys_migrate, XENOMAI_LINUX_DOMAIN);

	iargs.tid = tid;
	iargs.prio = prio;
	iargs.mode = mode;
	iargs.entry = entry;
	iargs.param = paddr;
	__real_sem_init(&iargs.sync, 0, 0);

	pthread_attr_init(&thattr);

	ustacksz = xeno_stacksize(ustacksz);

	pthread_attr_setinheritsched(&thattr, PTHREAD_EXPLICIT_SCHED);
	policy = vrtx_task_set_posix_priority(prio, &param);
	pthread_attr_setschedparam(&thattr, &param);
	pthread_attr_setschedpolicy(&thattr, policy);
	pthread_attr_setstacksize(&thattr, ustacksz);
	pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_DETACHED);

	err = __real_pthread_create(&thid, &thattr, &vrtx_task_trampoline, &iargs);
	if (err) {
		*errp = err;
		__real_sem_destroy(&iargs.sync);
		return -1;
	}

	while (__real_sem_wait(&iargs.sync) && errno == EINTR) ;
	__real_sem_destroy(&iargs.sync);

	return iargs.tid;
}
开发者ID:JackieXie168,项目名称:xenomai,代码行数:51,代码来源:task.c


示例17: initRTThreadAttr

int initRTThreadAttr(pthread_attr_t *p_attributes, unsigned int p_stackSize, int p_priority)
{
	int ret;
	ret = pthread_attr_init(p_attributes);
	if (ret != 0) {
		PRINT_ERR("Failed to init pthread attributes (%d).\n", ret);
		return ret;
	}
	
	ret = pthread_attr_setinheritsched(p_attributes, PTHREAD_EXPLICIT_SCHED);
	if(ret != 0) {
		PRINT_ERR("Failed to set inheritsched of pthread attribute (%d).\n", ret);
		return ret;
	}
	
	ret = pthread_attr_setstacksize(p_attributes, p_stackSize);
	if(ret != 0) {
		PRINT_ERR("Failed to set stacksize of pthread attribute (%d).\n", ret);
		return ret;
	}
	
	ret = pthread_attr_setdetachstate(p_attributes, PTHREAD_CREATE_JOINABLE);
	if(ret != 0) {
		PRINT_ERR("Failed to set detachstate of pthread attribute (%d).\n", ret);
		return ret;
	}
	
	ret = pthread_attr_setscope(p_attributes, PTHREAD_SCOPE_SYSTEM);
	if(ret != 0) {
		PRINT_ERR("Failed to set scope of pthread attribute (%d).\n", ret);
		return ret;
	}
	
	ret = pthread_attr_setschedpolicy(p_attributes, SCHEDULING_POLICY);
	if(ret != 0) {
		PRINT_ERR("Failed to set scheduling policy of pthread attribute (%d).\n", ret);
		return ret;
	}
	
	struct sched_param schedParam;
	// only priority is used by pthreads
	schedParam.sched_priority = p_priority;
	ret = pthread_attr_setschedparam(p_attributes, &schedParam);
	if(ret != 0) {
		PRINT_ERR("Failed to set scheduling priority of pthread attribute (%d).\n", ret);
		return ret;
	}
	
	return 0;
}
开发者ID:RealzeitsystemeSS14,项目名称:SpeechRecognition,代码行数:50,代码来源:RTScheduling.c


示例18: main

void main(void)
{
   int rc, scope;

   printf("Before adjustments to scheduling policy:\n");
   print_scheduler();

#ifdef RUN_RT_THREAD
   pthread_attr_init(&main_sched_attr);
   pthread_attr_setinheritsched(&main_sched_attr, PTHREAD_EXPLICIT_SCHED);
   pthread_attr_setschedpolicy(&main_sched_attr, SCHED_FIFO);

   rt_max_prio = sched_get_priority_max(SCHED_FIFO);
   rt_min_prio = sched_get_priority_min(SCHED_FIFO);

   main_param.sched_priority = rt_max_prio;
   rc=sched_setscheduler(getpid(), SCHED_FIFO, &main_param);


   if (rc)
   {
       printf("ERROR; sched_setscheduler rc is %d\n", rc);
       perror("sched_setschduler"); exit(-1);
   }

   printf("After adjustments to scheduling policy:\n");
   print_scheduler();

   main_param.sched_priority = rt_max_prio;
   pthread_attr_setschedparam(&main_sched_attr, &main_param);

   rc = pthread_create(&main_thread, &main_sched_attr, delay_test, (void *)0);

   if (rc)
   {
       printf("ERROR; pthread_create() rc is %d\n", rc);
       perror("pthread_create");
       exit(-1);
   }

   pthread_join(main_thread, NULL);

   if(pthread_attr_destroy(&main_sched_attr) != 0)
     perror("attr destroy");
#else
   delay_test((void *)0);
#endif

   printf("TEST COMPLETE\n");
}
开发者ID:naveenv90,项目名称:ecen5653,代码行数:50,代码来源:posix_clock.c


示例19: pth_attri_set

int
pth_attri_set (pth_attri_t *attri, pth_attr_types_t t, void *data) {
	int *di = (int *)data;
	size_t *ds = (size_t *)data;
	if (attri != (pth_attri_t *)NULL) {
		switch (t) {
			/* pthread_attr_setdetachstate */
		case PTH_ATTR_DETACHED:
			attri->at |= t;
			return pthread_attr_setdetachstate (&(attri->attr),
			                                    PTHREAD_CREATE_JOINABLE);
			/* pthread_attr_setdetachstate */
		case PTH_ATTR_JOINABLE:
			attri->at |= t;
			return pthread_attr_setdetachstate (&(attri->attr),
			                                    PTHREAD_CREATE_DETACHED);
#ifndef LINUX
			/* pthread_attr_setstacksize */
		case PTH_ATTR_STACKSZ:
			attri->at |= t;
			return pthread_attr_setstacksize (&(attri->attr), *ds);
			/* pthread_attr_setguardsize */
		case PTH_ATTR_GUARDSZ:
			attri->at |= t;
			return pthread_attr_setguardsize (&(attri->attr), *ds);
#endif /* !LINUX */
			/* pthread_attr_setschedparam */
		case PTH_ATTR_SCHEDPARAM:
			attri->at |= t;
			return pthread_attr_setschedparam (&(attri->attr),
			                                   (struct sched_param *)data);
			/* pthread_attr_setinheritsched */
		case PTH_ATTR_INSCHEDPARAM:
			attri->at |= t;
			return pthread_attr_setinheritsched (&(attri->attr), *di);
			/* pthread_attr_setschedpolicy */
		case PTH_ATTR_SCHEDPOLICY:
			attri->at |= t;
			return pthread_attr_setschedpolicy (&(attri->attr), *di);
			/* pthread_attr_setscope */
		case PTH_ATTR_SCOPE:
			attri->at |= t;
			return pthread_attr_setscope (&(attri->attr), *di);
		default:
			return CAF_ERROR_SUB;
		}
	}
	return CAF_ERROR_SUB;
}
开发者ID:danielspicar,项目名称:caffeine,代码行数:49,代码来源:caf_thread_attr.c


示例20: sizeof

osd_thread *osd_thread_create(osd_thread_callback callback, void *cbparam)
{
	osd_thread *thread;
	pthread_attr_t	attr;

	thread = (osd_thread *)calloc(1, sizeof(osd_thread));
	pthread_attr_init(&attr);
	pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
	if ( pthread_create(&thread->thread, &attr, callback, cbparam) != 0 )
	{
		free(thread);
		return NULL;
	}
	return thread;
}
开发者ID:coinhelper,项目名称:jsmess,代码行数:15,代码来源:sdlsync_tc.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pthread_attr_setschedparam函数代码示例发布时间:2022-05-30
下一篇:
C++ pthread_attr_setdetachstate函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap