aboutsummaryrefslogtreecommitdiff
path: root/common/uapi/timers.c
blob: 5ce596f8984ad42319878f906cc02a7525cc29f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <apos/timer.h>
#include <apos/uapi.h>

static ticks_t scaled_ticks(vm_t ticks, vm_t repeat)
{
#if __WORDSIZE == 64
	UNUSED(repeat);
	return ticks;
#else
	return ((ticks_t)ticks << 32) + repeat;
#endif
}

SYSCALL_DEFINE0(timebase)()
{
	return secs_to_ticks(1);
}

SYSCALL_DEFINE2(req_rel_timer)(vm_t ticks, vm_t repeat)
{
	return new_rel_timer(cur_tcb()->tid, scaled_ticks(ticks, repeat));
}

SYSCALL_DEFINE2(req_abs_timer)(vm_t ticks, vm_t repeat)
{
	return new_abs_timer(cur_tcb()->tid, scaled_ticks(ticks, repeat));
}

SYSCALL_DEFINE1(free_timer)(vm_t cid)
{
	struct timer *timer = find_timer(cid);
	if (!timer)
		return ERR_NF;

	remove_timer(timer);
	return OK;
}