summaryrefslogtreecommitdiffstats
path: root/cpukit/score/include/rtems/score/processormask.h
blob: 5a78dd33c642d5c57968b61361cc792a5ea34e4a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
 * @file
 *
 * @brief Processor Mask API
 *
 * @ingroup ScoreProcessorMask
 */

/*
 * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Dornierstr. 4
 *  82178 Puchheim
 *  Germany
 *  <rtems@embedded-brains.de>
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 */

#ifndef _RTEMS_SCORE_PROCESSORMASK_H
#define _RTEMS_SCORE_PROCESSORMASK_H

#include <rtems/score/cpu.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/**
 * @defgroup ScoreProcessorMask Processor Mask
 *
 * @ingroup Score
 *
 * The processor mask provides a bit map large enough to provide one bit for
 * each processor in the system.  It is a fixed size internal data type
 * provided for efficiency in addition to the API level cpu_set_t.
 *
 * @{
 */

#define PROCESSOR_MASK_BITS_PER_FIELD 32

#define PROCESSOR_MASK_FIELD_COUNT \
  ( ( CPU_MAXIMUM_PROCESSORS + PROCESSOR_MASK_BITS_PER_FIELD - 1 ) \
    / PROCESSOR_MASK_BITS_PER_FIELD )

#define PROCESSOR_MASK_BIT( index ) \
  (1UL << ( ( index ) % PROCESSOR_MASK_BITS_PER_FIELD ) )

#define PROCESSOR_MASK_FIELD( index ) \
  ( ( index ) / PROCESSOR_MASK_BITS_PER_FIELD )

/**
 * @brief A bit map consisting of 32-bit integer fields which is large enough
 * to provide one bit for each processor in the system.
 *
 * Processor 0 corresponds to the bit 0 (least-significant) of the field 0 in
 * the array, and so on.
 */
typedef uint32_t Processor_mask[ PROCESSOR_MASK_FIELD_COUNT ];

RTEMS_INLINE_ROUTINE void _Processor_mask_Set( Processor_mask mask, uint32_t index )
{
  mask[ PROCESSOR_MASK_FIELD( index ) ] |= PROCESSOR_MASK_BIT( index );
}

RTEMS_INLINE_ROUTINE void _Processor_mask_Clear( Processor_mask mask, uint32_t index )
{
  mask[ PROCESSOR_MASK_FIELD( index ) ] &= ~PROCESSOR_MASK_BIT( index );
}

RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_set(
  const Processor_mask mask,
  uint32_t index
)
{
  return ( mask[ PROCESSOR_MASK_FIELD( index ) ]
    & PROCESSOR_MASK_BIT( index ) ) != 0;
}

/** @} */

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* _RTEMS_SCORE_PROCESSORMASK_H */