IntrOS
Loading...
Searching...
No Matches
oslist.h
1/******************************************************************************
2
3 @file IntrOS: oslist.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_LST_H
33#define __INTROS_LST_H
34
35#include "oskernel.h"
36#include "osclock.h"
37
43
47
48typedef struct __que que_t;
49
50struct __que
51{
52 que_t * next;
53};
54
55/******************************************************************************
56 *
57 * Name : _QUE_INIT
58 *
59 * Description : create and initialize a queue object
60 *
61 * Parameters : none
62 *
63 * Return : queue object
64 *
65 * Note : for internal use
66 *
67 ******************************************************************************/
68
69#define _QUE_INIT() { NULL }
70
74
75typedef struct __lst lst_t;
76
77struct __lst
78{
79 obj_t obj;
80
81 que_t head;
82};
83
84typedef struct __lst lst_id [];
85
86/******************************************************************************
87 *
88 * Name : _LST_INIT
89 *
90 * Description : create and initialize a list object
91 *
92 * Parameters : none
93 *
94 * Return : list object
95 *
96 * Note : for internal use
97 *
98 ******************************************************************************/
99
100#define _LST_INIT() { _OBJ_INIT(), _QUE_INIT() }
101
108#define OS_LST( lst ) \
109 lst_t lst[] = { _LST_INIT() }
110
111/** static alias of OS_LST() */
112#define static_LST( lst ) \
113 static lst_t lst[] = { _LST_INIT() }
114
122
123#ifndef __cplusplus
124#define LST_INIT() \
125 _LST_INIT()
126#endif
127
135
136#ifndef __cplusplus
137#define LST_CREATE() \
138 { LST_INIT () }
139/** alias of LST_CREATE() */
140#define LST_NEW \
141 LST_CREATE
142#endif
143
144#ifdef __cplusplus
145extern "C" {
146#endif
147
154void lst_init( lst_t *lst );
155
164void lst_reset( lst_t *lst );
165
167__STATIC_INLINE
168void lst_kill( lst_t *lst ) { lst_reset(lst); }
169
181int lst_take( lst_t *lst, void **data );
182
184__STATIC_INLINE
185int lst_tryWait( lst_t *lst, void **data ) { return lst_take(lst, data); }
186
202int lst_waitFor( lst_t *lst, void **data, cnt_t delay );
203
217int lst_waitUntil( lst_t *lst, void **data, cnt_t time );
218
229
230__STATIC_INLINE
231int lst_wait( lst_t *lst, void **data ) { return lst_waitFor(lst, data, INFINITE); }
232
241void lst_give( lst_t *lst, void *data );
242
243#ifdef __cplusplus
244}
245#endif
246
247/* -------------------------------------------------------------------------- */
248
249#if defined(__cplusplus)
250namespace intros {
251
258
259template<class C>
260struct ListTT : public __lst
261{
263 constexpr
264 ListTT(): __lst _LST_INIT() {}
265
266 ~ListTT() { assert(__lst::obj.queue == nullptr); }
267
268 /// move constructor
269 ListTT( ListTT&& _src ): __lst(_src)
270 {
271 assert(_src.obj.queue == nullptr && _src.head.next == nullptr);
272 }
273
274 ListTT( const ListTT& ) = delete;
275 ListTT& operator=( ListTT&& ) = delete;
276 ListTT& operator=( const ListTT& ) = delete;
278 void reset () { lst_reset (this); }
279 void kill () { lst_kill (this); }
280 int take ( C **_data ) { return lst_take (this, reinterpret_cast<void **>(_data)); }
281 int tryWait ( C **_data ) { return lst_tryWait (this, reinterpret_cast<void **>(_data)); }
282 template<typename T>
283 int waitFor ( C **_data, const T& _delay ) { return lst_waitFor (this, reinterpret_cast<void **>(_data), Clock::count(_delay)); }
284 template<typename T>
285 int waitUntil( C **_data, const T& _time ) { return lst_waitUntil(this, reinterpret_cast<void **>(_data), Clock::until(_time)); }
286 int wait ( C **_data ) { return lst_wait (this, reinterpret_cast<void **>(_data)); }
287 void give ( void *_data ) { lst_give (this, _data); }
288};
289
293
294using List = ListTT<void>;
295
296} // namespace
297#endif//__cplusplus
298
299/* -------------------------------------------------------------------------- */
300
302
303#endif//__INTROS_LST_H
#define INFINITE
infinite waiting
Definition osbase.h:250
void lst_init(lst_t *lst)
initialize a list object
void lst_reset(lst_t *lst)
wake up all waiting tasks with 'E_STOPPED' event value
int lst_waitUntil(lst_t *lst, void **data, cnt_t time)
try to get memory object from the list object, wait until given timepoint while the list object is em...
void lst_give(lst_t *lst, void *data)
transfer memory object to the list object,
int lst_take(lst_t *lst, void **data)
try to get memory object from the list object, don't wait if the list object is empty
int lst_wait(lst_t *lst, void **data)
try to get memory object from the list object, wait indefinitely while the list object is empty
Definition oslist.h:230
void lst_kill(lst_t *lst)
alias of lst_reset()
Definition oslist.h:167
int lst_waitFor(lst_t *lst, void **data, cnt_t delay)
try to get memory object from the list object, wait for given duration of time while the list object ...
int lst_tryWait(lst_t *lst, void **data)
alias of lst_take()
Definition oslist.h:184
char data[]
message data
Definition osmessagequeue.h:54
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 a list object
Definition oslist.h:260
int waitFor(void **_data, const T &_delay)
Definition oslist.h:282
int waitUntil(void **_data, const T &_time)
Definition oslist.h:284
int wait(void **_data)
Definition oslist.h:285
int tryWait(C **_data)
lst_tryWait()
Definition oslist.h:280
void kill()
Definition oslist.h:278
int take(void **_data)
Definition oslist.h:279
constexpr ListTT()
constructor, see the constructor parameters of the class
Definition oslist.h:263
void give(void *_data)
lst_give()
Definition oslist.h:286
void reset()
Definition oslist.h:277