source: rtems/cpukit/libcsupport/src/gxx_wrappers.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 6.8 KB
Line 
1/*
2 *  RTEMS threads compatibility routines for libgcc2.
3 *
4 *  by: Rosimildo da Silva (rdasilva@connecttel.com)
5 *
6 *  Used ideas from:
7 *    W. Eric Norum
8 *    Canadian Light Source
9 *    University of Saskatchewan
10 *    Saskatoon, Saskatchewan, CANADA
11 *    eric@cls.usask.ca
12 *
13 *  Eric sent some e-mail in the rtems-list as a start point for this
14 *  module implementation.
15 */
16
17/*
18 * This file is only used if using gcc
19 */
20#if defined(__GNUC__)
21
22#if HAVE_CONFIG_H
23#include "config.h"
24#endif
25
26#include <rtems/gxx_wrappers.h>
27
28#include <stdlib.h>
29
30#include <rtems.h>
31
32/* uncomment this if you need to debug this interface */
33/*#define DEBUG_GXX_WRAPPERS 1*/
34
35int rtems_gxx_once(__gthread_once_t *once, void (*func) (void))
36{
37  #ifdef DEBUG_GXX_WRAPPERS
38    printk( "gxx_wrappers: once=%x, func=%x\n", *once, func );
39  #endif
40
41  if ( *(volatile __gthread_once_t *)once == 0 ) {
42    rtems_mode saveMode;
43    __gthread_once_t o;
44
45    rtems_task_mode(RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &saveMode);
46    if ( (o = *(volatile __gthread_once_t *)once) == 0 ) {
47      *(volatile __gthread_once_t *)once = 1;
48    }
49    rtems_task_mode(saveMode, RTEMS_PREEMPT_MASK, &saveMode);
50    if ( o == 0 )
51      (*func)();
52  }
53  return 0;
54}
55
56int rtems_gxx_key_create (__gthread_key_t *key, void (*dtor) (void *))
57{
58  rtems_status_code status;
59
60  /* Ok, this can be a bit tricky. We are going to return a "key" as a
61   * pointer to the buffer that will hold the value of the key itself.
62   * We have to to this, because the others functions on this interface
63   * deal with the value of the key, as used with the POSIX API.
64   */
65   /* Do not pull your hair, trust me this works. :-) */
66  __gthread_key_t new_key = (__gthread_key_t) malloc( sizeof( *new_key ) );
67  *key = new_key;
68  new_key->val  = NULL;
69  new_key->dtor = dtor;
70
71  #ifdef DEBUG_GXX_WRAPPERS
72    printk(
73      "gxx_wrappers: create key=%x, dtor=%x, new_key=%x\n", key, dtor, new_key
74    );
75  #endif
76
77  /* register with RTEMS the buffer that will hold the key values */
78  status = rtems_task_variable_add( RTEMS_SELF, (void **)new_key, dtor );
79  if ( status == RTEMS_SUCCESSFUL )
80    return 0;
81
82  free( new_key );
83  return -1;
84}
85
86int rtems_gxx_key_dtor (__gthread_key_t key, void *ptr)
87{
88  #ifdef DEBUG_GXX_WRAPPERS
89    printk( "gxx_wrappers: dtor key=%x, ptr=%x\n", key, ptr );
90  #endif
91
92  key->val  = 0;
93  return 0;
94}
95
96int rtems_gxx_key_delete (__gthread_key_t key)
97{
98  rtems_status_code status;
99
100  #ifdef DEBUG_GXX_WRAPPERS
101    printk( "gxx_wrappers: delete key=%x\n", key );
102  #endif
103
104  /* register with RTEMS the buffer that will hold the key values */
105  status = rtems_task_variable_delete( RTEMS_SELF, (void **)key );
106  if ( status == RTEMS_SUCCESSFUL ) {
107    /* Hmm - hopefully all tasks using this key have gone away... */
108    if ( key ) free( *(void **)key );
109    return 0;
110  }
111  key = NULL;
112  return 0;
113}
114
115void *rtems_gxx_getspecific(__gthread_key_t key)
116{
117  rtems_status_code  status;
118  void              *p= 0;
119
120  /* register with RTEMS the buffer that will hold the key values */
121  status = rtems_task_variable_get( RTEMS_SELF, (void **)key, &p );
122  if ( status == RTEMS_SUCCESSFUL ) {
123    /* We do not have to do this, but what the heck ! */
124     p= key->val;
125  } else {
126    /* fisrt time, always set to zero, it is unknown the value that the others
127     * threads are using at the moment of this call
128     */
129    status = rtems_task_variable_add( RTEMS_SELF, (void **)key, key->dtor );
130    if ( status != RTEMS_SUCCESSFUL ) {
131      _Internal_error_Occurred(
132        INTERNAL_ERROR_CORE,
133        true,
134        INTERNAL_ERROR_GXX_KEY_ADD_FAILED
135      );
136    }
137    key->val = (void *)0;
138  }
139
140  #ifdef DEBUG_GXX_WRAPPERS
141    printk(
142      "gxx_wrappers: getspecific key=%x, ptr=%x, id=%x\n",
143       key,
144       p,
145       rtems_task_self()
146    );
147  #endif
148  return p;
149}
150
151int rtems_gxx_setspecific(__gthread_key_t key, const void *ptr)
152{
153  rtems_status_code status;
154
155  #ifdef DEBUG_GXX_WRAPPERS
156    printk(
157      "gxx_wrappers: setspecific key=%x, ptr=%x, id=%x\n",
158      key,
159      ptr,
160      rtems_task_self()
161      );
162  #endif
163
164  /* register with RTEMS the buffer that will hold the key values */
165  status = rtems_task_variable_add( RTEMS_SELF, (void **)key, key->dtor );
166  if ( status == RTEMS_SUCCESSFUL ) {
167    /* now let's set the proper value */
168    key->val =  (void *)ptr;
169    return 0;
170  }
171  return -1;
172}
173
174
175/*
176 * MUTEX support
177 */
178void rtems_gxx_mutex_init (__gthread_mutex_t *mutex)
179{
180  rtems_status_code status;
181
182  #ifdef DEBUG_GXX_WRAPPERS
183    printk( "gxx_wrappers: mutex init =%X\n", *mutex );
184  #endif
185
186  status = rtems_semaphore_create(
187    rtems_build_name ('G', 'C', 'C', '2'),
188    1,
189    RTEMS_PRIORITY|RTEMS_BINARY_SEMAPHORE|
190      RTEMS_INHERIT_PRIORITY|RTEMS_NO_PRIORITY_CEILING|RTEMS_LOCAL,
191    0,
192    (rtems_id *)mutex
193  );
194  if ( status != RTEMS_SUCCESSFUL ) {
195    #ifdef DEBUG_GXX_WRAPPERS
196      printk(
197        "gxx_wrappers: mutex init failed %s (%d)\n",
198        rtems_status_text(status),
199        status
200      );
201    #endif
202    _Internal_error_Occurred(
203      INTERNAL_ERROR_CORE,
204      true,
205      INTERNAL_ERROR_GXX_MUTEX_INIT_FAILED
206    );
207  }
208  #ifdef DEBUG_GXX_WRAPPERS
209    printk( "gxx_wrappers: mutex init complete =%X\n", *mutex );
210  #endif
211}
212
213int rtems_gxx_mutex_lock (__gthread_mutex_t *mutex)
214{
215  rtems_status_code status;
216
217  #ifdef DEBUG_GXX_WRAPPERS
218    printk( "gxx_wrappers: lock mutex=%X\n", *mutex );
219  #endif
220
221  status = rtems_semaphore_obtain(
222    *(rtems_id *)mutex,
223    RTEMS_WAIT,
224    RTEMS_NO_TIMEOUT
225  );
226  if ( status == RTEMS_SUCCESSFUL )
227    return 0;
228  return -1;
229}
230
231int rtems_gxx_mutex_destroy (__gthread_mutex_t *mutex)
232{
233  rtems_status_code status;
234
235  #ifdef DEBUG_GXX_WRAPPERS
236    printk( "gxx_wrappers: destroy mutex=%X\n", *mutex );
237  #endif
238
239  status = rtems_semaphore_delete(*(rtems_id *)mutex);
240  if ( status == RTEMS_SUCCESSFUL )
241    return 0;
242  return -1;
243}
244
245int rtems_gxx_mutex_trylock (__gthread_mutex_t *mutex)
246{
247  rtems_status_code status;
248
249  #ifdef DEBUG_GXX_WRAPPERS
250    printk( "gxx_wrappers: trylock mutex=%X\n", *mutex );
251  #endif
252
253  status = rtems_semaphore_obtain (*(rtems_id *)mutex, RTEMS_NO_WAIT, 0);
254  if ( status == RTEMS_SUCCESSFUL )
255    return 0;
256  return -1;
257}
258
259int rtems_gxx_mutex_unlock (__gthread_mutex_t *mutex)
260{
261  rtems_status_code status;
262
263  #ifdef DEBUG_GXX_WRAPPERS
264    printk( "gxx_wrappers: unlock mutex=%X\n", *mutex );
265  #endif
266
267  status = rtems_semaphore_release( *(rtems_id *)mutex );
268  if ( status == RTEMS_SUCCESSFUL )
269    return 0;
270  return -1;
271}
272
273void rtems_gxx_recursive_mutex_init(__gthread_recursive_mutex_t *mutex)
274{
275  rtems_gxx_mutex_init(mutex);
276}
277
278int rtems_gxx_recursive_mutex_lock(__gthread_recursive_mutex_t *mutex)
279{
280  return rtems_gxx_mutex_lock(mutex);
281}
282
283int rtems_gxx_recursive_mutex_trylock(__gthread_recursive_mutex_t *mutex)
284{
285  return rtems_gxx_mutex_trylock(mutex);
286}
287
288int rtems_gxx_recursive_mutex_unlock(__gthread_recursive_mutex_t *mutex)
289{
290  return rtems_gxx_mutex_unlock(mutex);
291}
292
293#endif /* __GNUC__ */
Note: See TracBrowser for help on using the repository browser.