RTEMS CPU Kit with SuperCore  4.11.3
chain.h
Go to the documentation of this file.
1 
7 /*
8  * Copyright (c) 2010-2014 embedded brains GmbH.
9  *
10  * COPYRIGHT (c) 1989-2008.
11  * On-Line Applications Research Corporation (OAR).
12  *
13  * The license and distribution terms for this file may be
14  * found in the file LICENSE in this distribution or at
15  * http://www.rtems.org/license/LICENSE.
16  */
17 
18 #ifndef _RTEMS_CHAIN_H
19 #define _RTEMS_CHAIN_H
20 
21 #include <rtems/score/chainimpl.h>
22 #include <rtems/rtems/event.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
38 
40 
44 #define RTEMS_CHAIN_INITIALIZER_EMPTY( name ) \
45  CHAIN_INITIALIZER_EMPTY( name )
46 
52 #define RTEMS_CHAIN_INITIALIZER_ONE_NODE( node ) \
53  CHAIN_INITIALIZER_ONE_NODE( node )
54 
60 #define RTEMS_CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN( chain ) \
61  CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN( chain )
62 
66 #define RTEMS_CHAIN_DEFINE_EMPTY( name ) \
67  rtems_chain_control name = RTEMS_CHAIN_INITIALIZER_EMPTY( name )
68 
79  rtems_chain_control *chain,
80  rtems_chain_node *node,
81  rtems_id task,
82  rtems_event_set events
83 );
84 
95  rtems_chain_control *chain,
96  rtems_chain_node *node,
97  rtems_id task,
98  rtems_event_set events
99 );
100 
111  rtems_chain_control *chain,
112  rtems_id task,
113  rtems_event_set events,
114  rtems_chain_node **node
115 );
116 
127  rtems_chain_control *chain,
128  rtems_event_set events,
129  rtems_interval timeout,
130  rtems_chain_node **node
131 );
132 
147  rtems_chain_control *the_chain,
148  void *starting_address,
149  size_t number_nodes,
150  size_t node_size
151 )
152 {
154  the_chain,
155  starting_address,
156  number_nodes,
157  node_size
158  );
159 }
160 
169  rtems_chain_control *the_chain
170 )
171 {
172  _Chain_Initialize_empty( the_chain );
173 }
174 
184  rtems_chain_node *node
185 )
186 {
187  _Chain_Set_off_chain( node );
188 }
189 
202  const rtems_chain_node *node
203 )
204 {
205  return _Chain_Is_node_off_chain( node );
206 }
207 
219  const rtems_chain_node *the_node
220 )
221 {
222  return _Chain_Is_null_node( the_node );
223 }
224 
235  rtems_chain_control *the_chain
236 )
237 {
238  return _Chain_Head( the_chain );
239 }
240 
251  const rtems_chain_control *the_chain
252 )
253 {
254  return _Chain_Immutable_head( the_chain );
255 }
256 
267  rtems_chain_control *the_chain
268 )
269 {
270  return _Chain_Tail( the_chain );
271 }
272 
283  const rtems_chain_control *the_chain
284 )
285 {
286  return _Chain_Immutable_tail( the_chain );
287 }
288 
300  rtems_chain_control *the_chain
301 )
302 {
303  return _Chain_First( the_chain );
304 }
305 
317  const rtems_chain_control *the_chain
318 )
319 {
320  return _Chain_Immutable_first( the_chain );
321 }
322 
334  rtems_chain_control *the_chain
335 )
336 {
337  return _Chain_Last( the_chain );
338 }
339 
351  const rtems_chain_control *the_chain
352 )
353 {
354  return _Chain_Immutable_last( the_chain );
355 }
356 
367  rtems_chain_node *the_node
368 )
369 {
370  return _Chain_Next( the_node );
371 }
372 
383  const rtems_chain_node *the_node
384 )
385 {
386  return _Chain_Immutable_next( the_node );
387 }
388 
399  rtems_chain_node *the_node
400 )
401 {
402  return _Chain_Previous( the_node );
403 }
404 
415  const rtems_chain_node *the_node
416 )
417 {
418  return _Chain_Immutable_previous( the_node );
419 }
420 
434  const rtems_chain_node *left,
435  const rtems_chain_node *right
436 )
437 {
438  return _Chain_Are_nodes_equal( left, right );
439 }
440 
453  const rtems_chain_control *the_chain
454 )
455 {
456  return _Chain_Is_empty( the_chain );
457 }
458 
472  const rtems_chain_node *the_node
473 )
474 {
475  return _Chain_Is_first( the_node );
476 }
477 
490  const rtems_chain_node *the_node
491 )
492 {
493  return _Chain_Is_last( the_node );
494 }
495 
508  const rtems_chain_control *the_chain
509 )
510 {
511  return _Chain_Has_only_one_node( the_chain );
512 }
513 
527  const rtems_chain_control *the_chain,
528  const rtems_chain_node *the_node
529 )
530 {
531  return _Chain_Is_head( the_chain, the_node );
532 }
533 
547  const rtems_chain_control *the_chain,
548  const rtems_chain_node *the_node
549 )
550 {
551  return _Chain_Is_tail( the_chain, the_node );
552 }
553 
563 #if defined( RTEMS_SMP )
565  rtems_chain_node *the_node
566 );
567 #else
569  rtems_chain_node *the_node
570 )
571 {
572  _Chain_Extract( the_node );
573 }
574 #endif
575 
585  rtems_chain_node *the_node
586 )
587 {
588  _Chain_Extract_unprotected( the_node );
589 }
590 
603 #if defined( RTEMS_SMP )
604 rtems_chain_node *rtems_chain_get(
605  rtems_chain_control *the_chain
606 );
607 #else
609  rtems_chain_control *the_chain
610 )
611 {
612  return _Chain_Get( the_chain );
613 }
614 #endif
615 
620  rtems_chain_control *the_chain
621 )
622 {
623  return _Chain_Get_unprotected( the_chain );
624 }
625 
635 #if defined( RTEMS_SMP )
636 void rtems_chain_insert(
637  rtems_chain_node *after_node,
638  rtems_chain_node *the_node
639 );
640 #else
642  rtems_chain_node *after_node,
643  rtems_chain_node *the_node
644 )
645 {
646  _Chain_Insert( after_node, the_node );
647 }
648 #endif
649 
654  rtems_chain_node *after_node,
655  rtems_chain_node *the_node
656 )
657 {
658  _Chain_Insert_unprotected( after_node, the_node );
659 }
660 
669 #if defined( RTEMS_SMP )
670 void rtems_chain_append(
671  rtems_chain_control *the_chain,
672  rtems_chain_node *the_node
673 );
674 #else
676  rtems_chain_control *the_chain,
677  rtems_chain_node *the_node
678 )
679 {
680  _Chain_Append( the_chain, the_node );
681 }
682 #endif
683 
693  rtems_chain_control *the_chain,
694  rtems_chain_node *the_node
695 )
696 {
697  _Chain_Append_unprotected( the_chain, the_node );
698 }
699 
711 #if defined( RTEMS_SMP )
713  rtems_chain_control *the_chain,
714  rtems_chain_node *the_node
715 );
716 #else
718  rtems_chain_control *the_chain,
719  rtems_chain_node *the_node
720 )
721 {
722  _Chain_Prepend( the_chain, the_node );
723 }
724 #endif
725 
738  rtems_chain_control *the_chain,
739  rtems_chain_node *the_node
740 )
741 {
742  _Chain_Prepend_unprotected( the_chain, the_node );
743 }
744 
753 #if defined( RTEMS_SMP )
755  rtems_chain_control *chain,
756  rtems_chain_node *node
757 );
758 #else
760  rtems_chain_control *chain,
761  rtems_chain_node *node
762 )
763 {
764  return _Chain_Append_with_empty_check( chain, node );
765 }
766 #endif
767 
776 #if defined( RTEMS_SMP )
778  rtems_chain_control *chain,
779  rtems_chain_node *node
780 );
781 #else
783  rtems_chain_control *chain,
784  rtems_chain_node *node
785 )
786 {
787  return _Chain_Prepend_with_empty_check( chain, node );
788 }
789 #endif
790 
803 #if defined( RTEMS_SMP )
805  rtems_chain_control *chain,
806  rtems_chain_node **node
807 );
808 #else
810  rtems_chain_control *chain,
811  rtems_chain_node **node
812 )
813 {
814  return _Chain_Get_with_empty_check( chain, node );
815 }
816 #endif
817 
829  const rtems_chain_control *chain
830 )
831 {
832  return _Chain_Node_count_unprotected( chain );
833 }
834 
837 #ifdef __cplusplus
838 }
839 #endif
840 
841 #endif
842 /* end of include file */
RTEMS_INLINE_ROUTINE void _Chain_Prepend(Chain_Control *the_chain, Chain_Node *the_node)
Prepend a node (protected).
Definition: chainimpl.h:806
RTEMS_INLINE_ROUTINE rtems_chain_node * rtems_chain_tail(rtems_chain_control *the_chain)
Return pointer to Chain Tail.
Definition: chain.h:266
RTEMS_INLINE_ROUTINE void _Chain_Append_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Append a node (unprotected).
Definition: chainimpl.h:743
This is used to manage each element (node) which is placed on a chain.
Definition: chain.h:65
RTEMS_INLINE_ROUTINE Chain_Node * _Chain_Head(Chain_Control *the_chain)
Return pointer to chain head.
Definition: chainimpl.h:301
RTEMS_INLINE_ROUTINE bool rtems_chain_has_only_one_node(const rtems_chain_control *the_chain)
Does this chain have only one node.
Definition: chain.h:507
rtems_status_code rtems_chain_get_with_notification(rtems_chain_control *chain, rtems_id task, rtems_event_set events, rtems_chain_node **node)
Gets the first node of the chain and sends the events to the task if the chain is empty after the get...
Definition: chaingetnotify.c:29
RTEMS_INLINE_ROUTINE void rtems_chain_initialize_empty(rtems_chain_control *the_chain)
Initialize this chain as empty.
Definition: chain.h:168
RTEMS_INLINE_ROUTINE void rtems_chain_extract_unprotected(rtems_chain_node *the_node)
Extract the specified node from a chain (unprotected).
Definition: chain.h:584
Chain_Node * _Chain_Get(Chain_Control *the_chain)
Obtain the first node on a chain.
Definition: chainget.c:26
RTEMS_INLINE_ROUTINE const rtems_chain_node * rtems_chain_immutable_tail(const rtems_chain_control *the_chain)
Return pointer to immutable Chain Tail.
Definition: chain.h:282
RTEMS_INLINE_ROUTINE Chain_Node * _Chain_Next(Chain_Node *the_node)
Return pointer the next node from this node.
Definition: chainimpl.h:433
rtems_status_code rtems_chain_prepend_with_notification(rtems_chain_control *chain, rtems_chain_node *node, rtems_id task, rtems_event_set events)
Prepends the node to the chain and sends the events to the task if the chain was empty before the pre...
Definition: chainprependnotify.c:29
RTEMS_INLINE_ROUTINE rtems_chain_node * rtems_chain_last(rtems_chain_control *the_chain)
Return pointer to Chain&#39;s Last node before the permanent tail.
Definition: chain.h:333
Objects_Id rtems_id
Used to manage and manipulate RTEMS object identifiers.
Definition: types.h:80
void _Chain_Initialize(Chain_Control *the_chain, void *starting_address, size_t number_nodes, size_t node_size)
Initialize a chain header.
Definition: chain.c:26
bool _Chain_Prepend_with_empty_check(Chain_Control *the_chain, Chain_Node *the_node)
Prepend a node and check if the chain was empty before.
Definition: chainprependempty.c:31
RTEMS_INLINE_ROUTINE Chain_Node * _Chain_Previous(Chain_Node *the_node)
Return pointer the previous node from this node.
Definition: chainimpl.h:465
RTEMS_INLINE_ROUTINE const rtems_chain_node * rtems_chain_immutable_first(const rtems_chain_control *the_chain)
Return pointer to immutable Chain&#39;s First node.
Definition: chain.h:316
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
void _Chain_Extract(Chain_Node *the_node)
Extract the specified node from a chain.
Definition: chainextract.c:27
RTEMS_INLINE_ROUTINE size_t rtems_chain_node_count_unprotected(const rtems_chain_control *chain)
Returns the node count of the chain.
Definition: chain.h:828
RTEMS_INLINE_ROUTINE bool rtems_chain_append_with_empty_check(rtems_chain_control *chain, rtems_chain_node *node)
Checks if the chain is empty and appends the node.
Definition: chain.h:759
This is used to manage a chain.
Definition: chain.h:83
RTEMS_INLINE_ROUTINE bool rtems_chain_is_last(const rtems_chain_node *the_node)
Is this the last node on the chain.
Definition: chain.h:489
RTEMS_INLINE_ROUTINE bool _Chain_Are_nodes_equal(const Chain_Node *left, const Chain_Node *right)
Are two nodes equal.
Definition: chainimpl.h:267
RTEMS_INLINE_ROUTINE const Chain_Node * _Chain_Immutable_head(const Chain_Control *the_chain)
Return pointer to immutable chain head.
Definition: chainimpl.h:317
RTEMS_INLINE_ROUTINE bool rtems_chain_prepend_with_empty_check(rtems_chain_control *chain, rtems_chain_node *node)
Checks if the chain is empty and prepends the node.
Definition: chain.h:782
RTEMS_INLINE_ROUTINE bool _Chain_Is_node_off_chain(const Chain_Node *node)
Is the node off chain.
Definition: chainimpl.h:248
RTEMS_INLINE_ROUTINE void _Chain_Extract_unprotected(Chain_Node *the_node)
Extract this node (unprotected).
Definition: chainimpl.h:639
RTEMS_INLINE_ROUTINE void _Chain_Initialize_empty(Chain_Control *the_chain)
Initialize this chain as empty.
Definition: chainimpl.h:613
rtems_status_code rtems_chain_get_with_wait(rtems_chain_control *chain, rtems_event_set events, rtems_interval timeout, rtems_chain_node **node)
Gets the first node of the chain and sends the events to the task if the chain is empty afterwards...
Definition: chaingetwait.c:29
RTEMS_INLINE_ROUTINE void rtems_chain_append_unprotected(rtems_chain_control *the_chain, rtems_chain_node *the_node)
Append a node on the end of a chain (unprotected).
Definition: chain.h:692
Watchdog_Interval rtems_interval
Used to manage and manipulate intervals specified by clock ticks.
Definition: types.h:119
RTEMS_INLINE_ROUTINE const Chain_Node * _Chain_Immutable_previous(const Chain_Node *the_node)
Return pointer the immutable previous node from this node.
Definition: chainimpl.h:481
RTEMS_INLINE_ROUTINE bool _Chain_Is_empty(const Chain_Control *the_chain)
Is the chain empty.
Definition: chainimpl.h:499
RTEMS_INLINE_ROUTINE rtems_chain_node * rtems_chain_next(rtems_chain_node *the_node)
Return pointer the next node from this node.
Definition: chain.h:366
RTEMS_INLINE_ROUTINE rtems_chain_node * rtems_chain_get_unprotected(rtems_chain_control *the_chain)
See _Chain_Get_unprotected().
Definition: chain.h:619
RTEMS_INLINE_ROUTINE void rtems_chain_insert_unprotected(rtems_chain_node *after_node, rtems_chain_node *the_node)
See _Chain_Insert_unprotected().
Definition: chain.h:653
rtems_status_code rtems_chain_append_with_notification(rtems_chain_control *chain, rtems_chain_node *node, rtems_id task, rtems_event_set events)
Appends the node to the chain and sends the events to the task if the chain was empty before the appe...
Definition: chainappendnotify.c:29
RTEMS_INLINE_ROUTINE void rtems_chain_prepend_unprotected(rtems_chain_control *the_chain, rtems_chain_node *the_node)
Prepend a node (unprotected).
Definition: chain.h:737
rtems_status_code
Classic API Status.
Definition: status.h:46
RTEMS_INLINE_ROUTINE void rtems_chain_set_off_chain(rtems_chain_node *node)
Set off chain.
Definition: chain.h:183
RTEMS_INLINE_ROUTINE bool _Chain_Has_only_one_node(const Chain_Control *the_chain)
Does this chain have only one node.
Definition: chainimpl.h:558
RTEMS_INLINE_ROUTINE Chain_Node * _Chain_Get_unprotected(Chain_Control *the_chain)
Get the first node (unprotected).
Definition: chainimpl.h:695
RTEMS_INLINE_ROUTINE bool rtems_chain_is_node_off_chain(const rtems_chain_node *node)
Is the node off chain.
Definition: chain.h:201
RTEMS_INLINE_ROUTINE bool rtems_chain_get_with_empty_check(rtems_chain_control *chain, rtems_chain_node **node)
Tries to get the first node and check if the chain is empty afterwards.
Definition: chain.h:809
uint32_t rtems_event_set
Integer type to hold an event set of up to 32 events represented as a bit field.
Definition: event.h:51
RTEMS_INLINE_ROUTINE Chain_Node * _Chain_Last(Chain_Control *the_chain)
Return pointer to chain&#39;s last node.
Definition: chainimpl.h:400
size_t _Chain_Node_count_unprotected(const Chain_Control *chain)
Returns the node count of the chain.
Definition: chainnodecount.c:22
RTEMS_INLINE_ROUTINE bool _Chain_Is_last(const Chain_Node *the_node)
Is this the last node on the chain.
Definition: chainimpl.h:537
void _Chain_Insert(Chain_Node *after_node, Chain_Node *the_node)
Insert a node on a chain.
Definition: chaininsert.c:43
RTEMS_INLINE_ROUTINE bool rtems_chain_is_head(const rtems_chain_control *the_chain, const rtems_chain_node *the_node)
Is this node the chain head.
Definition: chain.h:526
RTEMS_INLINE_ROUTINE const Chain_Node * _Chain_Immutable_first(const Chain_Control *the_chain)
Return pointer to immutable chain&#39;s first node.
Definition: chainimpl.h:383
RTEMS_INLINE_ROUTINE Chain_Node * _Chain_Tail(Chain_Control *the_chain)
Return pointer to chain tail.
Definition: chainimpl.h:333
RTEMS_INLINE_ROUTINE const Chain_Node * _Chain_Immutable_next(const Chain_Node *the_node)
Return pointer the immutable next node from this node.
Definition: chainimpl.h:449
Chain Handler API.
RTEMS_INLINE_ROUTINE const rtems_chain_node * rtems_chain_immutable_next(const rtems_chain_node *the_node)
Return pointer the immutable next node from this node.
Definition: chain.h:382
RTEMS_INLINE_ROUTINE void rtems_chain_extract(rtems_chain_node *the_node)
Extract the specified node from a chain.
Definition: chain.h:568
bool _Chain_Append_with_empty_check(Chain_Control *the_chain, Chain_Node *the_node)
Append a node and check if the chain was empty before.
Definition: chainappendempty.c:31
RTEMS_INLINE_ROUTINE Chain_Node * _Chain_First(Chain_Control *the_chain)
Return pointer to chain&#39;s first node.
Definition: chainimpl.h:366
RTEMS_INLINE_ROUTINE void _Chain_Insert_unprotected(Chain_Node *after_node, Chain_Node *the_node)
Insert a node (unprotected).
Definition: chainimpl.h:718
RTEMS_INLINE_ROUTINE bool rtems_chain_is_first(const rtems_chain_node *the_node)
Is this the first node on the chain.
Definition: chain.h:471
RTEMS_INLINE_ROUTINE bool rtems_chain_is_null_node(const rtems_chain_node *the_node)
Is the chain node pointer NULL.
Definition: chain.h:218
RTEMS_INLINE_ROUTINE void rtems_chain_insert(rtems_chain_node *after_node, rtems_chain_node *the_node)
Insert a node on a chain.
Definition: chain.h:641
bool _Chain_Get_with_empty_check(Chain_Control *the_chain, Chain_Node **the_node)
Get the first node and check if the chain is empty afterwards.
Definition: chaingetempty.c:31
RTEMS_INLINE_ROUTINE bool rtems_chain_are_nodes_equal(const rtems_chain_node *left, const rtems_chain_node *right)
Are Two nodes equal.
Definition: chain.h:433
RTEMS_INLINE_ROUTINE rtems_chain_node * rtems_chain_first(rtems_chain_control *the_chain)
Return pointer to Chain&#39;s First node after the permanent head.
Definition: chain.h:299
void _Chain_Append(Chain_Control *the_chain, Chain_Node *the_node)
Append a node on the end of a chain.
Definition: chainappend.c:41
RTEMS_INLINE_ROUTINE rtems_chain_node * rtems_chain_get(rtems_chain_control *the_chain)
Obtain the first node on a chain.
Definition: chain.h:608
RTEMS_INLINE_ROUTINE const rtems_chain_node * rtems_chain_immutable_last(const rtems_chain_control *the_chain)
Return pointer to immutable Chain&#39;s Last node.
Definition: chain.h:350
RTEMS_INLINE_ROUTINE bool rtems_chain_is_tail(const rtems_chain_control *the_chain, const rtems_chain_node *the_node)
Is this node the chain tail.
Definition: chain.h:546
RTEMS_INLINE_ROUTINE bool rtems_chain_is_empty(const rtems_chain_control *the_chain)
Is the chain empty.
Definition: chain.h:452
RTEMS_INLINE_ROUTINE bool _Chain_Is_tail(const Chain_Control *the_chain, const Chain_Node *the_node)
Is this node the chail tail.
Definition: chainimpl.h:598
RTEMS_INLINE_ROUTINE bool _Chain_Is_first(const Chain_Node *the_node)
Is this the first node on the chain.
Definition: chainimpl.h:519
RTEMS_INLINE_ROUTINE rtems_chain_node * rtems_chain_previous(rtems_chain_node *the_node)
Return pointer the previous node from this node.
Definition: chain.h:398
RTEMS_INLINE_ROUTINE void _Chain_Set_off_chain(Chain_Node *node)
Set off chain.
Definition: chainimpl.h:230
RTEMS_INLINE_ROUTINE bool _Chain_Is_null_node(const Chain_Node *the_node)
Is the chain node pointer NULL.
Definition: chainimpl.h:285
RTEMS_INLINE_ROUTINE void rtems_chain_append(rtems_chain_control *the_chain, rtems_chain_node *the_node)
Append a node on the end of a chain.
Definition: chain.h:675
RTEMS_INLINE_ROUTINE void rtems_chain_initialize(rtems_chain_control *the_chain, void *starting_address, size_t number_nodes, size_t node_size)
Initialize a chain Header.
Definition: chain.h:146
RTEMS_INLINE_ROUTINE const Chain_Node * _Chain_Immutable_tail(const Chain_Control *the_chain)
Return pointer to immutable chain tail.
Definition: chainimpl.h:349
RTEMS_INLINE_ROUTINE void rtems_chain_prepend(rtems_chain_control *the_chain, rtems_chain_node *the_node)
Prepend a node.
Definition: chain.h:717
RTEMS_INLINE_ROUTINE bool _Chain_Is_head(const Chain_Control *the_chain, const Chain_Node *the_node)
Is this node the chain head.
Definition: chainimpl.h:578
RTEMS_INLINE_ROUTINE const Chain_Node * _Chain_Immutable_last(const Chain_Control *the_chain)
Return pointer to immutable chain&#39;s last node.
Definition: chainimpl.h:417
RTEMS_INLINE_ROUTINE void _Chain_Prepend_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Prepend a node (unprotected).
Definition: chainimpl.h:787
RTEMS_INLINE_ROUTINE const rtems_chain_node * rtems_chain_immutable_previous(const rtems_chain_node *the_node)
Return pointer the immutable previous node from this node.
Definition: chain.h:414
RTEMS_INLINE_ROUTINE rtems_chain_node * rtems_chain_head(rtems_chain_control *the_chain)
Return pointer to Chain Head.
Definition: chain.h:234
RTEMS_INLINE_ROUTINE const rtems_chain_node * rtems_chain_immutable_head(const rtems_chain_control *the_chain)
Return pointer to immutable Chain Head.
Definition: chain.h:250