source: trunk/kernel/syscalls/sys_alarm.c @ 1

Last change on this file since 1 was 1, checked in by alain, 5 years ago

First import

File size: 1.5 KB
Line 
1/*
2 * kern/sys_alarm.c - timed sleep/wakeup
3 *
4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
5 * Copyright (c) 2011,2012 UPMC Sorbonne Universites
6 *
7 * This file is part of ALMOS-kernel.
8 *
9 * ALMOS-kernel is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2.0 of the License.
12 *
13 * ALMOS-kernel is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ALMOS-kernel; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <types.h>
24#include <thread.h>
25#include <cluster.h>
26#include <task.h>
27#include <time.h>
28#include <scheduler.h>
29#include <cpu.h>
30#include <cpu-trace.h>
31
32EVENT_HANDLER(sys_alarm_event_handler)
33{
34        struct thread_s *thread;
35
36        thread = event_get_argument(event);
37        sched_wakeup(thread);
38        return 0;
39}
40
41int sys_alarm (unsigned nb_sec)
42{
43        struct thread_s *this;
44        struct event_s event;
45        struct alarm_info_s info;
46
47        if( nb_sec == 0)
48                return 0;
49
50        this = current_thread;
51        event_set_handler(&event, &sys_alarm_event_handler);
52        event_set_priority(&event, E_FUNC);
53        event_set_argument(&event,this);
54        info.event = &event;
55
56        alarm_wait(&info, nb_sec * 4);
57        sched_sleep(this);
58        return 0;
59}
60
61
Note: See TracBrowser for help on using the repository browser.