librfn
An ad-hoc utility library
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
librfn
posix
fibre_posix.c
Go to the documentation of this file.
1
/*
2
* fibre_posix.c
3
*
4
* Part of librfn (a general utility library from redfelineninja.org.uk)
5
*
6
* Copyright (C) 2013 Daniel Thompson <daniel@redfelineninja.org.uk>
7
*
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU Lesser General Public License as published
10
* by the Free Software Foundation; either version 3 of the License, or
11
* (at your option) any later version.
12
*/
13
14
#include <assert.h>
15
#include <stdint.h>
16
#include <stdlib.h>
17
#include <
string.h
>
18
#include <
time.h
>
19
#include <unistd.h>
20
21
#include "
librfn/fibre.h
"
22
#include "
librfn/time.h
"
23
#include "
librfn/util.h
"
24
25
void
fibre_scheduler_main_loop
()
26
{
27
while
(
true
) {
28
uint32_t sleep_until =
fibre_scheduler_next
(
time_now
());
29
int32_t sleep_interval =
cyclecmp32
(sleep_until,
time_now
());
30
sleep_interval = sleep_interval < 1000 ? sleep_interval : 50000;
31
if
(sleep_interval > 0)
32
usleep(sleep_interval);
33
}
34
}
string.h
time.h
fibre_scheduler_next
uint32_t fibre_scheduler_next(uint32_t time)
Schedule the next fibre.
Definition:
fibre.c:134
fibre_scheduler_main_loop
void fibre_scheduler_main_loop()
Definition:
fibre_posix.c:25
cyclecmp32
int32_t cyclecmp32(uint32_t a, uint32_t b)
Compares values that may be subject to overflow.
Definition:
util.c:19
util.h
time_now
uint32_t time_now(void)
Definition:
time_libopencm3.c:42
fibre.h
Generated on Sat Feb 6 2016 21:25:32 for librfn by
1.8.10