Exemplo n.º 1
0
TCGvoid TCGClient::AddThreadPriority()
{
#ifdef ANDROID
#if 0    /* Add thread priority */
    pthread_attr_t  attr;
    TCGbool         policy;
    TCGbool         rs;
    struct          sched_param param;
    TCGbool         maxThreadPriority;

    rs = pthread_attr_init(&attr);
    pthread_attr_getschedpolicy(&attr, &policy);

    if (policy != SCHED_RR)
    {
        pthread_attr_setschedpolicy(&attr, SCHED_RR);
    }

    maxThreadPriority = sched_get_priority_max(SCHED_RR);

    rs = pthread_attr_getschedparam(&attr, &param);
    policy =  param.sched_priority;
    if (policy < maxThreadPriority)
    {
        param.sched_priority = maxThreadPriority;
        pthread_attr_setschedparam(&attr, &param);

        rs = pthread_attr_getschedparam(&attr, &param);
    }
#endif
#endif
}
Exemplo n.º 2
0
void CPosixThreadImpl::start(IRhoRunnable *pRunnable, IRhoRunnable::EPriority ePriority)
{
    pthread_attr_t  attr;
    int return_val = pthread_attr_init(&attr);
    //return_val = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    RHO_ASSERT(!return_val);

    if ( ePriority != IRhoRunnable::epNormal)
    {
        sched_param param;
        return_val = pthread_attr_getschedparam (&attr, &param);
        param.sched_priority = ePriority == IRhoRunnable::epLow ? 20 : 100; //TODO: sched_priority
        return_val = pthread_attr_setschedparam (&attr, &param);
    }

    #ifdef __SYMBIAN32__
        size_t stacksize = 80000;
        pthread_attr_setstacksize(&attr, stacksize);
    #endif

    int thread_error = pthread_create(&m_thread, &attr, &runProc, pRunnable);
    return_val = pthread_attr_destroy(&attr);
    RHO_ASSERT(!return_val);
    RHO_ASSERT(thread_error==0);
}
Exemplo n.º 3
0
gm_Bool
httpreq_init(int port, int boost_prio)
{
  char portnum[8];
  int i;
  pthread_attr_t att;
  struct sched_param sched;

  sprintf(portnum,"%d",port);
  gSock = slisten(portnum);

  if (gSock < 1) {
    /* failed to open listening socket */
    MON_SEND_2(MON_ERR,"Socket listen failed: %s\n", strerror(errno));
    return gm_False;
    /* NOTREACHED */
  }

  i = 1;
  if (setsockopt(gSock, SOL_SOCKET, SO_REUSEADDR, (const char *)&i, sizeof(int))
      != 0) {
    MON_SEND_2(MON_ERR,"setsockopt SO_REUSEADDR: %s", strerror(errno));  
  }
  
  i = 0;
  if (setsockopt(gSock, SOL_SOCKET, SO_KEEPALIVE, (const char *)&i, sizeof(int))
      != 0) {
    MON_SEND_2(MON_ERR,"setsockopt SO_KEEPALIVE: %s", strerror(errno));
  }

  MON_SEND_2(MON_LOGGING,"(HTTP): listening on port %d\n", port);

  n_httpreqs = 1;

  /* spawn a local worker thread  */

  THR_OP("HTTP thread attrs init", pthread_attr_init(&att));
  THR_OP("HTTP set global scope",
         pthread_attr_setscope(&att, PTHREAD_SCOPE_SYSTEM));
  THR_OP("HTTP get sched params",
         pthread_attr_getschedparam(&att, &sched));

#ifdef _MIT_POSIX_THREADS
  sched.prio += boost_prio;
#else
  sched.sched_priority += boost_prio;
#endif

  THR_OP("HTTP boost prio",
         pthread_attr_setschedparam(&att, &sched));
  MON_SEND_2(MON_LOGGING,"Boosting HTTP accept() thread prio by %d\n",
	     boost_prio);
  THR_OP("Thread create HTTP",
         pthread_create(&thr_http, (pthread_attr_t *)&att,
                        http_eventloop_proc, (void *)NULL));
  
  proxy_debug_2(DBG_HTTP, "Spawned HTTP worker thread\n");
  return gm_True;

}
Exemplo n.º 4
0
int start_thread_TRIGGER(struct radclock_handle *handle)
{
	int err;
	pthread_attr_t thread_attr;
	pthread_attr_init(&thread_attr);
	pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);
	struct sched_param sched;

	/*
	 * Increase the priority of that particular thread to improve the accuracy
	 * of the packet sender
	 */
	err = pthread_attr_getschedparam (&thread_attr, &sched);
	sched.sched_priority = sched_get_priority_max(SCHED_FIFO);
	err = pthread_attr_setschedparam (&thread_attr, &sched);
	
	pthread_attr_setschedpolicy(&thread_attr, SCHED_FIFO);

	verbose(LOG_NOTICE, "Starting trigger thread");
	err = pthread_create(&(handle->threads[PTH_TRIGGER]), &thread_attr,
			thread_trigger, (void *)(handle));
	if (err)
		verbose(LOG_ERR, "pthread_create() returned error number %d", err);
	
	return (err);
}
Exemplo n.º 5
0
void CPosixThreadImpl::start(IRhoRunnable *pRunnable, IRhoRunnable::EPriority ePriority)
{
#if defined(OS_ANDROID)
    // Android has no pthread_condattr_xxx API
    pthread_cond_init(&m_condSync, NULL);
#else
    pthread_condattr_t sync_details;
    pthread_condattr_init(&sync_details);
    pthread_cond_init(&m_condSync, &sync_details);
    pthread_condattr_destroy(&sync_details);
#endif

    pthread_attr_t  attr;
    int return_val = pthread_attr_init(&attr);
    return_val = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    RHO_ASSERT(!return_val);

    if ( ePriority != IRhoRunnable::epNormal)
    {
        sched_param param;
        return_val = pthread_attr_getschedparam (&attr, &param);
        param.sched_priority = ePriority == IRhoRunnable::epLow ? 20 : 100; //TODO: sched_priority
        return_val = pthread_attr_setschedparam (&attr, &param);
    }

    int thread_error = pthread_create(&m_thread, &attr, &runProc, pRunnable);
    return_val = pthread_attr_destroy(&attr);
    RHO_ASSERT(!return_val);
    RHO_ASSERT(thread_error==0);
}
Exemplo n.º 6
0
static int forward_create_thread(pthread_t *tid, thread_param_t *arg)
{
	int t;
	pthread_attr_t attr;
	struct sched_param param;

	pthread_attr_init(&attr);

	pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);

	pthread_attr_setschedpolicy(&attr, DEF_SCHED_POLICY);

	pthread_attr_getschedparam(&attr, &param);
	param.sched_priority = DEF_PRIORITY;
	pthread_attr_setschedparam(&attr, &param);

	for (t = 0; t < NUM_THREADS; t++) {
		if (pthread_create(&tid[t], &attr, forward_thread, (void *) &arg[t])) {
			error_printf("forward_create_thread failed\n");
			return -1;
		}
	}

	pthread_attr_destroy(&attr);
	return 0;
}
Exemplo n.º 7
0
static int thread_createwithpriority(pthread_t *tid,int threadpriority,void *(*func)(void *),void *arg)
{
//pthread_t 		tid;
pthread_attr_t 	tattr;
struct sched_param 	param;
int ret;
int newprio = threadpriority;//20;


	// initialized with default attributes
	ret = pthread_attr_init(&tattr);
	// safe to get existing scheduling param
	ret = pthread_attr_getschedparam(&tattr, &param);
	// set the priority; others are unchanged

	//liqapp_log("thread schedparam=%i (current)",param.sched_priority);

	param.sched_priority = newprio;
	// setting the new scheduling param
	ret = pthread_attr_setschedparam(&tattr, &param);
	// with new priority specified

	ret = pthread_create(tid, &tattr, func, arg);


//	ret = pthread_create(tid, NULL, func, arg);
	return ret;
}
Exemplo n.º 8
0
static void
g_thread_create_posix_impl (GThreadFunc thread_func, 
			    gpointer arg, 
			    gulong stack_size,
			    gboolean joinable,
			    gboolean bound,
			    GThreadPriority priority,
			    gpointer thread)
{
  pthread_attr_t attr;

  g_return_if_fail (thread_func);

  posix_check_for_error (pthread_attr_init (&attr));
  
#ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE
  if (stack_size)
    {
      stack_size = MAX (g_thread_min_stack_size, stack_size);
      posix_check_for_error (pthread_attr_setstacksize (&attr, stack_size));
    }
#endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */

#ifdef PTHREAD_SCOPE_SYSTEM
  if (bound)
    /* No error check here, because some systems can't do it and we
     * simply don't want threads to fail because of that. */
    pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
#endif /* PTHREAD_SCOPE_SYSTEM */

#ifdef G_THREADS_IMPL_POSIX
  posix_check_for_error (pthread_attr_setdetachstate (&attr,
          joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED));
#endif /* G_THREADS_IMPL_POSIX */
  
#ifdef HAVE_PRIORITIES
# ifdef G_THREADS_IMPL_POSIX
  {
    struct sched_param sched;
    posix_check_for_error (pthread_attr_getschedparam (&attr, &sched));
    sched.sched_priority = g_thread_map_priority (priority);
    posix_check_for_error (pthread_attr_setschedparam (&attr, &sched));
  }
# else /* G_THREADS_IMPL_DCE */
  posix_check_for_error 
    (pthread_attr_setprio (&attr, g_thread_map_priority (priority)));
# endif /* G_THREADS_IMPL_DCE */
#endif /* HAVE_PRIORITIES */

  posix_check_for_error (pthread_create (thread, &attr, 
                                         (void* (*)(void*))thread_func,
                                         arg));
  
  posix_check_for_error (pthread_attr_destroy (&attr));

#ifdef G_THREADS_IMPL_DCE
  if (!joinable)
    posix_check_for_error (pthread_detach (thread));
#endif /* G_THREADS_IMPL_DCE */
}
Exemplo n.º 9
0
int InitThread(pthread_t *threadId, int prio, void *(*func)(void *), void *param){
	pthread_attr_t attr;
	sched_param sched;

	if(pthread_attr_init(&attr) != EOK)
		return -1;

	if(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != EOK)
		return -1;

	if(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) != EOK)
		return -1;

	if(pthread_attr_setschedpolicy(&attr, SCHED_FIFO) != EOK)
		return -1;

	if(pthread_attr_getschedparam(&attr, &sched) != EOK)
		return -1;

	sched.sched_priority = prio;

 	if(pthread_attr_setschedparam(&attr, &sched) != EOK)
		return -1;


	if(pthread_create(threadId, &attr, func, param) != EOK)
		return -1;

	if(pthread_attr_destroy(&attr) != 0)
		return -1;

	return 1;
}
Exemplo n.º 10
0
void
clone_attributes(pthread_attr_t *new_attr, pthread_attr_t *old_attr)
{
    struct sched_param param;
    void *addr;
    size_t size;
    int value;

    (void) pthread_attr_init(new_attr);

    if (old_attr != NULL) {
        (void) pthread_attr_getstack(old_attr, &addr, &size);
        /* don't allow a non-NULL thread stack address */
        (void) pthread_attr_setstack(new_attr, NULL, size);

        (void) pthread_attr_getscope(old_attr, &value);
        (void) pthread_attr_setscope(new_attr, value);

        (void) pthread_attr_getinheritsched(old_attr, &value);
        (void) pthread_attr_setinheritsched(new_attr, value);

        (void) pthread_attr_getschedpolicy(old_attr, &value);
        (void) pthread_attr_setschedpolicy(new_attr, value);

        (void) pthread_attr_getschedparam(old_attr, &param);
        (void) pthread_attr_setschedparam(new_attr, &param);

        (void) pthread_attr_getguardsize(old_attr, &size);
        (void) pthread_attr_setguardsize(new_attr, size);
    }

    /* make all pool threads be detached threads */
    (void) pthread_attr_setdetachstate(new_attr, PTHREAD_CREATE_DETACHED);
}
Exemplo n.º 11
0
void NONS_Thread::call(NONS_ThreadedFunctionPointer function,void *data,bool give_highest_priority){
	if (this->called)
		return;
	threadStruct *ts=new threadStruct;
	ts->f=function;
	ts->d=data;
#if NONS_SYS_WINDOWS
	this->thread=CreateThread(0,0,(LPTHREAD_START_ROUTINE)runningThread,ts,0,0);
	if (give_highest_priority)
		SetThreadPriority(this->thread,THREAD_PRIORITY_HIGHEST);
#elif NONS_SYS_UNIX
	pthread_attr_t attr,
		*pattr=0;
	if (give_highest_priority){
		pattr=&attr;
		pthread_attr_init(pattr);
		sched_param params;
		pthread_attr_getschedparam(pattr,&params);
		int policy;
		pthread_attr_getschedpolicy(pattr,&policy);
		params.sched_priority=sched_get_priority_max(policy);
		pthread_attr_setschedparam(pattr,&params);
	}
	pthread_create(&this->thread,pattr,runningThread,ts);
	if (give_highest_priority)
		pthread_attr_destroy(pattr);
#elif NONS_SYS_PSP
	this->thread=SDL_CreateThread(runningThread,ts);
#endif
	this->called=1;
}
Exemplo n.º 12
0
int test_schedparam(pthread_attr_t * attr, int prio, int err_number){
	struct sched_param param;
	param.sched_priority = prio;

	errno = 0;
	pthread_attr_setschedparam(attr, &param);
	if ( err_number != errno ){
		if ( errno == 0 ){
			printf("expected errno %d\n", errno);
		} else {
			printf("prio %d ", prio);
			fflush(stdout);
			perror("failed to set");
		}
		return -1;
	}

	if ( errno == 0 ){
		if ( pthread_attr_getschedparam(attr, &param) < 0 ){
			fflush(stdout);
			perror("failed to get");
			return -1;
		}

		if ( param.sched_priority != prio ){
			printf("failed to set/get (%d != %d)\n", param.sched_priority, prio);
			return -1;
		}
	}
	return 0;
}
Exemplo n.º 13
0
int
Thread::getPriority() const
    throw (IllegalThreadStateException)
{
    if(m_thread_state == TIDTHR_ERROR){
        throw IllegalThreadStateException
                ("Thread::getPriority() Invalid Object");
    }

    sched_param param;
    int policy;

    if(m_thread_state != TIDTHR_CREATED) {
        if(pthread_getschedparam(m_thread_id.value(),&policy, &param)) {
            return param.sched_priority;
        }      
    }
    // else the thread is not active, return the Thread creation priority
  
    const pthread_attr_t* attr = 
        (m_thread_attributes == NULL) ?  
            m_thread_group->getAttributes() : m_thread_attributes;

    pthread_attr_getschedparam(attr, &param);

    return param.sched_priority;
}
Exemplo n.º 14
0
static void display_pthread_attr (pthread_attr_t *attr, char *prefix)
{
  int s, i;
  size_t v;
  void *stkaddr;
  struct sched_param sp;

  s = pthread_attr_getdetachstate (attr, &i);
  if (s != 0)
    handle_error_en (s, "pthread_attr_getdetachstate");
  printf ("%sDetach state        = %s\n", prefix,
          (i == PTHREAD_CREATE_DETACHED)
              ? "PTHREAD_CREATE_DETACHED"
              : (i == PTHREAD_CREATE_JOINABLE) ? "PTHREAD_CREATE_JOINABLE"
                                               : "???");

  s = pthread_attr_getscope (attr, &i);
  if (s != 0)
    handle_error_en (s, "pthread_attr_getscope");
  printf ("%sScope               = %s\n", prefix,
          (i == PTHREAD_SCOPE_SYSTEM)
              ? "PTHREAD_SCOPE_SYSTEM"
              : (i == PTHREAD_SCOPE_PROCESS) ? "PTHREAD_SCOPE_PROCESS"
                                             : "???");

  s = pthread_attr_getinheritsched (attr, &i);
  if (s != 0)
    handle_error_en (s, "pthread_attr_getinheritsched");
  printf ("%sInherit scheduler   = %s\n", prefix,
          (i == PTHREAD_INHERIT_SCHED)
              ? "PTHREAD_INHERIT_SCHED"
              : (i == PTHREAD_EXPLICIT_SCHED) ? "PTHREAD_EXPLICIT_SCHED"
                                              : "???");

  s = pthread_attr_getschedpolicy (attr, &i);
  if (s != 0)
    handle_error_en (s, "pthread_attr_getschedpolicy");
  printf ("%sScheduling policy   = %s\n", prefix,
          (i == SCHED_OTHER)
              ? "SCHED_OTHER"
              : (i == SCHED_FIFO) ? "SCHED_FIFO" : (i == SCHED_RR) ? "SCHED_RR"
                                                                   : "???");

  s = pthread_attr_getschedparam (attr, &sp);
  if (s != 0)
    handle_error_en (s, "pthread_attr_getschedparam");
  printf ("%sScheduling priority = %d\n", prefix, sp.sched_priority);

  s = pthread_attr_getguardsize (attr, &v);
  if (s != 0)
    handle_error_en (s, "pthread_attr_getguardsize");
  printf ("%sGuard size          = %ld bytes\n", prefix, v);

  s = pthread_attr_getstack (attr, &stkaddr, &v);
  if (s != 0)
    handle_error_en (s, "pthread_attr_getstack");
  printf ("%sStack address       = %p\n", prefix, stkaddr);
  printf ("%sStack size          = 0x%zx bytes\n", prefix, v);
}
Exemplo n.º 15
0
void test( void )
{
  pthread_attr_t      attr;
  struct sched_param  param;
  int                 result;

  result = pthread_attr_getschedparam( &attr, &param );
}
Exemplo n.º 16
0
static int api_get_thread_priority(pthread_attr_t *attr)
{
	struct sched_param param;
	int rs = pthread_attr_getschedparam(attr, &param);
	assert (rs == 0);
	printf ("priority = %d\n", param.__sched_priority);
	return param.__sched_priority;
}
Exemplo n.º 17
0
int CKFWThread::start( )
{
  int lReturnCode = 0;
  pthread_attr_t lThreadAttribute;
  int lThreadPolicy;
  struct sched_param lThreadScheduleParameters;
  int lError = 0;
  if ( (lError = pthread_attr_init( &lThreadAttribute ) ) != 0 ) {
    throw CKErrNoException( __FILE__, __LINE__, lError );
  }

  if ( (lError = pthread_attr_getschedpolicy( &lThreadAttribute, &lThreadPolicy )) != 0 ) {
    throw CKErrNoException( __FILE__, __LINE__, lError );
  }

  if ( (lError =
        pthread_attr_getschedparam( &lThreadAttribute, &lThreadScheduleParameters)) != 0) {
    throw CKErrNoException( __FILE__, __LINE__, lError );
  }

  pthread_attr_setschedpolicy( &lThreadAttribute, mPolicy );
  pthread_attr_getschedpolicy( &lThreadAttribute, &mPolicy );

  if ( mPriority < 0.0 )
    mPriority = 0.0;
  if ( mPriority > 1.0 )
    mPriority = 1.0;

  int lPriorMax = sched_get_priority_max( mPolicy );
  int lPriorMin = sched_get_priority_min( mPolicy );

  lThreadScheduleParameters.sched_priority = lPriorMin +
    (int)floor( ( lPriorMax - lPriorMin ) *  mPriority );

  pthread_attr_setschedparam( &lThreadAttribute, &lThreadScheduleParameters );

  if ( ( lError = pthread_attr_setscope(&lThreadAttribute, mScope) ) != 0 ) {
    throw CKErrNoException( __FILE__, __LINE__, lError );
  }

  if ( (lError = pthread_create( &mThread,
                                 &lThreadAttribute,
                                 CKFWThread::threadFunction,
                                 this) ) == 0 ) {
    if ( mIsDetachable ) {
      pthread_detach( mThread );
    }

    pthread_attr_destroy( &lThreadAttribute );
  }
  else {
    throw CKErrNoException( __FILE__, __LINE__, lError );
  }

  return lReturnCode;
}
Exemplo n.º 18
0
Arquivo: testpi-3.c Projeto: kraj/ltp
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;
}
Exemplo n.º 19
0
int UavcanServers::start(uavcan::INode &main_node)
{
	if (_instance != nullptr) {
		warnx("Already started");
		return -1;
	}

	/*
	 * Node init
	 */
	_instance = new UavcanServers(main_node);

	if (_instance == nullptr) {
		warnx("Out of memory");
		return -2;
	}

	int rv  = _instance->init();

	if (rv < 0) {
		warnx("Node init failed: %d", rv);
		delete _instance;
		_instance = nullptr;
		return rv;
	}

	/*
	 * Start the thread. Normally it should never exit.
	 */
	pthread_attr_t tattr;
	struct sched_param param;

	pthread_attr_init(&tattr);
	(void)pthread_attr_getschedparam(&tattr, &param);
	tattr.stacksize = PX4_STACK_ADJUSTED(StackSize);
	param.sched_priority = Priority;
	if (pthread_attr_setschedparam(&tattr, &param)) {
		warnx("setting sched params failed");
	}

	static auto run_trampoline = [](void *) {return UavcanServers::_instance->run(_instance);};

	rv = pthread_create(&_instance->_subnode_thread, &tattr, static_cast<pthread_startroutine_t>(run_trampoline), NULL);

	if (rv != 0) {
		rv = -rv;
		warnx("pthread_create() failed: %d", rv);
		delete _instance;
		_instance = nullptr;
	}

	return rv;
}
Exemplo n.º 20
0
CThread::CThread(IRunnable *runner) :
		_runner(runner), _mutex(), _cond(),	_tid(0), _tattr(), _tpoli(0),
		_tparm(), _running(false), _finished(false), _canceled(false)
{
	int e;
	if ((e = pthread_attr_init(&_tattr)) != 0)
		throw XThread(e);
	if ((e = pthread_attr_getschedpolicy(&_tattr, &_tpoli)) != 0)
		throw XThread(e);
	if ((e = pthread_attr_getschedparam(&_tattr, &_tparm)) != 0)
		throw XThread(e);
}
Exemplo n.º 21
0
/**
 * Get current priority setting.
 */
int CThread::priority()
{
	if (isRunning()) {
		int e;
		if ((e = pthread_getschedparam(_tid, &_tpoli, &_tparm)) != 0)
			throw XThread(e);
	} else {
		int e;
		if ((e = pthread_attr_getschedparam(&_tattr, &_tparm)) != 0)
			throw XThread(e);
	}
	return _tparm.sched_priority;
}
Exemplo n.º 22
0
int
dcethread_attr_getprio(dcethread_attr* attr)
{
    struct sched_param sp;
    
    if (dcethread__set_errno(pthread_attr_getschedparam(attr, &sp)))
    {
	return -1;
    }
    else
    {
	return sp.sched_priority;
    }
}
Exemplo n.º 23
0
int main (int argc, char **argv) {
    signal(SIGPIPE, SIG_IGN);
    struct event_base *base = event_base_new();

    const char *hostname = (argc > 1) ? argv[1] : "127.0.0.1";
    int port = (argc > 2) ? atoi(argv[2]) : 6379;
    const char *subname = (argc > 3) ? argv[3] : "test";

    redisAsyncContext *c = redisAsyncConnect(hostname, port);
    if (c->err) {
        /* Let *c leak for now... */
        printf("Error: %s\n", c->errstr);
        return 1;
    }

    g_yuv_size = 1920*1080*3/2;
    g_yuv = malloc(g_yuv_size);
    start_time = time((time_t*)NULL);
    now_time = time((time_t*)NULL);


    // init pipe
    if(pipe(pipe_fd)){
        printf("pipe error\n");
        return -1;
    }

    // create thread
    pthread_attr_t attr;
    struct sched_param param;
    pthread_t tsk_id;

    pthread_attr_init(&attr);
    pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
    pthread_attr_getschedparam(&attr, &param);
     
    pthread_create(&tsk_id, &attr, (void *)thread_function, NULL);



    // event
    redisLibeventAttach(c,base);
    redisAsyncSetConnectCallback(c,connectCallback);
    redisAsyncSetDisconnectCallback(c,disconnectCallback);
    redisAsyncCommand(c, subCallback, (char*) "sub", "SMEMSUBSCRIBE %s", subname);

    event_base_dispatch(base);
    return 0;
}
Exemplo n.º 24
0
/*************************************************
  * Function:		Pthread_attr_getschedparam()
  * Description:    获取线程调度参数包裹函数 
  * Input:          *attr---线程属性结构 
  * Output:         *param---线程调度参数 
  * Return:         0/errno 
*************************************************/
int Pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param * param)
{
	int rval;

	if(attr==AII_NULL || param==AII_NULL)
	{
		return -1;	
	}

	if((rval = pthread_attr_getschedparam(attr, param)) != 0)
	{
		debug_info(DEBUG_LEVEL_4,"Pthread_attr_getschedparam() failed!\n");
	}

	return rval;
}
Exemplo n.º 25
0
int pthread_attr_init_ex(pthread_attr_ex_t *attr_ex)
{
	struct sched_param param;
	int policy;

	/* Start with defaulting all fields to null. */
	memset(attr_ex, 0, sizeof(*attr_ex));
	/* Merge in the default standard attribute set. */
	pthread_attr_init(&attr_ex->std);
	pthread_attr_getschedpolicy(&attr_ex->std, &policy);
	attr_ex->nonstd.sched_policy = policy;
	pthread_attr_getschedparam(&attr_ex->std, &param);
	attr_ex->nonstd.sched_param.sched_priority = param.sched_priority;

	return 0;
}
Exemplo n.º 26
0
SWITCH_DECLARE(switch_status_t) switch_threadattr_priority_increase(switch_threadattr_t *attr)
{
	int stat = 0;
#ifndef WIN32
	struct sched_param param;
	struct apr_threadattr_t *myattr = attr;

	pthread_attr_getschedparam(&myattr->attr, &param);
	param.sched_priority = 50;
	stat = pthread_attr_setschedparam(&myattr->attr, &param);

	if (stat == 0) {
		return SWITCH_STATUS_SUCCESS;
	}
#endif
	return stat;
}
BOOL clsCMM::StartInputThread(int priority)
{
    pthread_attr_t attribute;
    pthread_attr_init(&attribute);
    pthread_attr_setdetachstate(&attribute, PTHREAD_CREATE_DETACHED);
    pthread_attr_setinheritsched(&attribute, PTHREAD_EXPLICIT_SCHED);
    pthread_attr_setschedpolicy(&attribute, SCHED_RR);

    sched_param_t param;
    pthread_attr_getschedparam(&attribute, &param);
    param.sched_priority = priority;
    pthread_attr_setschedparam(&attribute, &param);

    pthread_create(&m_idInputThread, &attribute, &clsCMM::InputThread, this);

    return TRUE;
}
Exemplo n.º 28
0
/*
 * Initialize joinFS.
 */
static void * 
jfs_init(struct fuse_conn_info *conn)
{
  struct sched_param param;
  pthread_attr_t wattr;

  log_init();
  log_msg("Starting joinFS. FUSE Major=%d Minor=%d\n",
          conn->proto_major, conn->proto_minor);

  /* initialize caches */
  jfs_dynamic_path_init();
  jfs_datapath_cache_init();
  jfs_key_cache_init();
  jfs_meta_cache_init();
  jfs_init_db();

  jfs_read_pool = jfs_pool_create(JFS_THREAD_MIN, JFS_THREAD_MAX, 
								  JFS_THREAD_LINGER, NULL, 
								  SQLITE_OPEN_READONLY);
  if(!jfs_read_pool) {
	log_error("Failed to allocate READ pool.\n");
    log_destroy();

	exit(EXIT_FAILURE);
  }

  pthread_attr_init(&wattr);
  pthread_attr_setschedpolicy(&wattr, SCHED_RR);
  pthread_attr_getschedparam(&wattr, &param);
  param.sched_priority = 1;
  pthread_attr_setschedparam(&wattr, &param);

  jfs_write_pool = jfs_pool_create(1, 1, JFS_THREAD_LINGER, 
								   &wattr, SQLITE_OPEN_READWRITE);
  if(!jfs_write_pool) {
	log_error("Failed to allocate WRITE pool.\n");
    log_destroy();

	exit(EXIT_FAILURE);
  }
  
  log_msg("joinFS Thread pools started.\n");
  
  return NULL;
}
Exemplo n.º 29
0
static void uio_init_interrupt()
{
	pthread_attr_t pthread_attr;
	struct sched_param sched_param;

	memset(&uio_int, 0, sizeof(uio_int));
	/* Create LSR thread */
	pthread_attr_init(&pthread_attr);
	pthread_attr_setdetachstate(&pthread_attr, PTHREAD_CREATE_JOINABLE);/* Joinable for main thread */
	pthread_attr_setscope(&pthread_attr, PTHREAD_SCOPE_SYSTEM);			/* Real time */
	pthread_attr_getschedparam(&pthread_attr, &sched_param);
	sched_param.sched_priority = 90;//OSAL_PRI_IRQ;							/* Highest priority */
	pthread_attr_setschedparam(&pthread_attr, &sched_param);
	pthread_attr_setschedpolicy(&pthread_attr, SCHED_FIFO);				/* FIFO */
	pthread_create(&dec_thread, &pthread_attr, &uio_int_thread, NULL);
	pthread_attr_destroy(&pthread_attr);
	printf("uio_init_interrupt: PPID: 0x%08x -> PID: %d\n", pthread_self(), dec_thread);
}
Exemplo n.º 30
0
void *open_watch_dog(void)
{
    pthread_attr_t thread_attr;
    struct sched_param thread_params;
    dog_t *dog_param = (dog_t *)calloc(1, sizeof(dog_t));
    if(NULL == dog_param)
    {
        OMXDBUG(OMXDBUG_ERR, "alloc failed!\n");
        return NULL;
    }

    dog_param->stat = WDOG_IDLE;
    pthread_mutex_init(&dog_param->cmd_mutex, NULL);

    pthread_attr_init(&thread_attr);
    //pthread_attr_setschedpolicy(&thread_attr, SCHED_RR);
    pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);
    pthread_attr_getschedparam(&thread_attr, &thread_params);
    thread_params.sched_priority = (int) - 9;
    pthread_attr_setschedparam(&thread_attr, &thread_params);
    pthread_create(&dog_param->thread_loop, NULL/*&thread_attr*/, watch_dog_loop, dog_param);

    // performance test
    {
//	        long long t0 = get_current_time();
//	        long long t1;
//	        int loop_cnt = 1000;
//	        while(loop_cnt--)
//	        { get_current_time(); }
//	        t1 = get_current_time();
//	        OMXDBUG(OMXDBUG_PARAM, "watch dog performance: %lld!\n", t1 - t0);

//	        double t0 = now_ms();
//	        double t1;
//	        int loop_cnt = 1000;
//	        while(loop_cnt--)
//	        { now_ms(); }
//	        t1 = now_ms();
//	        OMXDBUG(OMXDBUG_PARAM, "watch dog performance: %g ms!\n", t1 - t0);
    }

    OMXDBUG(OMXDBUG_PARAM, "watch dog opened!\n");
    return (void *)dog_param;
}