-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
event.h
96 lines (87 loc) · 2.72 KB
/
event.h
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* @file sync/event.h
*
* @section License
* Copyright (C) 2014-2016, Erik Moqvist
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MEREVENTTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* This file is part of the Simba project.
*/
#ifndef __SYNC_EVENT_H__
#define __SYNC_EVENT_H__
#include "simba.h"
/**
* Event channel.
*/
struct event_t {
struct chan_t base;
uint32_t mask; /* Events that occured. */
};
/**
* Initialize given event channel.
*
* @param[in] self_p Event channel to initialize.
*
* @return zero(0) or negative error code
*/
int event_init(struct event_t *self_p);
/**
* Wait for an event to occur in given event mask. This function
* blocks until at least one of the events in the event mask has been
* set. When the function returns, given event mask has been
* overwritten with the events that actually occured.
*
* @param[in] self_p Event channel object.
* @param[in, out] buf_p The mask of events to wait for. When the
* function returns the mask contains the events
* that have occured.
* @param[in] size Size to read (always sizeof(mask)).
*
* @return sizeof(mask) or negative error code.
*/
ssize_t event_read(struct event_t *self_p,
void *buf_p,
size_t size);
/**
* Write given event(s) to given event channel.
*
* @param[in] self_p Event channel object.
* @param[in] buf_p The mask of events to write.
* @param[in] size Must always be sizeof(mask).
*
* @return sizeof(mask) or negative error code.
*/
ssize_t event_write(struct event_t *self_p,
const void *buf_p,
size_t size);
/**
* Write given events to the event channel from isr or with the system
* lock taken (see `sys_lock()`).
*
* @param[in] self_p Event channel object.
* @param[in] buf_p The mask of events to write.
* @param[in] size Must always be sizeof(mask).
*
* @return sizeof(mask) or negative error code.
*/
ssize_t event_write_isr(struct event_t *self_p,
const void *buf_p,
size_t size);
/**
* Checks if there are events active on the event channel.
*
* @param[in] self_p Event channel object.
*
* @return one(1) is at least one event is active, otherwise zero(0).
*/
ssize_t event_size(struct event_t *self_p);
#endif