summaryrefslogtreecommitdiff
path: root/nuttx/sched/sem_holder.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-03-13 22:35:23 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-03-13 22:35:23 +0000
commit4735875000348485d80c093c9af83d3029a21bc6 (patch)
treefd06f80b324ecb232a912057c58e370603a154b3 /nuttx/sched/sem_holder.c
parent145f2bf35bfc0e1dabae83cb78413483b01ede0b (diff)
downloadpx4-nuttx-4735875000348485d80c093c9af83d3029a21bc6.tar.gz
px4-nuttx-4735875000348485d80c093c9af83d3029a21bc6.tar.bz2
px4-nuttx-4735875000348485d80c093c9af83d3029a21bc6.zip
Add debug instrumentation; fix pholder freeing logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1599 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched/sem_holder.c')
-rw-r--r--nuttx/sched/sem_holder.c75
1 files changed, 74 insertions, 1 deletions
diff --git a/nuttx/sched/sem_holder.c b/nuttx/sched/sem_holder.c
index 1388965be..74f83837e 100644
--- a/nuttx/sched/sem_holder.c
+++ b/nuttx/sched/sem_holder.c
@@ -251,6 +251,7 @@ static int sem_foreachholder(FAR sem_t *sem, holderhandler_t handler, FAR void *
static int sem_recoverholders(struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg)
{
sem_freeholder(sem, pholder);
+ return 0;
}
/****************************************************************************
@@ -377,6 +378,23 @@ static int sem_verifyholder(struct semholder_s *pholder, FAR sem_t *sem, FAR voi
#endif
/****************************************************************************
+ * Name: sem_dumpholder
+ ****************************************************************************/
+
+#if defined(CONFIG_DEBUG) && defined(CONFIG_SEM_PHDEBUG)
+static int sem_dumpholder(struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg)
+{
+#if CONFIG_SEM_PREALLOCHOLDERS > 0
+ dbg(" %08x: %08x %08x %04x\n",
+ pholder, pholder->flink, pholder->holder, pholder->counts);
+#else
+ dbg(" %08x: %08x %04x\n", pholder, pholder->holder, pholder->counts);
+#endif
+ return 0;
+}
+#endif
+
+/****************************************************************************
* Name: sem_restoreholderprio
****************************************************************************/
@@ -759,7 +777,7 @@ void sem_restorebaseprio(FAR _TCB *stcb, FAR sem_t *sem)
* Description:
* Called from sem_post() after a thread that was waiting for a semaphore
* count was awakened because of a signal and the semaphore wait has been
- * canceld.
+ * canceled.
*
* Parameters:
* sem - A reference to the semaphore no longer being waited for
@@ -784,4 +802,59 @@ void sem_canceled(FAR sem_t *sem)
(void)sem_foreachholder(sem, sem_restoreholderprio, rtcb);
}
+/****************************************************************************
+ * Function: sem_enumholders
+ *
+ * Description:
+ * Show information about threads currently waiting on this semaphore
+ *
+ * Parameters:
+ * sem - A reference to the semaphore
+ *
+ * Return Value:
+ * None
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_DEBUG) && defined(CONFIG_SEM_PHDEBUG)
+void sem_enumholders(FAR sem_t *sem)
+{
+ (void)sem_foreachholder(sem, sem_dumpholder, NULL);
+}
+#endif
+
+/****************************************************************************
+ * Function: sem_nfreeholders
+ *
+ * Description:
+ * Return the number of available holder containers. This is a good way
+ * to find out which threads are not calling sem_destroy.
+ *
+ * Parameters:
+ * sem - A reference to the semaphore
+ *
+ * Return Value:
+ * The number of available holder containers
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_DEBUG) && defined(CONFIG_SEM_PHDEBUG)
+int sem_nfreeholders(void)
+{
+#if CONFIG_SEM_PREALLOCHOLDERS > 0
+ FAR struct semholder_s *pholder;
+ int n;
+
+ for (pholder = g_freeholders, n = 0; pholder; pholder = pholder->flink) n++;
+ return n;
+#else
+ return 0;
+#endif
+}
+#endif
+
#endif /* CONFIG_PRIORITY_INHERITANCE */