RTEMS 6.1-rc4
Loading...
Searching...
No Matches
userextimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * COPYRIGHT (c) 1989-2009.
14 * On-Line Applications Research Corporation (OAR).
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _RTEMS_SCORE_USEREXTIMPL_H
39#define _RTEMS_SCORE_USEREXTIMPL_H
40
43#include <rtems/score/isrlock.h>
44#include <rtems/score/thread.h>
45#include <rtems/score/percpu.h>
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
67 Chain_Iterator Iterator;
68 struct User_extensions_Iterator *previous;
70
71typedef struct {
76
81
82#if defined(RTEMS_SMP)
87 ISR_lock_Control Lock;
88#endif
90
95
100
111
118 User_extensions_Control *extension
119);
120
126static inline void _User_extensions_Add_API_set(
127 User_extensions_Control *extension
128)
129{
130 _User_extensions_Add_set( extension );
131}
132
139static inline void _User_extensions_Add_set_with_table(
140 User_extensions_Control *extension,
141 const User_extensions_Table *extension_table
142)
143{
144 extension->Callouts = *extension_table;
145
146 _User_extensions_Add_set( extension );
147}
148
155 User_extensions_Control *extension
156);
157
166 Thread_Control *executing,
167 void *arg,
168 const User_extensions_Table *callouts
169);
170
171typedef struct {
172 Thread_Control *created;
173 bool ok;
175
184 Thread_Control *executing,
185 void *arg,
186 const User_extensions_Table *callouts
187);
188
197 Thread_Control *executing,
198 void *arg,
199 const User_extensions_Table *callouts
200);
201
210 Thread_Control *executing,
211 void *arg,
212 const User_extensions_Table *callouts
213);
214
223 Thread_Control *executing,
224 void *arg,
225 const User_extensions_Table *callouts
226);
227
236 Thread_Control *executing,
237 void *arg,
238 const User_extensions_Table *callouts
239);
240
249 Thread_Control *executing,
250 void *arg,
251 const User_extensions_Table *callouts
252);
253
254typedef struct {
256 Internal_errors_t error;
258
267 Thread_Control *executing,
268 void *arg,
269 const User_extensions_Table *callouts
270);
271
280 Thread_Control *executing,
281 void *arg,
282 const User_extensions_Table *callouts
283);
284
293 void *arg,
296);
297
313static inline bool _User_extensions_Thread_create( Thread_Control *created )
314{
315 User_extensions_Thread_create_context ctx = { created, true };
316
318 &ctx,
321 );
322
323 return ctx.ok;
324}
325
331static inline void _User_extensions_Thread_delete( Thread_Control *deleted )
332{
334 deleted,
337 );
338}
339
345static inline void _User_extensions_Thread_start( Thread_Control *started )
346{
348 started,
351 );
352}
353
359static inline void _User_extensions_Thread_restart( Thread_Control *restarted )
360{
362 restarted,
365 );
366}
367
373static inline void _User_extensions_Thread_begin( Thread_Control *executing )
374{
376 executing,
379 );
380}
381
388static inline void _User_extensions_Thread_switch(
389 Thread_Control *executing,
390 Thread_Control *heir
391)
392{
393 const Chain_Control *chain;
394 const Chain_Node *tail;
395 const Chain_Node *node;
396
398 tail = _Chain_Immutable_tail( chain );
399 node = _Chain_Immutable_first( chain );
400
401 if ( node != tail ) {
402#if defined(RTEMS_SMP)
403 ISR_lock_Context lock_context;
404 Per_CPU_Control *cpu_self;
405
406 cpu_self = _Per_CPU_Get();
407
408 _ISR_lock_ISR_disable( &lock_context );
409 _Per_CPU_Acquire( cpu_self, &lock_context );
410
411 executing = cpu_self->ancestor;
412 cpu_self->ancestor = heir;
413 node = _Chain_Immutable_first( chain );
414
415 /*
416 * An executing thread equal to the heir thread may happen in two
417 * situations. Firstly, in case context switch extensions are created after
418 * system initialization. Secondly, during a thread self restart.
419 */
420 if ( executing != heir ) {
421#endif
422
423 while ( node != tail ) {
424 const User_extensions_Switch_control *extension;
425
426 extension = (const User_extensions_Switch_control *) node;
427 node = _Chain_Immutable_next( node );
428 (*extension->thread_switch)( executing, heir );
429 }
430
431#if defined(RTEMS_SMP)
432 }
433
434 _Per_CPU_Release( cpu_self, &lock_context );
435 _ISR_lock_ISR_enable( &lock_context );
436#endif
437 }
438}
439
445static inline void _User_extensions_Thread_exitted( Thread_Control *executing )
446{
448 executing,
451 );
452}
453
460static inline void _User_extensions_Fatal(
462 Internal_errors_t error
463)
464{
465 User_extensions_Fatal_context ctx = { source, error };
466
468 &ctx,
471 );
472}
473
479static inline void _User_extensions_Thread_terminate(
480 Thread_Control *executing
481)
482{
484 executing,
487 );
488}
489
495static inline void _User_extensions_Acquire( ISR_lock_Context *lock_context )
496{
499 lock_context
500 );
501}
502
508static inline void _User_extensions_Release( ISR_lock_Context *lock_context )
509{
512 lock_context
513 );
514}
515
522static inline void _User_extensions_Destroy_iterators(
523 Thread_Control *the_thread
524)
525{
526 ISR_lock_Context lock_context;
528
529 _User_extensions_Acquire( &lock_context );
530
531 iter = the_thread->last_user_extensions_iterator;
532
533 while ( iter != NULL ) {
534 _Chain_Iterator_destroy( &iter->Iterator );
535 iter = iter->previous;
536 }
537
538 _User_extensions_Release( &lock_context );
539}
540
545#ifdef __cplusplus
546}
547#endif
548
549#endif
550/* end of include file */
This header file provides interfaces of the Chain Handler which are only used by the implementation.
Chain_Iterator_direction
The chain iterator direction.
Definition: chainimpl.h:890
@ CHAIN_ITERATOR_BACKWARD
Iteration from tail to head.
Definition: chainimpl.h:899
@ CHAIN_ITERATOR_FORWARD
Iteration from head to tail.
Definition: chainimpl.h:894
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
Definition: isrlock.h:385
#define _ISR_lock_ISR_disable(_context)
Disables interrupts and saves the previous interrupt state in the ISR lock context.
Definition: isrlock.h:364
#define _ISR_lock_Release_and_ISR_enable(_lock, _context)
Releases an ISR lock.
Definition: isrlock.h:229
#define _ISR_lock_ISR_disable_and_acquire(_lock, _context)
Acquires an ISR lock.
Definition: isrlock.h:204
Internal_errors_Source
This type lists the possible sources from which an error can be reported.
Definition: interr.h:63
void _User_extensions_Thread_create_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Creates a visitor.
Definition: userextiterate.c:59
void _User_extensions_Thread_delete_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Deletes a visitor.
Definition: userextiterate.c:74
void _User_extensions_Thread_start_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Starts a visitor.
Definition: userextiterate.c:87
void _User_extensions_Iterate(void *arg, User_extensions_Visitor visitor, Chain_Iterator_direction direction)
Iterates through all user extensions and calls the visitor for each.
Definition: userextiterate.c:170
void _User_extensions_Remove_set(User_extensions_Control *extension)
Removes a user extension.
Definition: userextremoveset.c:45
void _User_extensions_Thread_restart_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Restarts a visitor.
Definition: userextiterate.c:100
void(* User_extensions_Visitor)(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
User extension visitor.
Definition: userextimpl.h:165
void _User_extensions_Thread_terminate_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Terminates a visitor.
Definition: userextiterate.c:156
void _User_extensions_Fatal_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Calls the fatal function of the thread callout for the visitor.
Definition: userextiterate.c:141
void _User_extensions_Thread_begin_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Calls the begin function of the thread callout for the visitor.
Definition: userextiterate.c:113
void _User_extensions_Thread_exitted_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Calls the exitted function of the thread callout for the visitor.
Definition: userextiterate.c:128
User_extensions_List _User_extensions_List
List of active extensions.
Definition: userextiterate.c:50
Chain_Control _User_extensions_Switches_list
List of active task switch extensions.
void _User_extensions_Handler_initialization(void)
Initializes the user extensions handler.
Definition: userext.c:44
void _User_extensions_Add_set(User_extensions_Control *extension)
Adds a user extension.
Definition: userextaddset.c:65
This header file provides the interfaces of the ISR Locks.
This header file provides the interfaces of the Per-CPU Information.
This header file provides interfaces of the Thread Handler which are used by the implementation and t...
A registry for chain iterators.
Definition: chainimpl.h:940
A chain iterator which is updated during node extraction if it is properly registered.
Definition: chainimpl.h:908
This structure represents a chain node.
Definition: chain.h:78
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:94
Per CPU Core Structure.
Definition: percpu.h:384
Manages each user extension set.
Definition: userextdata.h:72
Definition: userextimpl.h:254
Chain iterator for dynamic user extensions.
Definition: userextimpl.h:66
Definition: userextimpl.h:71
Chain_Iterator_registry Iterators
Chain iterator registration.
Definition: userextimpl.h:80
Chain_Control Active
Active dynamically added user extensions.
Definition: userextimpl.h:75
Manages the switch callouts.
Definition: userextdata.h:61
User extension table.
Definition: userext.h:253
Definition: userextimpl.h:171
Definition: thread.h:837
struct User_extensions_Iterator * last_user_extensions_iterator
LIFO list of user extensions iterators.
Definition: thread.h:1002
This union represents a chain control block.
Definition: chain.h:96
This header file provides data structures used by the implementation and the Application Configuratio...