⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pthreadlib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
* Other, non-realtime scheduling.* .LP** VxWorks only supports SCHED_RR and SCHED_FIFO.** RETURNS: On success zero; on failure a non-zero error code.** ERRNOS: 'EINVAL'** SEE ALSO:* schedPxLib,* pthread_attr_getschedpolicy(),* pthread_attr_init(),* pthread_attr_setinheritsched(),* pthread_getschedparam(),* pthread_setschedparam(),* sched_setscheduler(),* sched_getscheduler()*/int pthread_attr_setschedpolicy    (    pthread_attr_t *pAttr,		/* thread attributes	*/    int policy				/* new policy		*/    )    {    if (!pAttr || pAttr->threadAttrStatus != PTHREAD_INITIALIZED ||	(policy != SCHED_OTHER &&	policy != SCHED_FIFO &&	policy != SCHED_RR))	{	return (EINVAL);	}    pAttr->threadAttrSchedpolicy = policy;    return (_RETURN_PTHREAD_SUCCESS);    }/********************************************************************************* pthread_attr_getschedpolicy - get schedpolicy attribute from thread attributes object (POSIX)** This routine returns, via the pointer <pPolicy>, the current scheduling* policy in the thread attributes object specified by <pAttr>. Possible values* for VxWorks systems are SCHED_RR and SCHED_FIFO; SCHED_OTHER is not* supported.** RETURNS: On success zero; on failure a non-zero error code.** ERRNOS: 'EINVAL'** SEE ALSO:* schedPxLib,* pthread_attr_init(),* pthread_attr_setschedpolicy(),* pthread_getschedparam(),* pthread_setschedparam(),* sched_setscheduler(),* sched_getscheduler()*/int pthread_attr_getschedpolicy    (    const pthread_attr_t *pAttr,	/* thread attributes	*/    int *pPolicy			/* current policy (out)	*/    )    {    if (!pAttr || pAttr->threadAttrStatus != PTHREAD_INITIALIZED)	return (EINVAL);    *pPolicy = pAttr->threadAttrSchedpolicy;    return (_RETURN_PTHREAD_SUCCESS);    }/********************************************************************************* pthread_attr_setschedparam - set schedparam attribute in thread attributes object (POSIX)** Set the scheduling parameters in the thread attributes object <pAttr>.* The scheduling parameters are essentially the thread's priority.** RETURNS: On success zero; on failure a non-zero error code.** ERRNOS: 'EINVAL'** SEE ALSO:* schedPxLib,* pthread_attr_getschedparam(),* pthread_attr_init(),* pthread_getschedparam(),* pthread_setschedparam(),* sched_getparam(),* sched_setparam()*/int pthread_attr_setschedparam    (    pthread_attr_t *pAttr,		/* thread attributes	*/    const struct sched_param *pParam	/* new parameters	*/    )    {    int policy;    int priority;    if (!pAttr || pAttr->threadAttrStatus != PTHREAD_INITIALIZED || !pParam)	return (EINVAL);    policy = pAttr->threadAttrSchedpolicy;    if (!VALID_PRIORITY(pParam->sched_priority))	return (EINVAL);    else	priority = pParam->sched_priority;    pAttr->threadAttrSchedparam.sched_priority = priority;    return (_RETURN_PTHREAD_SUCCESS);    }/********************************************************************************* pthread_attr_getschedparam - get value of schedparam attribute from thread attributes object (POSIX)** Return, via the pointer <pParam>, the current scheduling parameters from the* thread attributes object <pAttr>.** RETURNS: On success zero; on failure a non-zero error code.** ERRNOS: 'EINVAL'** SEE ALSO:* schedPxLib,* pthread_attr_init(),* pthread_attr_setschedparam(),* pthread_getschedparam(),* pthread_setschedparam(),* sched_getparam(),* sched_setparam()*/int pthread_attr_getschedparam    (    const pthread_attr_t *pAttr,	/* thread attributes		*/    struct sched_param *pParam		/* current parameters (out)	*/    )    {    if (!pAttr || pAttr->threadAttrStatus != PTHREAD_INITIALIZED || !pParam)	return (EINVAL);    pParam->sched_priority = pAttr->threadAttrSchedparam.sched_priority;    return (_RETURN_PTHREAD_SUCCESS);    }/********************************************************************************* pthread_getschedparam - get value of schedparam attribute from a thread (POSIX)** This routine reads the current scheduling parameters and policy of the thread* specified by <thread>. The information is returned via <pPolicy> and* <pParam>.** RETURNS: On success zero; on failure a non-zero error code.** ERRNOS: 'ESRCH'** SEE ALSO:* schedPxLib,* pthread_attr_getschedparam()* pthread_attr_getschedpolicy()* pthread_attr_setschedparam()* pthread_attr_setschedpolicy()* pthread_setschedparam(),* sched_getparam(),* sched_setparam()*/int pthread_getschedparam    (    pthread_t thread,			/* thread			*/    int *pPolicy,			/* current policy (out)		*/    struct sched_param *pParam		/* current parameters (out)	*/    )    {    internalPthread *	pThread = (internalPthread *)thread;    WIND_TCB *		pTcb;    BOOL		roundRobinOn;    if (!VALID_PTHREAD(pThread, pTcb))	return (ESRCH);    roundRobinOn = _schedPxKernelIsTimeSlicing (NULL);    if (roundRobinOn == TRUE)	*pPolicy = SCHED_RR;    else	*pPolicy = SCHED_FIFO;    return (sched_getparam((pid_t)pThread->taskId, pParam) != 0 ? errno : 0);    }/********************************************************************************* pthread_setschedparam - dynamically set schedparam attribute for a thread (POSIX)** This routine will set the scheduling parameters (<pParam>) and policy* (<policy>) for the thread specified by <thread>.** In VxWorks the scheduling policy is global and not* set on a per-thread basis; if the selected policy does not match the* current global setting then this function will return an error ('EINVAL').** RETURNS: On success zero; on failure a non-zero error code.** ERRNOS: 'EINVAL', 'ESRCH'** SEE ALSO:* schedPxLib,* pthread_attr_getschedparam()* pthread_attr_getschedpolicy()* pthread_attr_setschedparam()* pthread_attr_setschedpolicy()* pthread_getschedparam(),* sched_getparam(),* sched_setparam()*/int pthread_setschedparam    (    pthread_t thread,			/* thread		*/    int policy,				/* new policy		*/    const struct sched_param *pParam	/* new parameters	*/    )    {    internalPthread *pThread = (internalPthread *)thread;    WIND_TCB *pTcb;    if (!VALID_PTHREAD(pThread, pTcb))	return (ESRCH);    return (sched_setscheduler((pid_t)pThread->taskId, policy, pParam) != 0 ?	    errno : 0);    }/* * Section 16 - Thread Management *//********************************************************************************* pthread_attr_init - initialize thread attributes object (POSIX)** DESCRIPTION** This routine initializes a thread attributes object. If <pAttr> is NULL* then this function will return EINVAL.** The attributes that are set by default are as follows:* .iP "'Stack Address'" 4* NULL - allow the system to allocate the stack.* .iP "'Stack Size'"* 0 - use the VxWorks taskLib default stack size.* .iP "'Detach State'"* PTHREAD_CREATE_JOINABLE* .iP "'Contention Scope'"* PTHREAD_SCOPE_SYSTEM* .iP "'Scheduling Inheritance'"* PTHREAD_INHERIT_SCHED* .iP "'Scheduling Policy'"* SCHED_RR* .iP "'Scheduling Priority'"* Use pthreadLib default priority* .LP** Note that the scheduling policy and priority values are only used if the* scheduling inheritance mode is changed to PTHREAD_EXPLICIT_SCHED - see* pthread_attr_setinheritsched() for information.** RETURNS: On success zero; on failure a non-zero error code.** ERRNOS: 'EINVAL'** SEE ALSO:* pthread_attr_destroy(),* pthread_attr_getdetachstate(),* pthread_attr_getinheritsched(),* pthread_attr_getschedparam(),* pthread_attr_getschedpolicy(),* pthread_attr_getscope(),* pthread_attr_getstackaddr(),* pthread_attr_getstacksize(),* pthread_attr_setdetachstate(),* pthread_attr_setinheritsched(),* pthread_attr_setschedparam(),* pthread_attr_setschedpolicy(),* pthread_attr_setscope(),* pthread_attr_setstackaddr(),* pthread_attr_setstacksize()*/int pthread_attr_init    (    pthread_attr_t *pAttr		/* thread attributes */    )    {    if (!pAttr)	return (EINVAL);    /* not a POSIX error return */    pAttr->threadAttrStackaddr			= NULL;    pAttr->threadAttrStacksize			= ((size_t) 0);    pAttr->threadAttrDetachstate		= PTHREAD_CREATE_JOINABLE;    pAttr->threadAttrContentionscope		= PTHREAD_SCOPE_SYSTEM;    pAttr->threadAttrInheritsched		= PTHREAD_INHERIT_SCHED;    pAttr->threadAttrSchedpolicy		= SCHED_RR;    pAttr->threadAttrSchedparam.sched_priority	= DEF_PRIORITY;    pAttr->threadAttrStatus			= PTHREAD_INITIALIZED;    pAttr->threadAttrName                       = NULL;    return (_RETURN_PTHREAD_SUCCESS);    }/********************************************************************************* pthread_attr_destroy - destroy a thread attributes object (POSIX)** Destroy the thread attributes object <pAttr>. It should not be re-used until* it has been reinitialized.** RETURNS: On success zero; on failure a non-zero error code.** ERRNOS: 'EINVAL'** SEE ALSO:* pthread_attr_init()*/int pthread_attr_destroy    (    pthread_attr_t *pAttr		/* thread attributes */    )    {    if (!pAttr)	return (EINVAL);    /* not a POSIX specified error return */    pAttr->threadAttrStatus = PTHREAD_DESTROYED;    return (_RETURN_PTHREAD_SUCCESS);    }/********************************************************************************* pthread_attr_setname - set name in thread attribute object** This routine sets the name in the specified thread attributes object, <pAttr>.** RETURNS: Always returns ** ERRNOS: None.** SEE ALSO:* pthread_attr_getname(),*/int pthread_attr_setname    (    pthread_attr_t *pAttr,    char *name    )    {    pAttr->threadAttrName = name;    return (_RETURN_PTHREAD_SUCCESS);    }/********************************************************************************* pthread_attr_getname - get name of thread attribute object** This routine gets the name in the specified thread attributes object, <pAttr>.** RETURNS: Always returns zero** ERRNOS: None.** SEE ALSO:* pthread_attr_setname(),*/int pthread_attr_getname    (    pthread_attr_t *pAttr,    char **name    )    {    if (pAttr->threadAttrName == NULL)	*name = "";    else	*name = pAttr->threadAttrName;        return (_RETURN_PTHREAD_SUCCESS);    }/********************************************************************************* pthread_attr_setstacksize - set stacksize attribute in thread attributesobject (POSIX)** This routine sets the thread stack size in the specified thread attributes* object, <pAttr>.** RETURNS: Always returns zero.** ERRNOS: None.** SEE ALSO:* pthread_attr_getstacksize(),* pthread_attr_init()*/int pthread_attr_setstacksize    (    pthread_attr_t *pAttr,		/* thread attributes	*/    size_t stacksize			/* new stack size	*/    )    {    pAttr->threadAttrStacksize = stacksize;    return (_RETURN_PTHREAD_SUCCESS);    }/********************************************************************************* pthread_attr_getstacksize - get stack value of stacksize attribute from thread attributes object (POSIX)** This routine gets the current stack size from the thread attributes object* <pAttr> and places it in the location pointed to by <pStacksize>.** RETURNS: Always returns zero.** ERRNOS: None.** SEE ALSO:* pthread_attr_init(),* pthread_attr_setstacksize()*/int pthread_attr_getstacksize    (    const pthread_attr_t *pAttr,	/* thread attributes		*/    size_t *pStacksize			/* current stack size (out)	*/    )    {    *pStacksize = pAttr->threadAttrStacksize;    return (_RETURN_PTHREAD_SUCCESS);    }/********************************************************************************* pthread_attr_setstackaddr - set stackaddr attribute in thread attributes object (POSIX)** This routine sets the stack address in the thread attributes object <pAttr>* to be <pStackaddr>.** It is important to note that the size of this stack must be large enough* to also include the task's TCB.  The size of the TCB varies from architecture* to architecture 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -