aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2015-04-18 12:19:43 +0900
committerNIIBE Yutaka <gniibe@fsij.org>2015-04-18 12:23:35 +0900
commita0f33c1036417c118496d77c98f0f7f1116df5bd (patch)
tree7a0e4caa7fd91b52d9f37feb8fe96bdca512bf7c
parent2fb7fb6826454b109f31901e48b2ae452d223ded (diff)
New: chopstx_main_init
-rw-r--r--ChangeLog6
-rw-r--r--chopstx.c32
-rw-r--r--chopstx.h2
3 files changed, 35 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 8100ef4..b8460b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-04-17 Niibe Yutaka <gniibe@fsij.org>
+
+ * chopstx.c (CHX_PRIO_MAIN_INIT): New, removing CHX_PRIO_MAIN.
+ (chopstx_main_init): New.
+ (chx_init): Use CHX_PRIO_MAIN_INIT.
+
2015-03-17 Niibe Yutaka <gniibe@fsij.org>
* VERSION: 0.04a.
diff --git a/chopstx.c b/chopstx.c
index 29bea71..a355263 100644
--- a/chopstx.c
+++ b/chopstx.c
@@ -34,8 +34,8 @@
/*
* Thread priority: higer has higher precedence.
*/
-#if !defined(CHX_PRIO_MAIN)
-#define CHX_PRIO_MAIN 1
+#if !defined(CHX_PRIO_MAIN_INIT)
+#define CHX_PRIO_MAIN_INIT 1
#endif
#if !defined(CHX_FLAGS_MAIN)
#define CHX_FLAGS_MAIN 0
@@ -740,20 +740,42 @@ chx_init (struct chx_thread *tp)
tp->flag_got_cancel = tp->flag_join_req = 0;
tp->flag_sched_rr = (CHX_FLAGS_MAIN & CHOPSTX_SCHED_RR)? 1 : 0;
tp->flag_detached = (CHX_FLAGS_MAIN & CHOPSTX_DETACHED)? 1 : 0;
- tp->prio_orig = CHX_PRIO_MAIN;
+ tp->prio_orig = CHX_PRIO_MAIN_INIT;
tp->prio = 0;
tp->v = 0;
running = tp;
- if (CHX_PRIO_MAIN >= CHOPSTX_PRIO_INHIBIT_PREEMPTION)
+ if (CHX_PRIO_MAIN_INIT >= CHOPSTX_PRIO_INHIBIT_PREEMPTION)
chx_cpu_sched_lock ();
- tp->prio = CHX_PRIO_MAIN;
+ tp->prio = CHX_PRIO_MAIN_INIT;
chopstx_main = (chopstx_t)tp;
}
+/**
+ * chopstx_main_init - initialize main thread
+ * @prio: priority
+ *
+ * Initialize main thread with @prio.
+ * The thread main is created with priority CHX_PRIO_MAIN_INIT,
+ * and it runs with that priority until this routine will is called.
+ */
+void
+chopstx_main_init (chopstx_prio_t prio)
+{
+ struct chx_thread *tp = (struct chx_thread *)chopstx_main;
+
+ tp->prio_orig = prio;
+
+ if (prio >= CHOPSTX_PRIO_INHIBIT_PREEMPTION)
+ chx_cpu_sched_lock ();
+
+ tp->prio = prio;
+}
+
+
static void
chx_request_preemption (void)
{
diff --git a/chopstx.h b/chopstx.h
index a7df3e8..cf8b233 100644
--- a/chopstx.h
+++ b/chopstx.h
@@ -31,6 +31,8 @@ typedef uint8_t chopstx_prio_t;
extern chopstx_t chopstx_main;
+void chopstx_main_init (chopstx_prio_t);
+
/* NOTE: This signature is different to PTHREAD's one. */
chopstx_t
chopstx_create (uint32_t flags_and_prio,