Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / kernel / core / its.c
blob17636bc53950bcad993d8645628edbc183e7dad2
1 /*
2 * ZeX/OS
3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2010 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 /** Interval Time Scheduler - NOTE: it's not a task/process scheduler */
22 #include <system.h>
23 #include <its.h>
25 its_t its_list;
27 extern unsigned long timer_ticks;
29 unsigned int its_unregister (its_t *its)
31 if (!its)
32 return 0;
34 its->next->prev = its->prev;
35 its->prev->next = its->next;
37 kfree (its);
39 return 1;
42 unsigned task_its ()
44 for (;; schedule ()) {
45 its_t *its;
46 for (its = its_list.next; its != &its_list; its = its->next)
47 if ((timer_ticks-its->timer) >= its->interval) {
48 if (!its->handler (its->arg)) {
49 its_unregister (its);
50 break;
53 its->timer = timer_ticks;
57 return 1;
60 unsigned int its_register (unsigned long interval, its_handler_t *handler, void *arg)
62 its_t *its = its_list.next;
63 /* create ITS' task when it's really needed */
64 if (its == &its_list)
65 task_create ("its", (unsigned) task_its, 255);
67 /* alloc and init context */
68 its = (its_t *) kmalloc (sizeof (its_t));
70 if (!its)
71 return 0;
73 its->timer = timer_ticks;
74 its->interval = interval;
75 its->handler = handler;
76 its->arg = arg;
78 /* add into list */
79 its->next = &its_list;
80 its->prev = its_list.prev;
81 its->prev->next = its;
82 its->next->prev = its;
84 DPRINT (DBG_CORE, "its_register () -> 0x%x every %dms", handler, interval);
86 return 1;
89 #ifdef TEST
90 unsigned int test_its_handler (void *arg)
92 if (arg)
93 kprintf ("%s", arg);
95 return 1;
97 #endif
99 unsigned int init_its ()
101 its_list.next = &its_list;
102 its_list.prev = &its_list;
104 #ifdef TEST
105 its_register (10000, &test_its_handler, "test");
106 #endif
107 return 1;