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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [compat/] [posix/] [v2_0/] [src/] [pprivate.h] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
#ifndef CYGONCE_PPRIVATE_H
2
#define CYGONCE_PPRIVATE_H
3
//=============================================================================
4
//
5
//      pprivate.h
6
//
7
//      POSIX types header
8
//
9
//=============================================================================
10
//####ECOSGPLCOPYRIGHTBEGIN####
11
// -------------------------------------------
12
// This file is part of eCos, the Embedded Configurable Operating System.
13
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14
//
15
// eCos is free software; you can redistribute it and/or modify it under
16
// the terms of the GNU General Public License as published by the Free
17
// Software Foundation; either version 2 or (at your option) any later version.
18
//
19
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22
// for more details.
23
//
24
// You should have received a copy of the GNU General Public License along
25
// with eCos; if not, write to the Free Software Foundation, Inc.,
26
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27
//
28
// As a special exception, if other files instantiate templates or use macros
29
// or inline functions from this file, or you compile this file and link it
30
// with other works to produce a work based on this file, this file does not
31
// by itself cause the resulting work to be covered by the GNU General Public
32
// License. However the source code for this file must still be made available
33
// in accordance with section (3) of the GNU General Public License.
34
//
35
// This exception does not invalidate any other reasons why a work based on
36
// this file might be covered by the GNU General Public License.
37
//
38
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39
// at http://sources.redhat.com/ecos/ecos-license/
40
// -------------------------------------------
41
//####ECOSGPLCOPYRIGHTEND####
42
//=============================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):     nickg
46
// Contributors:  nickg
47
// Date:          2000-03-17
48
// Purpose:       POSIX private header
49
// Description:   This header contains various POSIX type definitions that are
50
//                shared between the various parts of the POSIX package.
51
//              
52
// Usage:         #include <pprivate.h>
53
//              
54
//
55
//####DESCRIPTIONEND####
56
//
57
//=============================================================================
58
 
59
#include <pkgconf/hal.h>
60
#include <pkgconf/kernel.h>
61
#include <pkgconf/posix.h>
62
 
63
#include <stddef.h>                     // NULL, size_t
64
 
65
#include <sys/types.h>
66
#include <sched.h>
67
#include <pthread.h>
68
#include <errno.h>                      // error codes
69
#include <signal.h>                     // sigset_t
70
#include <limits.h>                     // PTHREAD_KEYS_MAX
71
 
72
#include <cyg/posix/export.h>           // POSIX exports header
73
 
74
#include <cyg/kernel/thread.hxx>        // thread definitions
75
#include <cyg/kernel/mutex.hxx>         // mutex definitions
76
 
77
//=============================================================================
78
// Constructor prioritization
79
 
80
// Prioritization for POSIX library support objects
81
#define CYGBLD_POSIX_INIT CYGBLD_ATTRIB_INIT_PRI(CYG_INIT_COMPAT)
82
 
83
// Prioritization for POSIX library startup initialization. This must
84
// come after CYGBLD_POSIX_INIT constructors.
85
#define CYGBLD_POSIX_START CYGBLD_ATTRIB_INIT_PRI(CYG_INIT_COMPAT+5)
86
 
87
//=============================================================================
88
// Thread control data structure
89
 
90
// Per-thread information needed by POSIX
91
// This is pointed to by the CYGNUM_KERNEL_THREADS_DATA_POSIX entry of the
92
// per-thread data.
93
 
94
#ifdef CYGPKG_POSIX_PTHREAD
95
typedef struct
96
{
97
    unsigned int        state:4,                // Thread state
98
                        cancelstate:2,          // Cancel state of thread
99
                        canceltype:2,           // Cancel type of thread
100
                        cancelpending:1,        // pending cancel flag
101
                        freestack:1;            // stack malloced, must be freed
102
 
103
    pthread_t           id;                     // My thread ID
104
    Cyg_Thread          *thread;                // pointer to eCos thread object
105
    pthread_attr_t      attr;                   // Current thread attributes
106
    void                *retval;                // return value
107
    void                *(*start_routine)(void *); // start routine
108
    void                *start_arg;             // argument to start routine
109
    char                name[20];               // name string for debugging
110
    Cyg_Condition_Variable *joiner;             // joining threads wait here
111
    CYG_ADDRWORD        stackmem;               // base of stack memory area
112
                                                // only valid if freestack == true
113
 
114
    struct pthread_cleanup_buffer *cancelbuffer; // stack of cleanup buffers
115
 
116
#ifdef CYGPKG_POSIX_SIGNALS
117
    sigset_t            sigpending;     // Set of pending signals
118
    sigset_t            sigmask;        // Thread's signal mask
119
#endif
120
 
121
    // The following is space for the eCos thread object that underlies
122
    // this POSIX thread. It is allocated like this to avoid constructing
123
    // it on startup.
124
    cyg_uint8           thread_obj[sizeof(Cyg_Thread)];
125
 
126
    // And the same for the joiner condition variable.
127
    cyg_uint8           joiner_obj[sizeof(Cyg_Condition_Variable)];
128
 
129
    // Per-thread data table pointer
130
    void                **thread_data;
131
 
132
} pthread_info;
133
 
134
 
135
// Values for the state field. These are solely concerned with the
136
// states visible to POSIX. The thread's run state is stored in the
137
// eCos thread object.
138
// Note: numerical order here is important, do not rearrange.
139
 
140
#define PTHREAD_STATE_FREE      0       // This structure is free for reuse
141
#define PTHREAD_STATE_DETACHED  1       // The thread is running but detached
142
#define PTHREAD_STATE_RUNNING   2       // The thread is running and will wait
143
                                        // to join when it exits
144
#define PTHREAD_STATE_JOIN      3       // The thread has exited and is waiting
145
                                        // to be joined
146
#define PTHREAD_STATE_EXITED    4       // The thread has exited and is ready to
147
                                        // be reaped
148
#endif // ifdef CYGPKG_POSIX_PTHREAD
149
//-----------------------------------------------------------------------------
150
// Internal definitions
151
 
152
// Handle entry to a pthread package function. 
153
#define PTHREAD_ENTRY() CYG_REPORT_FUNCTYPE( "returning %d" )
154
 
155
// Handle entry to a pthread package function with no args. 
156
#define PTHREAD_ENTRY_VOID() CYG_REPORT_FUNCTION()
157
 
158
// Do a pthread package defined return. This requires the error code to be
159
// returned as the result of the function. This also gives us a place to
160
// put any generic tidyup handling needed for things like signal delivery
161
// and cancellation.
162
#define PTHREAD_RETURN(err)                     \
163
CYG_MACRO_START                                 \
164
    CYG_REPORT_RETVAL( err );                   \
165
    return err;                                 \
166
CYG_MACRO_END
167
 
168
// A void variant of the above.
169
#define PTHREAD_RETURN_VOID                     \
170
CYG_MACRO_START                                 \
171
    CYG_REPORT_RETURN();                        \
172
    return;                                     \
173
CYG_MACRO_END
174
 
175
// Check that a pointer passed in as an argument is valid and return
176
// EINVAL if it is not. This should be used to check pointers that are
177
// required to be valid. Pointers that may optionally be NULL should
178
// be checked within the function.
179
#define PTHREAD_CHECK(ptr) if( (ptr) == NULL ) PTHREAD_RETURN(EINVAL);
180
 
181
#ifdef CYGPKG_POSIX_PTHREAD
182
# define PTHREAD_TESTCANCEL() pthread_testcancel()
183
#else
184
# define PTHREAD_TESTCANCEL()
185
#endif
186
 
187
//-----------------------------------------------------------------------------
188
// Priority translation.
189
// eCos priorities run from 0 as the highest to 31 as the lowest. POSIX priorities
190
// run in the opposite direction. The following macros translate between the two
191
// priority ranges.
192
 
193
#define PTHREAD_ECOS_PRIORITY(pri) (CYG_THREAD_MIN_PRIORITY-(pri))
194
 
195
#define PTHREAD_POSIX_PRIORITY(pri) (CYG_THREAD_MIN_PRIORITY-(pri))
196
 
197
//-----------------------------------------------------------------------------
198
// Global data structures
199
 
200
// Mutex for locking access to pthread_info structures
201
extern Cyg_Mutex pthread_mutex;
202
 
203
//-----------------------------------------------------------------------------
204
// Functions exported by pthread.cxx to the other parts of the POSIX subsystem.
205
 
206
#ifdef CYGPKG_POSIX_PTHREAD
207
externC void cyg_posix_pthread_start( void );
208
 
209
externC pthread_info *pthread_self_info(void);
210
 
211
externC pthread_info *pthread_info_id( pthread_t id );
212
 
213
# ifdef CYGPKG_POSIX_SIGNALS
214
externC void cyg_posix_pthread_release_thread( sigset_t *mask );
215
# endif
216
#endif
217
 
218
//-----------------------------------------------------------------------------
219
// Functions exported by signal.cxx to the other parts of the POSIX subsystem.
220
 
221
#ifdef CYGPKG_POSIX_SIGNALS
222
externC void cyg_posix_signal_start();
223
 
224
externC void cyg_posix_signal_asr(pthread_info *self);
225
 
226
externC cyg_bool cyg_sigqueue( const struct sigevent *sev, int code,
227
                               pthread_info *thread = NULL );
228
 
229
externC cyg_bool cyg_deliver_signals();
230
 
231
externC void cyg_posix_signal_sigwait();
232
 
233
externC void cyg_posix_thread_siginit( pthread_info *thread,
234
                                       pthread_info *parentthread );
235
 
236
externC void cyg_posix_thread_sigdestroy( pthread_info *thread );
237
#endif
238
 
239
//-----------------------------------------------------------------------------
240
// Functions exported by time.cxx to other parts of the POSIX subsystem.
241
 
242
#ifdef CYGPKG_POSIX_CLOCKS
243
externC void cyg_posix_clock_start();
244
 
245
externC cyg_tick_count cyg_timespec_to_ticks( const struct timespec *tp,
246
                                         cyg_bool roundup = false);
247
 
248
externC void cyg_ticks_to_timespec( cyg_tick_count ticks, struct timespec *tp );
249
 
250
#endif
251
 
252
#ifdef CYGPKG_POSIX_TIMERS
253
 
254
externC void cyg_posix_timer_asr( pthread_info *self );
255
 
256
#endif
257
 
258
//-----------------------------------------------------------------------------
259
// Functions exported by except.cxx
260
 
261
#ifdef CYGPKG_POSIX_SIGNALS
262
externC void cyg_posix_exception_start();
263
 
264
externC void cyg_pthread_exception_init(pthread_info *thread);
265
 
266
externC void cyg_pthread_exception_destroy(pthread_info *thread);
267
#endif
268
 
269
//-----------------------------------------------------------------------------
270
#endif // ifndef CYGONCE_PPRIVATE_H
271
// End of pprivate.h

powered by: WebSVN 2.1.0

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