source: rtems/cpukit/libcsupport/include/rtems/libcsupport.h @ c42be504

5
Last change on this file since c42be504 was c42be504, checked in by Sebastian Huber <sebastian.huber@…>, on 11/16/16 at 13:50:09

posix: Add self-contained pthread spinlock

Turn pthread_spinlock_t into a self-contained object. On uni-processor
configurations, interrupts are disabled in the lock/trylock operations
and the previous interrupt status is restored in the corresponding
unlock operations. On SMP configurations, a ticket lock is a acquired
and released in addition.

The self-contained pthread_spinlock_t object is defined by Newlib in
<sys/_pthreadtypes.h>.

typedef struct {

struct _Ticket_lock_Control _lock;
uint32_t _interrupt_state;

} pthread_spinlock_t;

This implementation is simple and efficient. However, this test case of
the Linux Test Project would fail due to call of printf() and sleep()
during spin lock ownership:

https://github.com/linux-test-project/ltp/blob/master/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_lock/1-2.c

There is only limited support for profiling on SMP configurations.

Delete CORE spinlock implementation.

Update #2674.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/**
2 * @file
3 *
4 * @brief Standard C Library Support
5 *
6 * This include file contains the information regarding the
7 * RTEMS specific support for the standard C library.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2011.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#ifndef _RTEMS_RTEMS_LIBCSUPPORT_H
20#define _RTEMS_RTEMS_LIBCSUPPORT_H
21
22#include <sys/types.h>
23#include <stdint.h>
24
25#include <rtems/score/heap.h>
26#include <rtems/rtems/tasks.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/**
33 * @defgroup libcsupport Standard C Library Support
34 *
35 * @brief RTEMS Specific Support for the Standard C Library
36 *
37 */
38/**@{**/
39
40extern void malloc_dump(void);
41
42/**
43 * @brief Malloc walk.
44 */
45extern bool malloc_walk(int source, bool printf_enabled);
46
47/**
48 * @brief Set malloc heap pointer.
49 *
50 * This routine is primarily used for debugging.
51 */
52void malloc_set_heap_pointer(Heap_Control *new_heap);
53
54/**
55 * @brief Get malloc heap pointer.
56 *
57 * This routine is primarily used for debugging.
58 */
59Heap_Control *malloc_get_heap_pointer( void );
60
61/**
62 * @brief Get free malloc information.
63 *
64 * Find amount of free heap remaining
65 */
66extern size_t malloc_free_space(void);
67
68/**
69 * @brief Get malloc status information.
70 *
71 * Find amount of free heap remaining.
72 */
73extern int malloc_info(Heap_Information_block *the_info);
74
75/*
76 *  Prototypes required to install newlib reentrancy user extension
77 */
78bool newlib_create_hook(
79  rtems_tcb *current_task,
80  rtems_tcb *creating_task
81);
82
83void newlib_terminate_hook(
84  rtems_tcb *current_task
85);
86
87#define RTEMS_NEWLIB_EXTENSION \
88{ \
89  newlib_create_hook,     /* rtems_task_create  */ \
90  0,                      /* rtems_task_start   */ \
91  0,                      /* rtems_task_restart */ \
92  0,                      /* rtems_task_delete  */ \
93  0,                      /* task_switch  */ \
94  0,                      /* task_begin   */ \
95  0,                      /* task_exitted */ \
96  0,                      /* fatal        */ \
97  newlib_terminate_hook   /* thread terminate */ \
98}
99
100typedef struct {
101  uint32_t active_barriers;
102  uint32_t active_extensions;
103  uint32_t active_message_queues;
104  uint32_t active_partitions;
105  uint32_t active_periods;
106  uint32_t active_ports;
107  uint32_t active_regions;
108  uint32_t active_semaphores;
109  uint32_t active_tasks;
110  uint32_t active_timers;
111} rtems_resource_rtems_api;
112
113typedef struct {
114  uint32_t active_barriers;
115  uint32_t active_condition_variables;
116  uint32_t active_message_queues;
117  uint32_t active_mutexes;
118  uint32_t active_rwlocks;
119  uint32_t active_semaphores;
120  uint32_t active_threads;
121  uint32_t active_timers;
122} rtems_resource_posix_api;
123
124typedef struct {
125  Heap_Information_block workspace_info;
126  Heap_Information_block heap_info;
127  uint32_t active_posix_key_value_pairs;
128  uint32_t active_posix_keys;
129  rtems_resource_rtems_api rtems_api;
130  rtems_resource_posix_api posix_api;
131  int open_files;
132} rtems_resource_snapshot;
133
134/**
135 * @brief Tasks a snapshot of the resource usage of the system.
136 *
137 * @param[out] snapshot The snapshot of used resources.
138 *
139 * @see rtems_resource_snapshot_equal() and rtems_resource_snapshot_check().
140 *
141 * @code
142 * #include <assert.h>
143 *
144 * #include <rtems/libcsupport.h>
145 *
146 * void example(void)
147 * {
148 *   rtems_resource_snapshot before;
149 *
150 *   test_setup();
151 *   rtems_resource_snapshot_take(&before);
152 *   test();
153 *   assert(rtems_resource_snapshot_check(&before));
154 *   test_cleanup();
155 * }
156 * @endcode
157 */
158void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot);
159
160/**
161 * @brief Compares two resource snapshots for equality.
162 *
163 * @param[in] a One resource snapshot.
164 * @param[in] b Another resource snapshot.
165 *
166 * @retval true The resource snapshots are equal.
167 * @retval false Otherwise.
168 *
169 * @see rtems_resource_snapshot_take().
170 */
171bool rtems_resource_snapshot_equal(
172  const rtems_resource_snapshot *a,
173  const rtems_resource_snapshot *b
174);
175
176/**
177 * @brief Takes a new resource snapshot and checks that it is equal to the
178 * given resource snapshot.
179 *
180 * @param[in] snapshot The resource snapshot used for comparison with the new
181 * resource snapshot.
182 *
183 * @retval true The resource snapshots are equal.
184 * @retval false Otherwise.
185 *
186 * @see rtems_resource_snapshot_take().
187 */
188bool rtems_resource_snapshot_check(const rtems_resource_snapshot *snapshot);
189
190/** @} */
191
192#ifdef __cplusplus
193}
194#endif
195
196#endif
197/* end of include file */
Note: See TracBrowser for help on using the repository browser.