OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [gthr-tpf.h] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 jlechner
/* Threads compatibility routines for libgcc2 and libobjc.
2
   Compile this one with gcc.
3
   Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4
 
5
This file is part of GCC.
6
 
7
GCC is free software; you can redistribute it and/or modify it under
8
the terms of the GNU General Public License as published by the Free
9
Software Foundation; either version 2, or (at your option) any later
10
version.
11
 
12
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13
WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15
for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with GCC; see the file COPYING.  If not, write to the Free
19
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20
02110-1301, USA.  */
21
 
22
/* As a special exception, if you link this library with other files,
23
   some of which are compiled with GCC, to produce an executable,
24
   this library does not by itself cause the resulting executable
25
   to be covered by the GNU General Public License.
26
   This exception does not however invalidate any other reasons why
27
   the executable file might be covered by the GNU General Public License.  */
28
 
29
 
30
/* TPF needs its own version of gthr-*.h because TPF always links to
31
   the thread library.  However, for performance reasons we still do not
32
   want to issue thread api calls unless a check is made to see that we
33
   are running as a thread.  */
34
 
35
#ifndef GCC_GTHR_TPF_H
36
#define GCC_GTHR_TPF_H
37
 
38
/* POSIX threads specific definitions.
39
   Easy, since the interface is just one-to-one mapping.  */
40
 
41
#define __GTHREADS 1
42
 
43
/* Some implementations of <pthread.h> require this to be defined.  */
44
#ifndef _REENTRANT
45
#define _REENTRANT 1
46
#endif
47
 
48
#include <pthread.h>
49
#include <unistd.h>
50
 
51
typedef pthread_key_t __gthread_key_t;
52
typedef pthread_once_t __gthread_once_t;
53
typedef pthread_mutex_t __gthread_mutex_t;
54
typedef pthread_mutex_t __gthread_recursive_mutex_t;
55
 
56
#if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
57
#define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
58
#elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
59
#define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
60
#endif
61
 
62
#define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
63
#define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
64
 
65
#define NOTATHREAD   00
66
#define ECBBASEPTR (unsigned long int) *(unsigned int *)0x00000514u
67
#define ECBPG2PTR  ECBBASEPTR + 0x1000
68
#define CE2THRCPTR *((unsigned char *)(ECBPG2PTR + 16))
69
#define __tpf_pthread_active() (CE2THRCPTR != NOTATHREAD)
70
 
71
#if SUPPORTS_WEAK && GTHREAD_USE_WEAK
72
# define __gthrw(name) \
73
  extern __typeof(name) __gthrw_ ## name __attribute__ ((__weakref__(#name)));
74
# define __gthrw_(name) __gthrw_ ## name
75
#else
76
# define __gthrw(name)
77
# define __gthrw_(name) name
78
#endif
79
 
80
__gthrw(pthread_once)
81
__gthrw(pthread_key_create)
82
__gthrw(pthread_key_delete)
83
__gthrw(pthread_getspecific)
84
__gthrw(pthread_setspecific)
85
__gthrw(pthread_create)
86
 
87
__gthrw(pthread_mutex_lock)
88
__gthrw(pthread_mutex_trylock)
89
__gthrw(pthread_mutex_unlock)
90
 
91
static inline int
92
__gthread_active_p (void)
93
{
94
  return 1;
95
}
96
 
97
static inline int
98
__gthread_once (__gthread_once_t *once, void (*func) (void))
99
{
100
  if (__tpf_pthread_active ())
101
    return __gthrw_(pthread_once) (once, func);
102
  else
103
    return -1;
104
}
105
 
106
static inline int
107
__gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
108
{
109
  if (__tpf_pthread_active ())
110
    return __gthrw_(pthread_key_create) (key, dtor);
111
  else
112
    return -1;
113
}
114
 
115
static inline int
116
__gthread_key_delete (__gthread_key_t key)
117
{
118
  if (__tpf_pthread_active ())
119
    return __gthrw_(pthread_key_delete) (key);
120
  else
121
    return -1;
122
}
123
 
124
static inline void *
125
__gthread_getspecific (__gthread_key_t key)
126
{
127
  if (__tpf_pthread_active ())
128
    return __gthrw_(pthread_getspecific) (key);
129
  else
130
    return NULL;
131
}
132
 
133
static inline int
134
__gthread_setspecific (__gthread_key_t key, const void *ptr)
135
{
136
  if (__tpf_pthread_active ())
137
    return __gthrw_(pthread_setspecific) (key, ptr);
138
  else
139
    return -1;
140
}
141
 
142
static inline int
143
__gthread_mutex_lock (__gthread_mutex_t *mutex)
144
{
145
  if (__tpf_pthread_active ())
146
    return __gthrw_(pthread_mutex_lock) (mutex);
147
  else
148
    return 0;
149
}
150
 
151
static inline int
152
__gthread_mutex_trylock (__gthread_mutex_t *mutex)
153
{
154
  if (__tpf_pthread_active ())
155
    return __gthrw_(pthread_mutex_trylock) (mutex);
156
  else
157
    return 0;
158
}
159
 
160
static inline int
161
__gthread_mutex_unlock (__gthread_mutex_t *mutex)
162
{
163
  if (__tpf_pthread_active ())
164
    return __gthrw_(pthread_mutex_unlock) (mutex);
165
  else
166
    return 0;
167
}
168
 
169
static inline int
170
__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
171
{
172
  if (__tpf_pthread_active ())
173
    return __gthread_mutex_lock (mutex);
174
  else
175
    return 0;
176
}
177
 
178
static inline int
179
__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
180
{
181
  if (__tpf_pthread_active ())
182
    return __gthread_mutex_trylock (mutex);
183
  else
184
    return 0;
185
}
186
 
187
static inline int
188
__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
189
{
190
  if (__tpf_pthread_active ())
191
    return __gthread_mutex_unlock (mutex);
192
  else
193
    return 0;
194
}
195
 
196
#endif /* ! GCC_GTHR_TPF_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.