From ba594d5eaebe0885b09f9633b58ae55b1b03b246 Mon Sep 17 00:00:00 2001
From: NIIBE Yutaka <gniibe@fsij.org>
Date: Tue, 4 Jun 2013 13:16:20 +0900
Subject: Priority macros

---
 ChangeLog |  1 +
 chopstx.c | 15 ++++++++++-----
 chopstx.h | 13 ++++++++++++-
 3 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index eceddbf..0d78cfb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,7 @@
 	(preempt, chx_timer_expired, chx_handle_intr): Those can be
 	considered holding cpu_sched_lock (by its equal exception
 	priorities), thus no acquiring lock required.
+	(CHX_PRIO_MAIN): New macro.
 
 2013-06-03  Niibe Yutaka  <gniibe@fsij.org>
 
diff --git a/chopstx.c b/chopstx.c
index 6c23d80..52cb2bf 100644
--- a/chopstx.c
+++ b/chopstx.c
@@ -32,7 +32,14 @@
 #include <chopstx.h>
 
 /*
- * Note: Lower has higher precedence.
+ * Thread priority: higer has higher precedence.
+ */
+#if !defined(CHX_PRIO_DEFAULT)
+#define CHX_PRIO_MAIN 1
+#endif
+
+/*
+ * Exception priority: lower has higher precedence.
  *
  * Prio 0x30: svc
  * ---------------------
@@ -635,8 +642,6 @@ static uint32_t *const AIRCR = (uint32_t *const)0xE000ED0C;
 static uint32_t *const SHPR2 = (uint32_t *const)0xE000ED1C;
 static uint32_t *const SHPR3 = (uint32_t *const)0xE000ED20;
 
-#define PRIO_DEFAULT 1
-
 void
 chx_init (struct chx_thread *tp)
 {
@@ -655,7 +660,7 @@ chx_init (struct chx_thread *tp)
   tp->state = THREAD_RUNNING;
   tp->flag_detached = tp->flag_got_cancel
     = tp->flag_join_req = tp->flag_sched_rr = 0;
-  tp->prio_orig = tp->prio = PRIO_DEFAULT;
+  tp->prio_orig = tp->prio = CHX_PRIO_MAIN;
   tp->v = 0;
 
   running = tp;
@@ -757,7 +762,7 @@ chx_mutex_unlock (chopstx_mutex_t *mutex)
 void
 chopstx_attr_init (chopstx_attr_t *attr)
 {
-  attr->prio = PRIO_DEFAULT;
+  attr->prio = CHX_PRIO_DEFAULT;
   attr->addr = 0;
   attr->size = 0;
 }
diff --git a/chopstx.h b/chopstx.h
index 9676c4e..c50ef0b 100644
--- a/chopstx.h
+++ b/chopstx.h
@@ -91,7 +91,10 @@ void chopstx_release_irq (chopstx_intr_t *intr);
 
 void chopstx_intr_wait (chopstx_intr_t *intr);
 
-/* Library provides default as weak reference.  User can replace it.  */
+/*
+ * Library provides default implementation as weak reference.
+ * User can replace it.
+  */
 void chx_fatal (uint32_t err_code) __attribute__((__noreturn__));
 
 void chopstx_join (chopstx_t, void **);
@@ -111,3 +114,11 @@ enum {
 
 void chopstx_cancel (chopstx_t thd);
 void chopstx_testcancel (void);
+
+/*
+ * User can define this macro (like: -DCHX_PRIO_DEFAULT=3) to specify
+ * default priority.
+ */
+#if !defined(CHX_PRIO_DEFAULT)
+#define CHX_PRIO_DEFAULT 1
+#endif
-- 
cgit v1.2.3