summaryrefslogtreecommitdiff
path: root/nuttx/examples
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/examples
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/examples')
-rw-r--r--nuttx/examples/ostest/main.c4
-rw-r--r--nuttx/examples/ostest/ostest.h20
-rw-r--r--nuttx/examples/ostest/prioinherit.c12
3 files changed, 36 insertions, 0 deletions
diff --git a/nuttx/examples/ostest/main.c b/nuttx/examples/ostest/main.c
index 9e2ad02c0..261f7974b 100644
--- a/nuttx/examples/ostest/main.c
+++ b/nuttx/examples/ostest/main.c
@@ -155,6 +155,10 @@ static void check_test_memory_usage(void)
#else
memcpy(&g_mmprevious, &g_mmafter, sizeof(struct mallinfo));
#endif
+
+ /* If so enabled, show the use of priority inheritance resources */
+
+ dump_nfreeholders("user_main:");
}
#else
# define check_test_memory_usage()
diff --git a/nuttx/examples/ostest/ostest.h b/nuttx/examples/ostest/ostest.h
index 8c71906c5..1cd705898 100644
--- a/nuttx/examples/ostest/ostest.h
+++ b/nuttx/examples/ostest/ostest.h
@@ -71,6 +71,14 @@
# define CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS 8
#endif
+/* Priority inheritance */
+
+#if defined(CONFIG_DEBUG) && defined(CONFIG_PRIORITY_INHERITANCE) && defined(CONFIG_SEM_PHDEBUG)
+# define dump_nfreeholders(s) printf(s " nfreeholders: %d\n", sem_nfreeholders())
+#else
+# define dump_nfreeholders(s)
+#endif
+
/****************************************************************************
* Public Types
****************************************************************************/
@@ -139,4 +147,16 @@ extern void barrier_test(void);
extern void priority_inheritance(void);
+/* APIs exported (conditionally) by the OS specifically for testing of
+ * priority inheritance
+ */
+
+#if defined(CONFIG_DEBUG) && defined(CONFIG_PRIORITY_INHERITANCE) && defined(CONFIG_SEM_PHDEBUG)
+extern void sem_enumholders(FAR sem_t *sem);
+extern int sem_nfreeholders(void);
+#else
+# define sem_enumholders(sem)
+# define sem_nfreeholders()
+#endif
+
#endif /* __OSTEST_H */
diff --git a/nuttx/examples/ostest/prioinherit.c b/nuttx/examples/ostest/prioinherit.c
index 92238a8c2..7f392b27a 100644
--- a/nuttx/examples/ostest/prioinherit.c
+++ b/nuttx/examples/ostest/prioinherit.c
@@ -269,6 +269,7 @@ static void *lowpri_thread(void *parameter)
printf(" g_highstate[%d]: %d\n", i, (int)g_highstate[i]);
}
printf(" I still have a count on the semaphore\n");
+ sem_enumholders(&g_sem);
fflush(stdout);
sleep(1);
}
@@ -308,6 +309,7 @@ static void *lowpri_thread(void *parameter)
}
ret = pthread_getschedparam(pthread_self(), &policy, &sparam);
+ sem_enumholders(&g_sem);
sem_post(&g_sem);
if (ret != 0)
{
@@ -352,6 +354,7 @@ static void *lowpri_thread(void *parameter)
printf(" ERROR should have been %d\n", g_lowpri);
}
}
+ sem_enumholders(&g_sem);
printf("lowpri_thread-%d: Okay... I'm done!\n", threadno);
fflush(stdout);
@@ -396,6 +399,7 @@ void priority_inheritance(void)
g_medpri = my_pri - 1;
sem_init(&g_sem, 0, NLOWPRI_THREADS);
+ dump_nfreeholders("priority_inheritance:");
/* Start the low priority threads */
@@ -429,6 +433,7 @@ void priority_inheritance(void)
}
printf("priority_inheritance: Waiting...\n");
sleep(2);
+ dump_nfreeholders("priority_inheritance:");
/* Start the medium priority thread */
@@ -458,6 +463,7 @@ void priority_inheritance(void)
}
printf("priority_inheritance: Waiting...\n");
sleep(1);
+ dump_nfreeholders("priority_inheritance:");
/* Start the high priority threads */
@@ -491,6 +497,8 @@ void priority_inheritance(void)
printf("priority_inheritance: pthread_create failed, status=%d\n", status);
}
}
+ dump_nfreeholders("priority_inheritance:");
+ fflush(stdout);
/* Wait for all thread instances to complete */
@@ -499,19 +507,23 @@ void priority_inheritance(void)
printf("priority_inheritance: Waiting for highpri_thread-%d to complete\n", i+1);
fflush(stdout);
(void)pthread_join(highpri[i], &result);
+ dump_nfreeholders("priority_inheritance:");
}
printf("priority_inheritance: Waiting for medpri_thread to complete\n");
fflush(stdout);
(void)pthread_join(medpri, &result);
+ dump_nfreeholders("priority_inheritance:");
for (i = 0; i < NLOWPRI_THREADS; i++)
{
printf("priority_inheritance: Waiting for lowpri_thread-%d to complete\n", i+1);
fflush(stdout);
(void)pthread_join(lowpri[i], &result);
+ dump_nfreeholders("priority_inheritance:");
}
printf("priority_inheritance: Finished\n");
sem_destroy(&g_sem);
+ dump_nfreeholders("priority_inheritance:");
fflush(stdout);
#endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */
}