00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _POSIX_INTERNAL_H
00020 #define _POSIX_INTERNAL_H
00021
00022 #include <nucleus/xenomai.h>
00023 #include <nucleus/core.h>
00024 #include <nucleus/ppd.h>
00025 #include <posix/posix.h>
00026 #include <posix/registry.h>
00027
00028
00029 #include <nucleus/assert.h>
00030
00031 #ifndef CONFIG_XENO_OPT_DEBUG_POSIX
00032 #define CONFIG_XENO_OPT_DEBUG_POSIX 0
00033 #endif
00034
00035 #define PSE51_MAGIC(n) (0x8686##n##n)
00036 #define PSE51_ANY_MAGIC PSE51_MAGIC(00)
00037 #define PSE51_THREAD_MAGIC PSE51_MAGIC(01)
00038 #define PSE51_THREAD_ATTR_MAGIC PSE51_MAGIC(02)
00039 #define PSE51_MUTEX_MAGIC PSE51_MAGIC(03)
00040 #define PSE51_MUTEX_ATTR_MAGIC (PSE51_MAGIC(04) & ((1 << 24) - 1))
00041 #define PSE51_COND_MAGIC PSE51_MAGIC(05)
00042 #define PSE51_COND_ATTR_MAGIC (PSE51_MAGIC(05) & ((1 << 24) - 1))
00043 #define PSE51_SEM_MAGIC PSE51_MAGIC(06)
00044 #define PSE51_KEY_MAGIC PSE51_MAGIC(07)
00045 #define PSE51_ONCE_MAGIC PSE51_MAGIC(08)
00046 #define PSE51_MQ_MAGIC PSE51_MAGIC(09)
00047 #define PSE51_MQD_MAGIC PSE51_MAGIC(0A)
00048 #define PSE51_INTR_MAGIC PSE51_MAGIC(0B)
00049 #define PSE51_NAMED_SEM_MAGIC PSE51_MAGIC(0C)
00050 #define PSE51_TIMER_MAGIC PSE51_MAGIC(0D)
00051 #define PSE51_SHM_MAGIC PSE51_MAGIC(0E)
00052
00053 #define PSE51_MIN_PRIORITY XNCORE_LOW_PRIO
00054 #define PSE51_MAX_PRIORITY XNCORE_HIGH_PRIO
00055
00056 #define ONE_BILLION 1000000000
00057
00058 #define pse51_obj_active(h,m,t) \
00059 ((h) && ((t *)(h))->magic == (m))
00060
00061 #define pse51_obj_deleted(h,m,t) \
00062 ((h) && ((t *)(h))->magic == ~(m))
00063
00064 #define pse51_mark_deleted(t) ((t)->magic = ~(t)->magic)
00065
00066 typedef struct {
00067 xnqueue_t condq;
00068 xnqueue_t intrq;
00069 xnqueue_t mutexq;
00070 xnqueue_t semq;
00071 xnqueue_t threadq;
00072 xnqueue_t timerq;
00073 } pse51_kqueues_t;
00074
00075 #if defined(__KERNEL__) && defined(CONFIG_XENO_OPT_PERVASIVE)
00076 typedef struct {
00077 pse51_kqueues_t kqueues;
00078 pse51_assocq_t uqds;
00079 pse51_assocq_t usems;
00080 pse51_assocq_t umaps;
00081 pse51_assocq_t ufds;
00082
00083 xnshadow_ppd_t ppd;
00084
00085 #define ppd2queues(addr) \
00086 ((pse51_queues_t *) ((char *) (addr) - offsetof(pse51_queues_t, ppd)))
00087
00088 } pse51_queues_t;
00089
00090 extern int pse51_muxid;
00091 #endif
00092
00093 extern pse51_kqueues_t pse51_global_kqueues;
00094
00095 #if defined(__KERNEL__) && defined(CONFIG_XENO_OPT_PERVASIVE)
00096 static inline pse51_queues_t *pse51_queues(void)
00097 {
00098 xnshadow_ppd_t *ppd;
00099 spl_t s;
00100
00101 xnlock_get_irqsave(&nklock, s);
00102
00103 ppd = xnshadow_ppd_get(pse51_muxid);
00104
00105 xnlock_put_irqrestore(&nklock, s);
00106
00107 if (!ppd)
00108 return NULL;
00109
00110 return ppd2queues(ppd);
00111 }
00112 #endif
00113
00114 static inline pse51_kqueues_t *pse51_kqueues(int pshared)
00115 {
00116 #if defined(__KERNEL__) && defined(CONFIG_XENO_OPT_PERVASIVE)
00117 xnshadow_ppd_t *ppd;
00118
00119 if (pshared || !(ppd = xnshadow_ppd_get(pse51_muxid)))
00120 return &pse51_global_kqueues;
00121
00122 return &ppd2queues(ppd)->kqueues;
00123 #else
00124 return &pse51_global_kqueues;
00125 #endif
00126 }
00127
00128 static inline void ticks2ts(struct timespec *ts, xnticks_t ticks)
00129 {
00130 ts->tv_sec = xnarch_uldivrem(xnpod_ticks2ns(ticks),
00131 ONE_BILLION,
00132 &ts->tv_nsec);
00133 }
00134
00135 static inline xnticks_t ts2ticks_floor(const struct timespec *ts)
00136 {
00137 xntime_t nsecs = ts->tv_nsec;
00138 if(ts->tv_sec)
00139 nsecs += (xntime_t) ts->tv_sec * ONE_BILLION;
00140 return xnpod_ns2ticks(nsecs);
00141 }
00142
00143 static inline xnticks_t ts2ticks_ceil(const struct timespec *ts)
00144 {
00145 xntime_t nsecs = ts->tv_nsec;
00146 unsigned long rem;
00147 xnticks_t ticks;
00148 if(ts->tv_sec)
00149 nsecs += (xntime_t) ts->tv_sec * ONE_BILLION;
00150 ticks = xnarch_ulldiv(nsecs, xnpod_get_tickval(), &rem);
00151 return rem ? ticks+1 : ticks;
00152 }
00153
00154 static inline xnticks_t clock_get_ticks(clockid_t clock_id)
00155 {
00156 if(clock_id == CLOCK_REALTIME)
00157 return xnpod_get_time();
00158 else
00159 return xnpod_ns2ticks(xnpod_get_cpu_time());
00160 }
00161
00162
00163 static inline int clock_adjust_timeout(xnticks_t *timeoutp, clockid_t clock_id)
00164 {
00165 xnsticks_t delay;
00166
00167 if(*timeoutp == XN_INFINITE)
00168 return 0;
00169
00170 delay = *timeoutp - clock_get_ticks(clock_id);
00171 if(delay <= 0)
00172 return ETIMEDOUT;
00173
00174 *timeoutp = delay;
00175 return 0;
00176 }
00177
00178 #endif