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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [compat/] [posix/] [current/] [src/] [pprivate.h] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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