[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v4 04/12] lib/uksched: Introduce detached flag for threads


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Fri, 22 Mar 2019 16:16:31 +0200
  • Cc: Florian.Schmidt@xxxxxxxxx
  • Delivery-date: Fri, 22 Mar 2019 14:16:48 +0000
  • Ironport-phdr: 9a23:Vzvd3BN4JbU/9nFTI/Al6mtUPXoX/o7sNwtQ0KIMzox0Iv3yrarrMEGX3/hxlliBBdydt6sczbWP+P2/EUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCehbb9oLhi6sArdu8kUjIB/Nqs/1xzFr2dSde9L321oP1WTnxj95se04pFu9jlbtuwi+cBdT6j0Zrw0QrNEAjsoNWA1/9DrugLYTQST/HscU34ZnQRODgPY8Rz1RJbxsi/9tupgxCmXOND9QL4oVTi+6apgVRnlgzoFOTEk6mHaksx+grxGrhyvpBJxxIzbYI+OOfZiYq/QZ88WSHBdUspNUSFKH4Oyb5EID+oEJetVsY79p0ASrRu/AwmnGeXhyiJQhn/rwKY31PguEQbd3Aw8HtIOtm7YrNHoNKcKTOC417XHzS7ZY/NOxDfy85LEcgomofyVW797bMnfyVE3Gg/YgVictJbpMjCV2+gXrWSX8ehtWfihhmI/tg18rSWjyt0vh4TJnI4Z1F7J+CtjzIooKtC0Vkh2asO+HpRKrSGVLY52T9snQ2FvpSk11KULuYW+fCgW0JQnwAPfa+Cff4iI/B3jUOGRLC9mhHJgYr2/hhKy/VK8xe3nTMW0yEtKoTFfntnWsXABzx3T6s6ZRfth5kqtxDmC2x3J5uxHIU04j7TXJ4Ajz7IqmJcfqUHDETX3mEXygq+WbEIk+u2w5uv7ZbXmvYOcN45yig3kNqQuh9S/AfkjPwcSRGiX4/y81KD48kHjWrVKieU6krPFv5DCOcQbuqm5DhdQ0oYi7Ra/DjCm0M8BkXYaMl1FZgyIj4zyNlHKIfD4Fuu/g0+2nDZk2f/GOKftApLXLnjMiL3hZ6py61ZAyAovytBS/5JaCrUGIPLpW0/+rtrYAgUkPQOow+bnDdR92Z4CWW+UBK+WLr/dsVuS6e00OeWDepIV637BLK0g5vjvimR8lVIDcK2B2ZoMdGv+DvlgZUKDbinCmNAEREwNpRY/SqTOlUWfGWpYYG2uXqR64iwjFaqtFsHbW4rrmrvXj3TzJYFfem0TUgPEKnzvbYjRA/o=
  • Ironport-sdr: Nq/c5+0S4W6tUqZ8elhHXaBZOBZJ36O/b+A0MT3ezVfkD0XCdiNrmRC2yUXP+dZK352KnriVXN Tamqv5/qLdEw==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

By the default, detached flag is set on false meaning that one has to
wait for the thread in order to free its resources after completion.
Detached threads should not be waited on. If the flag is true then the
thread resources will be freed by the system.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
Reviewed-by: Florian Schmidt <florian.schmidt@xxxxxxxxx>
---
 lib/uksched/exportsyms.uk       |  3 ++-
 lib/uksched/include/uk/sched.h  |  2 ++
 lib/uksched/include/uk/thread.h |  2 ++
 lib/uksched/thread.c            | 10 ++++++++++
 4 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/lib/uksched/exportsyms.uk b/lib/uksched/exportsyms.uk
index df0bb4db..334c652f 100644
--- a/lib/uksched/exportsyms.uk
+++ b/lib/uksched/exportsyms.uk
@@ -11,6 +11,7 @@ uk_sched_thread_sleep
 uk_sched_thread_exit
 uk_thread_init
 uk_thread_fini
+uk_thread_detach
 uk_thread_set_prio
 uk_thread_get_prio
 uk_thread_set_timeslice
@@ -25,4 +26,4 @@ uk_thread_attr_get_detachstate
 uk_thread_attr_set_prio
 uk_thread_attr_get_prio
 uk_thread_attr_set_timeslice
-uk_thread_attr_get_timeslice
\ No newline at end of file
+uk_thread_attr_get_timeslice
diff --git a/lib/uksched/include/uk/sched.h b/lib/uksched/include/uk/sched.h
index 5f2d308f..9554c6e1 100644
--- a/lib/uksched/include/uk/sched.h
+++ b/lib/uksched/include/uk/sched.h
@@ -111,6 +111,8 @@ static inline void uk_sched_thread_add(struct uk_sched *s,
 {
        UK_ASSERT(s);
        UK_ASSERT(t);
+       if (attr)
+               t->detached = attr->detached;
        t->sched = s;
        s->thread_add(s, t, attr);
 }
diff --git a/lib/uksched/include/uk/thread.h b/lib/uksched/include/uk/thread.h
index 5ff2dd65..5f3c2501 100644
--- a/lib/uksched/include/uk/thread.h
+++ b/lib/uksched/include/uk/thread.h
@@ -29,6 +29,7 @@
 #define __UK_THREAD_H__
 
 #include <stdint.h>
+#include <stdbool.h>
 #ifdef CONFIG_HAVE_LIBC
 #include <sys/reent.h>
 #endif
@@ -52,6 +53,7 @@ struct uk_thread {
        UK_TAILQ_ENTRY(struct uk_thread) thread_list;
        uint32_t flags;
        __snsec wakeup_time;
+       bool detached;
        struct uk_sched *sched;
 #ifdef CONFIG_HAVE_LIBC
        struct _reent reent;
diff --git a/lib/uksched/thread.c b/lib/uksched/thread.c
index 9d065526..aeeaff17 100644
--- a/lib/uksched/thread.c
+++ b/lib/uksched/thread.c
@@ -86,6 +86,7 @@ int uk_thread_init(struct uk_thread *thread,
        /* Not runnable, not exited, not sleeping */
        thread->flags = 0;
        thread->wakeup_time = 0LL;
+       thread->detached = false;
 
 #ifdef CONFIG_HAVE_LIBC
        //TODO _REENT_INIT_PTR(&thread->reent);
@@ -130,6 +131,15 @@ void uk_thread_wake(struct uk_thread *thread)
        set_runnable(thread);
 }
 
+int uk_thread_detach(struct uk_thread *thread)
+{
+       UK_ASSERT(thread);
+
+       thread->detached = true;
+
+       return 0;
+}
+
 int uk_thread_set_prio(struct uk_thread *thread, prio_t prio)
 {
        if (!thread)
-- 
2.11.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.