From b1c4413c56045ef361e8928b76ee911d3c980a8e Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Tue, 22 Sep 2009 19:58:40 +0000 Subject: [PATCH] Turns out the selection sort algorithm was broken for more than... 2 entries, if they were not already ordered. Or, to say id differently, it was completely broken. Luckily no one noticed.... Also disabled again printing the timers, since it could print not available ones. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33235 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/arch/x86/arch_timer.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/system/kernel/arch/x86/arch_timer.c b/src/system/kernel/arch/x86/arch_timer.c index 988bfbb2f9..b8999728d9 100644 --- a/src/system/kernel/arch/x86/arch_timer.c +++ b/src/system/kernel/arch/x86/arch_timer.c @@ -65,24 +65,28 @@ arch_timer_clear_hardware_timer(void) static void sort_timers(timer_info *timers[], int numTimers) { - int size; timer_info *tempPtr; int max = 0; int i = 0; + int j = 0; - for (size = numTimers; size > 1; size--) { - for (i = 0; i < size; i++) { - if (timers[i]->get_priority() < timers[max]->get_priority()) - max = i; + for (i = 0; i < numTimers - 1; i++) { + max = i; + for (j = i + 1; j < numTimers; j++) { + if (timers[j]->get_priority() > timers[max]->get_priority()) + max = j; + } + if (max != i) { + tempPtr = timers[max]; + timers[max] = timers[i]; + timers[i] = tempPtr; } - tempPtr = timers[max]; - timers[max] = timers[size - 1]; - timers[size - 1] = tempPtr; } - - dprintf("arch_init_timer:timers found:\n"); + +#if 0 for (i = 0; i < numTimers; i++) dprintf(" %s: priority %d\n", timers[i]->name, timers[i]->get_priority()); +#endif }