+ * Macros for the processes of the priority inversion test.
+ */
+#define PROC_INV_TEST(num) static void proc_semInvTest##num(void) \
+{ \
+ ProcType p_type = (ProcType)((ssize_t) proc_currentUserData()); \
+ int mult = p_type == NONE ? 5 : 1; \
+ unsigned int i, local_count = 0; \
+ ticks_t start; \
+ \
+ kprintf("> test%d(%d): Start.\n", num, proc_current()->link.pri); \
+ finishing_time[num-1] = timer_clock(); \
+ \
+ if (p_type == S1 || p_type == S1S2) { \
+ kprintf("> test%d(prio=%d): Obtain %p..\n", num, \
+ proc_current()->link.pri, &s1); \
+ sem_obtain(&s1); \
+ kprintf("> test%d(prio=%d): Obtained %p.\n", num, \
+ proc_current()->link.pri, &s1); \
+ } \
+ if (p_type == S2 || p_type == S1S2) { \
+ kprintf("> test%d(prio=%d): Obtain %p..\n", num, \
+ proc_current()->link.pri, &s2); \
+ sem_obtain(&s2); \
+ kprintf("> test%d(prio=%d): Obtained %p.\n", num, \
+ proc_current()->link.pri, &s2); \
+ } \
+ \
+ start = timer_clock(); \
+ for (i = 0; i < loops * mult && (((unsigned)timer_clock()-start) <= loops*mult); i++) { \
+ local_count++; \
+ } \
+ \
+ sem_obtain(&sem); \
+ global_count += local_count; \
+ kprintf("> test%d(prio=%d): global_count=%u..\n", num, \
+ proc_current()->link.pri, global_count); \
+ sem_release(&sem); \
+ \
+ if (p_type == S2 || p_type == S1S2) { \
+ kprintf("> test%d(prio=%d): Release %p..\n", num, \
+ proc_current()->link.pri, &s2); \
+ sem_release(&s2); \
+ kprintf("> test%d(prio=%d): %p Released.\n", num, \
+ proc_current()->link.pri, &s2); \
+ } \
+ if (p_type == S1 || p_type == S1S2) { \
+ kprintf("> test%d(prio=%d): Release %p..\n", num, \
+ proc_current()->link.pri, &s1); \
+ sem_release(&s1); \
+ kprintf("> test%d(prio=%d): %p Released.\n", num, \
+ proc_current()->link.pri, &s1); \
+ } \
+ \
+ finishing_time[num-1] = timer_clock() - finishing_time[num-1]; \
+ kprintf("> test%d(prio=%d): Exit.\n", num, proc_current()->link.pri); \
+} \
+
+#define PROC_INV_TEST_INIT(num, pri, type) \
+do { \
+ struct Process *p; \
+ \
+ timer_delay(10); \
+ p = proc_new(proc_semInvTest##num, \
+ ((void*)type), sizeof(proc_sem_test##num##_stack), \
+ proc_sem_test##num##_stack); \
+ proc_setPri(p, pri); \
+} while (0) \
+
+// Define processes for the priority inversion test.
+PROC_INV_TEST(1)
+PROC_INV_TEST(2)
+PROC_INV_TEST(3)
+PROC_INV_TEST(4)
+PROC_INV_TEST(5)
+PROC_INV_TEST(6)
+PROC_INV_TEST(7)
+PROC_INV_TEST(8)
+
+#endif /* CONFIG_KERN_PRI */
+
+// Define process stacks for both of the tests.