IntrOS
Loading...
Searching...
No Matches
osevent.h
1/******************************************************************************
2
3 @file IntrOS: osevent.h
4 @author Rajmund Szymanski
5 @date 17.11.2025
6 @brief This file contains definitions for IntrOS.
7
8 ******************************************************************************
9
10 Copyright (c) 2018-2022 Rajmund Szymanski. All rights reserved.
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to
14 deal in the Software without restriction, including without limitation the
15 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16 sell copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included
20 in all copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 IN THE SOFTWARE.
29
30 ******************************************************************************/
31
32#ifndef __INTROS_EVT_H
33#define __INTROS_EVT_H
34
35#include "oskernel.h"
36#include "osclock.h"
37
43
47
48typedef struct __evt evt_t;
49
50struct __evt
51{
52 obj_t obj;
53};
54
55typedef struct __evt evt_id [];
56
57/******************************************************************************
58 *
59 * Name : _EVT_INIT
60 *
61 * Description : create and initialize an event object
62 *
63 * Parameters : none
64 *
65 * Return : event object
66 *
67 * Note : for internal use
68 *
69 ******************************************************************************/
70
71#define _EVT_INIT() { _OBJ_INIT() }
72
79#define OS_EVT( evt ) \
80 evt_t evt[] = { _EVT_INIT() }
81
82/** static alias of OS_EVT() */
83#define static_EVT( evt ) \
84 static evt_t evt[] = { _EVT_INIT() }
85
93
94#ifndef __cplusplus
95#define EVT_INIT() \
96 _EVT_INIT()
97#endif
98
106
107#ifndef __cplusplus
108#define EVT_CREATE() \
109 { EVT_INIT () }
110/** alias of EVT_CREATE() */
111#define EVT_NEW \
112 EVT_CREATE
113#endif
114
115#ifdef __cplusplus
116extern "C" {
117#endif
118
125void evt_init( evt_t *evt );
126
135void evt_reset( evt_t *evt );
136
138__STATIC_INLINE
139void evt_kill( evt_t *evt ) { evt_reset(evt); }
140
155int evt_waitFor( evt_t *evt, unsigned *event, cnt_t delay );
156
169int evt_waitUntil( evt_t *evt, unsigned *event, cnt_t time );
170
180
181__STATIC_INLINE
182int evt_wait( evt_t *evt, unsigned *event ) { return evt_waitFor(evt, event, INFINITE); }
183
191void evt_give( evt_t *evt, unsigned event );
192
193#ifdef __cplusplus
194}
195#endif
196
197/* -------------------------------------------------------------------------- */
198
199#if defined(__cplusplus)
200namespace intros {
201
206struct Event : public __evt
207{
209 constexpr
210 Event(): __evt _EVT_INIT() {}
211
212 ~Event() { assert(__evt::obj.queue == nullptr); }
213
214 /// move constructor
215 Event( Event&& _src ): __evt(_src)
216 {
217 assert(_src.obj.queue == nullptr);
218 }
219
220 Event( const Event& ) = delete;
221 Event& operator=( Event&& ) = delete;
222 Event& operator=( const Event& ) = delete;
224 void reset () { evt_reset (this); }
225 void kill () { evt_kill (this); }
226 template<typename T>
227 int waitFor ( unsigned *_event, const T& _delay ) { return evt_waitFor (this, _event, Clock::count(_delay)); }
228 template<typename T>
229 int waitFor ( unsigned &_event, const T& _delay ) { return evt_waitFor (this, &_event, Clock::count(_delay)); }
230 template<typename T>
231 int waitUntil( unsigned *_event, const T& _time ) { return evt_waitUntil(this, _event, Clock::until(_time)); }
232 template<typename T>
233 int waitUntil( unsigned &_event, const T& _time ) { return evt_waitUntil(this, &_event, Clock::until(_time)); }
234 int wait ( unsigned *_event = nullptr ) { return evt_wait (this, _event); }
235 int wait ( unsigned &_event ) { return evt_wait (this, &_event); }
236 void give ( unsigned _event ) { evt_give (this, _event); }
237
238};
239
240} // namespace
241#endif//__cplusplus
242
243/* -------------------------------------------------------------------------- */
244
246
247#endif//__INTROS_EVT_H
#define INFINITE
infinite waiting
Definition osbase.h:250
int evt_waitFor(evt_t *evt, unsigned *event, cnt_t delay)
wait for release the event object for given duration of time
void evt_init(evt_t *evt)
initialize an event object
void evt_give(evt_t *evt, unsigned event)
resume all tasks that are waiting on the event object
int evt_waitUntil(evt_t *evt, unsigned *event, cnt_t time)
wait for release the event object until given timepoint
void evt_kill(evt_t *evt)
alias of evt_reset()
Definition osevent.h:138
int evt_wait(evt_t *evt, unsigned *event)
wait indefinitely until the event object has been released
Definition osevent.h:181
void evt_reset(evt_t *evt)
reset the event object and wake up all waiting tasks with 'E_STOPPED' event value
static constexpr rep until(const std::chrono::time_point< Clock, _Duration > &_time)
time point in ticks, rounded up to whole ticks (only a time point of this clock)
Definition osclock.h:109
static constexpr rep count(const std::chrono::duration< _Rep, _Period > &_delay)
delay in ticks, rounded up to whole ticks; negative delay: IMMEDIATE, delay out of range: INFINITE
Definition osclock.h:102
create and initialize an event object
Definition osevent.h:206
void reset()
evt_reset()
Definition osevent.h:223
void give(unsigned _event)
evt_give()
Definition osevent.h:235
int waitUntil(unsigned *_event, const T &_time)
evt_waitUntil()
Definition osevent.h:230
int wait(unsigned *_event=nullptr)
evt_wait()
Definition osevent.h:233
int waitFor(unsigned *_event, const T &_delay)
evt_waitFor()
Definition osevent.h:226
void kill()
evt_kill()
Definition osevent.h:224
int wait(unsigned &_event)
evt_wait()
Definition osevent.h:234
constexpr Event()
constructor, see the constructor parameters of the class
Definition osevent.h:209