From a96a8bb6d9505ebac2c32f7b0ec23a1269a5ce13 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Mon, 10 Nov 2008 11:29:09 +0200 Subject: [PATCH] Modification on allocation of thread group ids in the kernel. A new or forked thread will have its tgid same as its unique thread id. A cloned thread (i.e. in the same space) will get its parent's tgid if the parent tgid is supplied as the suggested tgid in the ids field. Otherwise the thread will have its tgid same as its unique thread id. Previously we also allocated a tgid from a separate pool, but this doesn't make sense. It is cleaner to have the unique thread id get used also as the tgid. --- src/api/thread.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/api/thread.c b/src/api/thread.c index c6cb4a2..33af867 100644 --- a/src/api/thread.c +++ b/src/api/thread.c @@ -164,8 +164,10 @@ int arch_setup_new_thread(struct ktcb *new, struct ktcb *orig, unsigned int flag return 0; } -extern unsigned int return_from_syscall; - +/* + * Sets up the thread, thread group and space id of newly created thread + * according to supplied flags. + */ int thread_setup_new_ids(struct task_ids *ids, unsigned int flags, struct ktcb *new, struct ktcb *orig) { @@ -187,20 +189,19 @@ int thread_setup_new_ids(struct task_ids *ids, unsigned int flags, ids->spid)) < 0) ids->spid = id_new(space_id_pool); - /* It also gets a thread group id */ - if ((ids->tgid = id_get(tgroup_id_pool, - ids->tgid)) < 0) - ids->tgid = id_new(tgroup_id_pool); + /* Thread gets same group id as its thread id */ + ids->tgid = ids->tid; } - /* If thread space is the same, tgid is either new or existing one */ if (flags == THREAD_SAME_SPACE) { - /* Check if same tgid is expected */ - if (ids->tgid != orig->tgid) { - if ((ids->tgid = id_get(tgroup_id_pool, - ids->tgid)) < 0) - ids->tgid = id_new(tgroup_id_pool); - } + /* + * If the tgid of original thread is supplied, that + * implies the new thread wants to be in the same group, + * and we leave it as it is. Otherwise the thread gets + * the same group id as its unique thread id. + */ + if (ids->tgid != orig->tgid) + ids->tgid = ids->tid; } /* Set all ids */