1 #ifndef CYGONCE_PPRIVATE_H
2 #define CYGONCE_PPRIVATE_H
3 //=============================================================================
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.
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.
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
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.
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.
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.
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####
46 // Contributors: nickg
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.
52 // Usage: #include <pprivate.h>
55 //####DESCRIPTIONEND####
57 //=============================================================================
59 #include <pkgconf/hal.h>
60 #include <pkgconf/kernel.h>
61 #include <pkgconf/posix.h>
63 #include <stddef.h> // NULL, size_t
65 #include <sys/types.h>
68 #include <errno.h> // error codes
69 #include <signal.h> // sigset_t
70 #include <limits.h> // PTHREAD_KEYS_MAX
72 #include <cyg/posix/export.h> // POSIX exports header
74 #include <cyg/kernel/thread.hxx> // thread definitions
75 #include <cyg/kernel/mutex.hxx> // mutex definitions
77 //=============================================================================
78 // Constructor prioritization
80 // Prioritization for POSIX library support objects
81 #define CYGBLD_POSIX_INIT CYGBLD_ATTRIB_INIT_PRI(CYG_INIT_COMPAT)
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)
87 //=============================================================================
88 // Thread control data structure
90 // Per-thread information needed by POSIX
91 // This is pointed to by the CYGNUM_KERNEL_THREADS_DATA_POSIX entry of the
94 #ifdef CYGPKG_POSIX_PTHREAD
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
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
114 struct pthread_cleanup_buffer *cancelbuffer; // stack of cleanup buffers
116 #ifdef CYGPKG_POSIX_SIGNALS
117 sigset_t sigpending; // Set of pending signals
118 sigset_t sigmask; // Thread's signal mask
121 // The following is space for the eCos thread object that underlies
122 // this POSIX thread. It is allocated like this to avoid constructing
124 cyg_uint8 thread_obj[sizeof(Cyg_Thread)];
126 // And the same for the joiner condition variable.
127 cyg_uint8 joiner_obj[sizeof(Cyg_Condition_Variable)];
129 // Per-thread data table pointer
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.
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
146 #define PTHREAD_STATE_EXITED 4 // The thread has exited and is ready to
148 #endif // ifdef CYGPKG_POSIX_PTHREAD
149 //-----------------------------------------------------------------------------
150 // Internal definitions
152 // Handle entry to a pthread package function.
153 #define PTHREAD_ENTRY() CYG_REPORT_FUNCTYPE( "returning %d" )
155 // Handle entry to a pthread package function with no args.
156 #define PTHREAD_ENTRY_VOID() CYG_REPORT_FUNCTION()
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
162 #define PTHREAD_RETURN(err) \
164 CYG_REPORT_RETVAL( err ); \
168 // A void variant of the above.
169 #define PTHREAD_RETURN_VOID \
171 CYG_REPORT_RETURN(); \
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);
181 #ifdef CYGPKG_POSIX_PTHREAD
182 # define PTHREAD_TESTCANCEL() pthread_testcancel()
184 # define PTHREAD_TESTCANCEL()
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
193 #define PTHREAD_ECOS_PRIORITY(pri) (CYG_THREAD_MIN_PRIORITY-(pri))
195 #define PTHREAD_POSIX_PRIORITY(pri) (CYG_THREAD_MIN_PRIORITY-(pri))
197 //-----------------------------------------------------------------------------
198 // Global data structures
200 // Mutex for locking access to pthread_info structures
201 extern Cyg_Mutex pthread_mutex;
203 //-----------------------------------------------------------------------------
204 // Functions exported by pthread.cxx to the other parts of the POSIX subsystem.
206 #ifdef CYGPKG_POSIX_PTHREAD
207 externC void cyg_posix_pthread_start( void );
209 externC pthread_info *pthread_self_info(void);
211 externC pthread_info *pthread_info_id( pthread_t id );
213 # ifdef CYGPKG_POSIX_SIGNALS
214 externC void cyg_posix_pthread_release_thread( sigset_t *mask );
218 //-----------------------------------------------------------------------------
219 // Functions exported by signal.cxx to the other parts of the POSIX subsystem.
221 #ifdef CYGPKG_POSIX_SIGNALS
222 externC void cyg_posix_signal_start();
224 externC void cyg_posix_signal_asr(pthread_info *self);
226 externC cyg_bool cyg_sigqueue( const struct sigevent *sev, int code,
227 pthread_info *thread = NULL );
229 externC cyg_bool cyg_deliver_signals();
231 externC void cyg_posix_signal_sigwait();
233 externC void cyg_posix_thread_siginit( pthread_info *thread,
234 pthread_info *parentthread );
236 externC void cyg_posix_thread_sigdestroy( pthread_info *thread );
239 //-----------------------------------------------------------------------------
240 // Functions exported by time.cxx to other parts of the POSIX subsystem.
242 #ifdef CYGPKG_POSIX_CLOCKS
243 externC void cyg_posix_clock_start();
245 externC cyg_tick_count cyg_timespec_to_ticks( const struct timespec *tp,
246 cyg_bool roundup = false);
248 externC void cyg_ticks_to_timespec( cyg_tick_count ticks, struct timespec *tp );
252 #ifdef CYGPKG_POSIX_TIMERS
254 externC void cyg_posix_timer_asr( pthread_info *self );
258 //-----------------------------------------------------------------------------
259 // Functions exported by except.cxx
261 #ifdef CYGPKG_POSIX_SIGNALS
262 externC void cyg_posix_exception_start();
264 externC void cyg_pthread_exception_init(pthread_info *thread);
266 externC void cyg_pthread_exception_destroy(pthread_info *thread);
269 //-----------------------------------------------------------------------------
270 #endif // ifndef CYGONCE_PPRIVATE_H