summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2013-06-01 16:36:48 +0200
committerRichard Braun <rbraun@sceen.net>2013-06-01 16:36:48 +0200
commit716a81ecd8b8e4dc23f04ff2a1d2c4ae8ace0f49 (patch)
tree64bf28f9d2425e474aba65cdb05cfb3e4ee37dd0
parent0ce715c716f0510d9ec2d5a56dec4cbcfbd9522e (diff)
kern/thread: update creation attributes handling
Make passing attributes and passing a thread name mandatory.
-rw-r--r--kern/llsync.c4
-rw-r--r--kern/thread.c30
-rw-r--r--kern/thread.h12
3 files changed, 14 insertions, 32 deletions
diff --git a/kern/llsync.c b/kern/llsync.c
index 2254aac4..8150276b 100644
--- a/kern/llsync.c
+++ b/kern/llsync.c
@@ -153,11 +153,11 @@ llsync_setup(void)
list_init(&llsync_list1);
list_init(&llsync_list2);
- attr.task = NULL;
attr.name = "x15_llsync_work";
+ attr.cpumap = NULL;
+ attr.task = NULL;
attr.policy = THREAD_SCHED_POLICY_TS;
attr.priority = THREAD_SCHED_TS_PRIO_DEFAULT;
- attr.cpumap = NULL;
error = thread_create(&llsync_worker, &attr, llsync_work, NULL);
if (error)
diff --git a/kern/thread.c b/kern/thread.c
index 648f8ca1..7affc2d8 100644
--- a/kern/thread.c
+++ b/kern/thread.c
@@ -241,14 +241,6 @@ static unsigned char thread_policy_table[THREAD_NR_SCHED_POLICIES];
*/
static struct thread_sched_ops thread_sched_ops[THREAD_NR_SCHED_CLASSES];
-static struct thread_attr thread_default_attr = {
- NULL,
- NULL,
- THREAD_SCHED_POLICY_TS,
- THREAD_SCHED_TS_PRIO_DEFAULT,
- NULL
-};
-
/*
* Map of run queues for which a processor is running.
*/
@@ -1426,19 +1418,11 @@ thread_init(struct thread *thread, void *stack, const struct thread_attr *attr,
struct thread *caller;
struct task *task;
struct cpumap *cpumap;
- const char *name;
caller = thread_self();
- if (attr == NULL)
- attr = &thread_default_attr;
-
task = (attr->task == NULL) ? caller->task : attr->task;
- assert(task != NULL);
- name = (attr->name == NULL) ? task->name : attr->name;
- assert(name != NULL);
cpumap = (attr->cpumap == NULL) ? &caller->cpumap : attr->cpumap;
- assert(cpumap != NULL);
assert(attr->policy < THREAD_NR_SCHED_POLICIES);
/*
@@ -1463,7 +1447,7 @@ thread_init(struct thread *thread, void *stack, const struct thread_attr *attr,
thread_init_sched(thread, attr->priority);
thread->task = task;
thread->stack = stack;
- strlcpy(thread->name, name, sizeof(thread->name));
+ strlcpy(thread->name, attr->name, sizeof(thread->name));
thread->fn = fn;
thread->arg = arg;
@@ -1552,11 +1536,11 @@ thread_setup_reaper(void)
condition_init(&thread_reap_condition);
list_init(&thread_reap_list);
- attr.task = NULL;
attr.name = "x15_thread_reap";
+ attr.cpumap = NULL;
+ attr.task = NULL;
attr.policy = THREAD_SCHED_POLICY_TS;
attr.priority = THREAD_SCHED_TS_PRIO_DEFAULT;
- attr.cpumap = NULL;
error = thread_create(&thread, &attr, thread_reap, NULL);
if (error)
@@ -1627,11 +1611,11 @@ thread_setup_balancer(struct thread_runq *runq)
cpumap_zero(cpumap);
cpumap_set(cpumap, thread_runq_id(runq));
snprintf(name, sizeof(name), "x15_thread_balance/%u", thread_runq_id(runq));
- attr.task = NULL;
attr.name = name;
+ attr.cpumap = cpumap;
+ attr.task = NULL;
attr.policy = THREAD_SCHED_POLICY_RR;
attr.priority = THREAD_SCHED_RT_PRIO_MIN;
- attr.cpumap = cpumap;
error = thread_create(&balancer, &attr, thread_balance, runq);
cpumap_destroy(cpumap);
@@ -1698,10 +1682,10 @@ thread_setup_idler(struct thread_runq *runq)
panic("thread: unable to allocate idler thread stack");
snprintf(name, sizeof(name), "x15_thread_idle/%u", thread_runq_id(runq));
- attr.task = kernel_task;
attr.name = name;
- attr.policy = THREAD_SCHED_POLICY_IDLE;
attr.cpumap = cpumap;
+ attr.task = NULL;
+ attr.policy = THREAD_SCHED_POLICY_IDLE;
thread_init(idler, stack, &attr, thread_idle, runq);
cpumap_destroy(cpumap);
diff --git a/kern/thread.h b/kern/thread.h
index 7cef3eae..dca1a698 100644
--- a/kern/thread.h
+++ b/kern/thread.h
@@ -176,11 +176,11 @@ struct thread {
* Thread creation attributes.
*/
struct thread_attr {
- struct task *task;
const char *name;
+ struct cpumap *cpumap;
+ struct task *task;
unsigned char policy;
unsigned short priority;
- struct cpumap *cpumap;
};
/*
@@ -200,11 +200,9 @@ void thread_setup(void);
/*
* Create a thread.
*
- * If the given attributes are NULL, default attributes are used. If the task
- * is NULL, the caller task is selected. If the name is NULL, the task name is
- * used instead. If the CPU map is NULL, the new thread inherits the map of
- * the caller. The default attributes also select the caller task, task name
- * and CPU map.
+ * Creation attributes must be passed, but some of them may be NULL, in which
+ * case the value is inherited from the caller. The name attribute must not be
+ * NULL.
*/
int thread_create(struct thread **threadp, const struct thread_attr *attr,
void (*fn)(void *), void *arg);