From 5181b1e391f3480d375a484fb55e70fd5586a5d1 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Wed, 24 Feb 2016 10:28:43 +0000 Subject: Enhanced registry. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8939 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/src/chregistry.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'os/rt/src') diff --git a/os/rt/src/chregistry.c b/os/rt/src/chregistry.c index 07185d331..944383bf1 100644 --- a/os/rt/src/chregistry.c +++ b/os/rt/src/chregistry.c @@ -44,6 +44,9 @@ * option must be enabled in @p chconf.h. * @{ */ + +#include + #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; +} + /** @} */ -- cgit v1.2.3