ksrc/skins/posix/thread.h

00001 /*
00002  * Written by Gilles Chanteperdrix <gilles.chanteperdrix@laposte.net>.
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 #include <nucleus/select.h>
00025 
00026 typedef unsigned long long pse51_sigset_t;
00027 
00028 struct mm_struct;
00029 
00030 struct pse51_hkey {
00031 
00032     unsigned long u_tid;
00033     struct mm_struct *mm;
00034 };
00035 
00036 typedef struct {
00037     pse51_sigset_t mask;
00038     xnpqueue_t list;
00039 } pse51_sigqueue_t;
00040 
00041 struct pse51_thread {
00042     unsigned magic;
00043     xnthread_t threadbase;
00044 
00045 #define thread2pthread(taddr) ({                                        \
00046     xnthread_t *_taddr = (taddr);                                       \
00047     (_taddr                                                             \
00048     ? ((xnthread_get_magic(_taddr) == PSE51_SKIN_MAGIC)                 \
00049        ? ((pthread_t)(((char *)_taddr)- offsetof(struct pse51_thread,   \
00050                                                  threadbase)))          \
00051        : NULL)                                                          \
00052     : NULL);                                                            \
00053 })
00054 
00055 
00056    xnholder_t link;     /* Link in pse51_threadq */
00057    xnqueue_t *container;
00058     
00059 #define link2pthread(laddr) \
00060     ((pthread_t)(((char *)laddr) - offsetof(struct pse51_thread, link)))
00061     
00062 
00063     pthread_attr_t attr;        /* creation attributes */
00064 
00065     void *(*entry)(void *arg);  /* start routine */
00066     void *arg;                  /* start routine argument */
00067 
00068     /* For pthread_join */
00069     void *exit_status;
00070     xnsynch_t join_synch;       /* synchronization object, used by other threads
00071                                    waiting for this one to finish. */
00072     int nrt_joiners;
00073 
00074     /* For pthread_cancel */
00075     unsigned cancelstate : 2;
00076     unsigned canceltype : 2;
00077     unsigned cancel_request : 1;
00078     xnqueue_t cleanup_handlers_q;
00079 
00080     /* errno value for this thread. */
00081     int err;
00082 
00083     /* For signals handling. */
00084     pse51_sigset_t sigmask;     /* signals mask. */
00085     pse51_sigqueue_t pending;   /* Pending signals */
00086     pse51_sigqueue_t blocked_received; /* Blocked signals received. */
00087 
00088     /* For thread specific data. */
00089     const void *tsd [PTHREAD_KEYS_MAX];
00090 
00091     /* For timers. */
00092     xnqueue_t timersq;
00093     
00094     /* For select. */
00095     struct xnselector *selector;
00096 
00097 #ifdef CONFIG_XENO_OPT_PERVASIVE
00098     struct pse51_hkey hkey;
00099 #endif /* CONFIG_XENO_OPT_PERVASIVE */
00100 };
00101 
00102 #define PSE51_JOINED_DETACHED XNTHREAD_INFO_SPARE0
00103 
00104 #define pse51_current_thread() thread2pthread(xnpod_current_thread())
00105 
00106 static inline void thread_set_errno (int err)
00107 {
00108     *xnthread_get_errno_location() = err;
00109 }
00110 
00111 static inline int thread_get_errno (void)
00112 {
00113     return *xnthread_get_errno_location();
00114 }
00115 
00116 #define thread_name(thread) ((thread)->attr.name)
00117 
00118 #define thread_exit_status(thread) ((thread)->exit_status)
00119 
00120 #define thread_getdetachstate(thread) ((thread)->attr.detachstate)
00121 
00122 #define thread_setdetachstate(thread, state) ((thread)->attr.detachstate=state)
00123 
00124 #define thread_getcancelstate(thread) ((thread)->cancelstate)
00125 
00126 #define thread_setcancelstate(thread, state) ((thread)->cancelstate=state)
00127 
00128 #define thread_setcanceltype(thread, type) ((thread)->canceltype=type)
00129 
00130 #define thread_getcanceltype(thread) ((thread)->canceltype)
00131 
00132 #define thread_clrcancel(thread) ((thread)->cancel_request = 0)
00133 
00134 #define thread_setcancel(thread) ((thread)->cancel_request = 1)
00135 
00136 #define thread_cleanups(thread) (&(thread)->cleanup_handlers_q)
00137 
00138 #define thread_gettsd(thread, key) ((thread)->tsd[key])
00139 
00140 #define thread_settsd(thread, key, value) ((thread)->tsd[key]=(value))
00141 
00142 void pse51_thread_abort(pthread_t thread, void *status);
00143 
00144 static inline void thread_cancellation_point (xnthread_t *thread)
00145 {
00146     pthread_t cur = thread2pthread(thread);
00147     
00148     if(cur && cur->cancel_request
00149         && thread_getcancelstate(cur) == PTHREAD_CANCEL_ENABLE )
00150         pse51_thread_abort(cur, PTHREAD_CANCELED);
00151 }
00152 
00153 void pse51_threadq_cleanup(pse51_kqueues_t *q);
00154 
00155 void pse51_thread_pkg_init(u_long rrperiod);
00156 
00157 void pse51_thread_pkg_cleanup(void);
00158 
00159 /* round-robin period. */
00160 extern xnticks_t pse51_time_slice;
00161 
00162 #endif /* !_POSIX_THREAD_H */

Generated on Mon Mar 24 18:02:40 2008 for Xenomai API by  doxygen 1.5.3