aboutsummaryrefslogtreecommitdiffstats
path: root/extras/mini-os/sched.c
diff options
context:
space:
mode:
authorIan Campbell <Ian.Campbell@citrix.com>2012-01-31 16:06:14 +0000
committerIan Campbell <Ian.Campbell@citrix.com>2012-01-31 16:06:14 +0000
commit1a4af67d32b1c39b73e09346203f3e12c00b9e41 (patch)
treeee7058fc62cdec6fe3f3582a63f99f90bd05bb24 /extras/mini-os/sched.c
parentf17888fc962b5249f9b6b34f28a61998c3092018 (diff)
downloadxen-1a4af67d32b1c39b73e09346203f3e12c00b9e41.tar.gz
xen-1a4af67d32b1c39b73e09346203f3e12c00b9e41.tar.bz2
xen-1a4af67d32b1c39b73e09346203f3e12c00b9e41.zip
mini-os: use BSD sys/queue.h instead of Linux list.h
The latter is GPL which makes the whole of mini-os GPL rather than BSD as intended. In tree users are all GPL or GPL-compatible but we should fix this so that mini-os is BSD. Do so by using the same BSD sys/queue.h as we use in libxl. Tested with the builtin mini-os test app and qemu stubdomain, both of which appear to still function as expected. Move tools/libxl/external and the associated sed script to tools/include/xen-external to allow more sensible access from mini-os. Also add s/NULL/0/ in the sed script due to NULL not always being defined in stubdom code when mini-os/wait.h is included. As well as the obvious ABI changes there are a few API updates associated with the change: - struct rw_semaphore.wait_list is unused - remove_waiter needs to take the wait_queue_head The latter requires a qemu update, so there is also a QEMU_TAG update in this changeset. I sprinkled some extra-emacs local variables around the files I edited which didn't have them. I think this should be backported to the stable branches since external users of mini-os may have been mislead into thinking they could safely link mini-os against GPL-incompatible code. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Diffstat (limited to 'extras/mini-os/sched.c')
-rw-r--r--extras/mini-os/sched.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/extras/mini-os/sched.c b/extras/mini-os/sched.c
index c0229c5687..2d27bfaa97 100644
--- a/extras/mini-os/sched.c
+++ b/extras/mini-os/sched.c
@@ -54,19 +54,20 @@
#define DEBUG(_f, _a...) ((void)0)
#endif
+MINIOS_TAILQ_HEAD(thread_list, struct thread);
+
struct thread *idle_thread = NULL;
-MINIOS_LIST_HEAD(exited_threads);
+static struct thread_list exited_threads = MINIOS_TAILQ_HEAD_INITIALIZER(exited_threads);
+static struct thread_list thread_list = MINIOS_TAILQ_HEAD_INITIALIZER(thread_list);
static int threads_started;
struct thread *main_thread;
void inline print_runqueue(void)
{
- struct minios_list_head *it;
struct thread *th;
- minios_list_for_each(it, &idle_thread->thread_list)
+ MINIOS_TAILQ_FOREACH(th, &thread_list, thread_list)
{
- th = minios_list_entry(it, struct thread, thread_list);
printk(" Thread \"%s\", runnable=%d\n", th->name, is_runnable(th));
}
printk("\n");
@@ -74,8 +75,7 @@ void inline print_runqueue(void)
void schedule(void)
{
- struct thread *prev, *next, *thread;
- struct minios_list_head *iterator, *next_iterator;
+ struct thread *prev, *next, *thread, *tmp;
unsigned long flags;
prev = current;
@@ -96,10 +96,9 @@ void schedule(void)
time when the next timeout expires, else use 10 seconds. */
s_time_t now = NOW();
s_time_t min_wakeup_time = now + SECONDS(10);
- next = NULL;
- minios_list_for_each_safe(iterator, next_iterator, &idle_thread->thread_list)
+ next = NULL;
+ MINIOS_TAILQ_FOREACH_SAFE(thread, &thread_list, thread_list, tmp)
{
- thread = minios_list_entry(iterator, struct thread, thread_list);
if (!is_runnable(thread) && thread->wakeup_time != 0LL)
{
if (thread->wakeup_time <= now)
@@ -111,8 +110,8 @@ void schedule(void)
{
next = thread;
/* Put this thread on the end of the list */
- minios_list_del(&thread->thread_list);
- minios_list_add_tail(&thread->thread_list, &idle_thread->thread_list);
+ MINIOS_TAILQ_REMOVE(&thread_list, thread, thread_list);
+ MINIOS_TAILQ_INSERT_TAIL(&thread_list, thread, thread_list);
break;
}
}
@@ -128,12 +127,11 @@ void schedule(void)
inturrupted at the return instruction. And therefore at safe point. */
if(prev != next) switch_threads(prev, next);
- minios_list_for_each_safe(iterator, next_iterator, &exited_threads)
+ MINIOS_TAILQ_FOREACH_SAFE(thread, &exited_threads, thread_list, tmp)
{
- thread = minios_list_entry(iterator, struct thread, thread_list);
if(thread != prev)
{
- minios_list_del(&thread->thread_list);
+ MINIOS_TAILQ_REMOVE(&exited_threads, thread, thread_list);
free_pages(thread->stack, STACK_SIZE_PAGE_ORDER);
xfree(thread);
}
@@ -154,13 +152,7 @@ struct thread* create_thread(char *name, void (*function)(void *), void *data)
#endif
set_runnable(thread);
local_irq_save(flags);
- if(idle_thread != NULL) {
- minios_list_add_tail(&thread->thread_list, &idle_thread->thread_list);
- } else if(function != idle_thread_fn)
- {
- printk("BUG: Not allowed to create thread before initialising scheduler.\n");
- BUG();
- }
+ MINIOS_TAILQ_INSERT_TAIL(&thread_list, thread, thread_list);
local_irq_restore(flags);
return thread;
}
@@ -208,10 +200,10 @@ void exit_thread(void)
printk("Thread \"%s\" exited.\n", thread->name);
local_irq_save(flags);
/* Remove from the thread list */
- minios_list_del(&thread->thread_list);
+ MINIOS_TAILQ_REMOVE(&thread_list, thread, thread_list);
clear_runnable(thread);
/* Put onto exited list */
- minios_list_add(&thread->thread_list, &exited_threads);
+ MINIOS_TAILQ_INSERT_HEAD(&exited_threads, thread, thread_list);
local_irq_restore(flags);
/* Schedule will free the resources */
while(1)
@@ -296,6 +288,14 @@ void init_sched(void)
_REENT_INIT_PTR((&callback_reent))
#endif
idle_thread = create_thread("Idle", idle_thread_fn, NULL);
- MINIOS_INIT_LIST_HEAD(&idle_thread->thread_list);
}
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */