Xenomai API  2.5.6.1
ksrc/skins/posix/thread.h
00001 /*
00002  * Written by Gilles Chanteperdrix <[email protected]>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 
00020 #ifndef _POSIX_THREAD_H
00021 #define _POSIX_THREAD_H
00022 
00023 #include <posix/internal.h>
00024 
00025 typedef unsigned long long pse51_sigset_t;
00026 
00027 struct mm_struct;
00028 
00029 struct pse51_hkey {
00030 
00031     unsigned long u_tid;
00032     struct mm_struct *mm;
00033 };
00034 
00035 typedef struct {
00036     pse51_sigset_t mask;
00037     xnpqueue_t list;
00038 } pse51_sigqueue_t;
00039 
00040 struct pse51_thread {
00041     unsigned magic;
00042     xnthread_t threadbase;
00043 
00044 #define thread2pthread(taddr) ({                                        \
00045     xnthread_t *_taddr = (taddr);                                       \
00046     (_taddr                                                             \
00047     ? ((xnthread_get_magic(_taddr) == PSE51_SKIN_MAGIC)                 \
00048        ? ((pthread_t)(((char *)_taddr)- offsetof(struct pse51_thread,   \
00049                                                  threadbase)))          \
00050        : NULL)                                                          \
00051     : NULL);                                                            \
00052 })
00053 
00054 
00055    xnholder_t link;     /* Link in pse51_threadq */
00056    xnqueue_t *container;
00057 
00058 #define link2pthread(laddr) \
00059     ((pthread_t)(((char *)laddr) - offsetof(struct pse51_thread, link)))
00060 
00061 
00062     pthread_attr_t attr;        /* creation attributes */
00063 
00064     void *(*entry)(void *arg);  /* start routine */
00065     void *arg;                  /* start routine argument */
00066 
00067     /* For pthread_join */
00068     void *exit_status;
00069     xnsynch_t join_synch;       /* synchronization object, used by other threads
00070                                    waiting for this one to finish. */
00071     int nrt_joiners;
00072 
00073     /* For pthread_cancel */
00074     unsigned cancelstate : 2;
00075     unsigned canceltype : 2;
00076     unsigned cancel_request : 1;
00077     xnqueue_t cleanup_handlers_q;
00078 
00079     /* errno value for this thread. */
00080     int err;
00081 
00082     /* For signals handling. */
00083     pse51_sigset_t sigmask;     /* signals mask. */
00084     pse51_sigqueue_t pending;   /* Pending signals */
00085     pse51_sigqueue_t blocked_received; /* Blocked signals received. */
00086 
00087     /* For thread specific data. */
00088     const void *tsd [PTHREAD_KEYS_MAX];
00089 
00090     /* For timers. */
00091     xnqueue_t timersq;
00092 
00093 #ifdef CONFIG_XENO_OPT_PERVASIVE
00094     struct pse51_hkey hkey;
00095 #endif /* CONFIG_XENO_OPT_PERVASIVE */
00096 };
00097 
00098 #define PSE51_JOINED_DETACHED XNTHREAD_INFO_SPARE0
00099 
00100 #define pse51_current_thread() thread2pthread(xnpod_current_thread())
00101 
00102 static inline void thread_set_errno (int err)
00103 {
00104         *xnthread_get_errno_location(xnpod_current_thread()) = err;
00105 }
00106 
00107 static inline int thread_get_errno (void)
00108 {
00109         return *xnthread_get_errno_location(xnpod_current_thread());
00110 }
00111 
00112 #define thread_name(thread) ((thread)->attr.name)
00113 
00114 #define thread_exit_status(thread) ((thread)->exit_status)
00115 
00116 #define thread_getdetachstate(thread) ((thread)->attr.detachstate)
00117 
00118 #define thread_setdetachstate(thread, state) ((thread)->attr.detachstate=state)
00119 
00120 #define thread_getcancelstate(thread) ((thread)->cancelstate)
00121 
00122 #define thread_setcancelstate(thread, state) ((thread)->cancelstate=state)
00123 
00124 #define thread_setcanceltype(thread, type) ((thread)->canceltype=type)
00125 
00126 #define thread_getcanceltype(thread) ((thread)->canceltype)
00127 
00128 #define thread_clrcancel(thread) ((thread)->cancel_request = 0)
00129 
00130 #define thread_setcancel(thread) ((thread)->cancel_request = 1)
00131 
00132 #define thread_cleanups(thread) (&(thread)->cleanup_handlers_q)
00133 
00134 #define thread_gettsd(thread, key) ((thread)->tsd[key])
00135 
00136 #define thread_settsd(thread, key, value) ((thread)->tsd[key]=(value))
00137 
00138 void pse51_thread_abort(pthread_t thread, void *status);
00139 
00140 static inline void thread_cancellation_point (xnthread_t *thread)
00141 {
00142     pthread_t cur = thread2pthread(thread);
00143 
00144     if(cur && cur->cancel_request
00145         && thread_getcancelstate(cur) == PTHREAD_CANCEL_ENABLE )
00146         pse51_thread_abort(cur, PTHREAD_CANCELED);
00147 }
00148 
00149 void pse51_threadq_cleanup(pse51_kqueues_t *q);
00150 
00151 void pse51_thread_pkg_init(u_long rrperiod);
00152 
00153 void pse51_thread_pkg_cleanup(void);
00154 
00155 /* round-robin period. */
00156 extern xnticks_t pse51_time_slice;
00157 
00158 #endif /* !_POSIX_THREAD_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines