Enhanced registry.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8939 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
54e8a6c9e2
commit
5181b1e391
|
@ -1318,8 +1318,12 @@ int32 OS_TaskInstallDeleteHandler(void *function_pointer) {
|
|||
* @api
|
||||
*/
|
||||
int32 OS_TaskDelete(uint32 task_id) {
|
||||
thread_t *tp = (thread_t *)task_id;
|
||||
|
||||
(void)task_id;
|
||||
/* Check for thread validity.*/
|
||||
if (chRegFindThreadByPointer(tp) == NULL) {
|
||||
return OS_ERR_INVALID_ID;
|
||||
}
|
||||
|
||||
return OS_ERR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
@ -1361,6 +1365,11 @@ int32 OS_TaskSetPriority (uint32 task_id, uint32 new_priority) {
|
|||
tprio_t rt_newprio;
|
||||
thread_t *tp = (thread_t *)task_id;
|
||||
|
||||
/* Check for thread validity.*/
|
||||
if (chRegFindThreadByPointer(tp) == NULL) {
|
||||
return OS_ERR_INVALID_ID;
|
||||
}
|
||||
|
||||
/* Checking priority range.*/
|
||||
if ((new_priority < MIN_PRIORITY) || (new_priority > MAX_PRIORITY)) {
|
||||
return OS_ERR_INVALID_PRIORITY;
|
||||
|
@ -1373,8 +1382,6 @@ int32 OS_TaskSetPriority (uint32 task_id, uint32 new_priority) {
|
|||
return OS_SUCCESS;
|
||||
}
|
||||
|
||||
/* TODO: Check presence in registry.*/
|
||||
|
||||
chSysLock();
|
||||
|
||||
/* Changing priority.*/
|
||||
|
@ -1464,21 +1471,17 @@ int32 OS_TaskGetIdByName (uint32 *task_id, const char *task_name) {
|
|||
return OS_ERR_NAME_TOO_LONG;
|
||||
}
|
||||
|
||||
/* TODO: Check presence in registry.*/
|
||||
|
||||
/* Scanning registry.*/
|
||||
tp = chRegFirstThread();
|
||||
do {
|
||||
if (strcmp(chRegGetThreadNameX(tp), task_name) == 0) {
|
||||
*task_id = (uint32)tp;
|
||||
return OS_SUCCESS;
|
||||
}
|
||||
tp = chRegNextThread(tp);
|
||||
} while (tp != NULL);
|
||||
|
||||
/* Searching in the registry.*/
|
||||
tp = chRegFindThreadByName(task_name);
|
||||
if (tp == NULL) {
|
||||
return OS_ERR_NAME_NOT_FOUND;
|
||||
}
|
||||
|
||||
*task_id = (uint32)tp;
|
||||
|
||||
return OS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns task information.
|
||||
* @note This function can be safely called from timer callbacks or ISRs.
|
||||
|
@ -1494,13 +1497,16 @@ int32 OS_TaskGetInfo(uint32 task_id, OS_task_prop_t *task_prop) {
|
|||
thread_t *tp = (thread_t *)task_id;
|
||||
size_t wasize = (size_t)tp - (size_t)tp->stklimit + sizeof (thread_t);
|
||||
|
||||
/* Check for thread validity.*/
|
||||
if (chRegFindThreadByPointer(tp) == NULL) {
|
||||
return OS_ERR_INVALID_ID;
|
||||
}
|
||||
|
||||
/* NULL pointer checks.*/
|
||||
if (task_prop == NULL) {
|
||||
return OS_INVALID_POINTER;
|
||||
}
|
||||
|
||||
/* TODO: Check presence in registry.*/
|
||||
|
||||
strncpy(task_prop->name, tp->name, OS_MAX_API_NAME - 1);
|
||||
task_prop->creator = (uint32)chSysGetIdleThreadX();
|
||||
task_prop->stack_size = (uint32)MEM_ALIGN_NEXT(wasize, PORT_STACK_ALIGN);
|
||||
|
|
|
@ -108,6 +108,8 @@ extern "C" {
|
|||
extern ROMCONST chdebug_t ch_debug;
|
||||
thread_t *chRegFirstThread(void);
|
||||
thread_t *chRegNextThread(thread_t *tp);
|
||||
thread_t *chRegFindThreadByName(const char *name);
|
||||
thread_t *chRegFindThreadByPointer(thread_t *tp);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -44,6 +44,9 @@
|
|||
* option must be enabled in @p chconf.h.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "ch.h"
|
||||
|
||||
#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
|
||||
|
@ -160,6 +163,53 @@ thread_t *chRegNextThread(thread_t *tp) {
|
|||
return ntp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Retrieves a thread pointer by name.
|
||||
*
|
||||
* @param[in] name the thread name
|
||||
* @return A pointer to the found thread.
|
||||
* @retval NULL if a matching thread has not been found.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
thread_t *chRegFindThreadByName(const char *name) {
|
||||
thread_t *ctp;
|
||||
|
||||
/* Scanning registry.*/
|
||||
ctp = chRegFirstThread();
|
||||
do {
|
||||
if (strcmp(chRegGetThreadNameX(ctp), name) == 0) {
|
||||
return ctp;
|
||||
}
|
||||
ctp = chRegNextThread(ctp);
|
||||
} while (ctp != NULL);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif /* CH_CFG_USE_REGISTRY == TRUE */
|
||||
|
||||
/**
|
||||
* @brief Confirms that a pointer is a valid thread pointer.
|
||||
*
|
||||
* @param[in] tp pointer to the thread
|
||||
* @return A pointer to the found thread.
|
||||
* @retval NULL if a matching thread has not been found.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
thread_t *chRegFindThreadByPointer(thread_t *tp) {
|
||||
thread_t *ctp;
|
||||
|
||||
/* Scanning registry.*/
|
||||
ctp = chRegFirstThread();
|
||||
do {
|
||||
if (ctp == tp) {
|
||||
return ctp;
|
||||
}
|
||||
ctp = chRegNextThread(ctp);
|
||||
} while (ctp != NULL);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -25,6 +25,7 @@ a series of important new features.
|
|||
- Ability to use the new shared RTOS components.
|
||||
- Enhanced trace buffer, it is able to store events regarding not just threads
|
||||
but also IRQs, halts and user events.
|
||||
- Enhanced Registry, it is now possible to find threads by name or by pointer.
|
||||
- Simplified the dynamic threading model, now it is the thread creator
|
||||
responsible for memory release, the references counter has been removed
|
||||
and the code is much simpler.
|
||||
|
|
Loading…
Reference in New Issue