source: rtems/cpukit/score/src/chain.c @ 0daa8ab

5
Last change on this file since 0daa8ab was a3fc33f, checked in by Sebastian Huber <sebastian.huber@…>, on 06/24/15 at 11:36:40

score: Assert proper node size

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/**
2 * @file
3 *
4 * @brief Initialize a Chain Header
5 *
6 * @ingroup ScoreChain
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2007.
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#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/score/chainimpl.h>
23#include <rtems/score/address.h>
24#include <rtems/score/assert.h>
25
26void _Chain_Initialize(
27  Chain_Control *the_chain,
28  void           *starting_address,
29  size_t         number_nodes,
30  size_t         node_size
31)
32{
33  size_t count = number_nodes;
34  Chain_Node *head = _Chain_Head( the_chain );
35  Chain_Node *tail = _Chain_Tail( the_chain );
36  Chain_Node *current = head;
37  Chain_Node *next = starting_address;
38
39  _Assert( node_size >= sizeof( *next ) );
40
41  head->previous = NULL;
42
43  while ( count-- ) {
44    current->next  = next;
45    next->previous = current;
46    current        = next;
47    next           = (Chain_Node *)
48                        _Addresses_Add_offset( (void *) next, node_size );
49  }
50
51  current->next = tail;
52  tail->previous = current;
53}
Note: See TracBrowser for help on using the repository browser.