-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsleep.c
49 lines (42 loc) · 947 Bytes
/
sleep.c
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
38
39
40
41
42
43
44
45
46
47
48
49
#include <time.h>
#include "sleep.h"
#define ONE_SECOND 1 // 1 second
#define HALF_SECOND 500000000 // 0.5 seconds
/*
* Makes the execution of the program paused for
* the number of seconds passed as parameter.
*/
void sleep_n_seconds(long segundos)
{
struct timespec tim, tim2;
tim.tv_sec = segundos;
tim.tv_nsec = 0;
nanosleep(&tim, &tim2);
}
/*
* Makes the execution of the program paused for
* the number of nanoseconds passed as parameter.
*/
void sleep_n_nanoseconds(long nanosegundos)
{
struct timespec tim, tim2;
tim.tv_sec = 0;
tim.tv_nsec = nanosegundos;
nanosleep(&tim, &tim2);
}
/*
* Makes the execution of the program paused for
* a fixed number of seconds defined as constant.
*/
void sleep_a_bit()
{
sleep_n_seconds(ONE_SECOND);
}
/*
* Makes the execution of the program paused for
* a fixed number of nanoseconds defined as constant.
*/
void sleep_a_nano_bit()
{
sleep_n_nanoseconds(HALF_SECOND);
}