• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

include/posix/pthread.h

00001 /*
00002  * Copyright (C) 2005 Philippe Gerum <rpm@xenomai.org>.
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 #ifndef _XENO_POSIX_PTHREAD_H
00020 #define _XENO_POSIX_PTHREAD_H
00021 
00022 #if defined(__KERNEL__) || defined(__XENO_SIM__)
00023 
00024 #include <nucleus/xenomai.h>
00025 
00026 #ifdef __KERNEL__
00027 #include <linux/types.h>
00028 #include <sched.h>
00029 #endif /* __KERNEL__ */
00030 
00031 #ifdef __XENO_SIM__
00032 #include <posix_overrides.h>
00033 #define PTHREAD_STACK_MIN   8192
00034 #else /* __XENO_SIM__ */
00035 #define PTHREAD_STACK_MIN   1024
00036 #endif /* __XENO_SIM__ */
00037 
00038 #define PTHREAD_CREATE_JOINABLE 0
00039 #define PTHREAD_CREATE_DETACHED 1
00040 
00041 #define PTHREAD_INHERIT_SCHED  0
00042 #define PTHREAD_EXPLICIT_SCHED 1
00043 
00044 #define PTHREAD_SCOPE_SYSTEM  0
00045 #define PTHREAD_SCOPE_PROCESS 1
00046 
00047 #define PTHREAD_MUTEX_NORMAL     0
00048 #define PTHREAD_MUTEX_RECURSIVE  1
00049 #define PTHREAD_MUTEX_ERRORCHECK 2
00050 #define PTHREAD_MUTEX_DEFAULT    0
00051 
00052 #define PTHREAD_PRIO_NONE    0
00053 #define PTHREAD_PRIO_INHERIT 1
00054 #define PTHREAD_PRIO_PROTECT 2
00055 
00056 #define PTHREAD_PROCESS_PRIVATE 0
00057 #define PTHREAD_PROCESS_SHARED  1
00058 
00059 #define PTHREAD_CANCEL_ENABLE  0
00060 #define PTHREAD_CANCEL_DISABLE 1
00061 
00062 #define PTHREAD_CANCEL_DEFERRED     2
00063 #define PTHREAD_CANCEL_ASYNCHRONOUS 3
00064 
00065 #define PTHREAD_CANCELED  ((void *)-2)
00066 
00067 #define PTHREAD_DESTRUCTOR_ITERATIONS 4
00068 #define PTHREAD_KEYS_MAX 128
00069 
00070 #define PTHREAD_ONCE_INIT { 0x86860808, 0 }
00071 
00072 struct timespec;
00073 
00074 struct pse51_thread;
00075 
00076 typedef struct pse51_thread *pthread_t;
00077 
00078 typedef struct pse51_threadattr {
00079 
00080         unsigned magic;
00081         int detachstate;
00082         size_t stacksize;
00083         int inheritsched;
00084         int policy;
00085 
00086         /* Non portable */
00087         struct sched_param_ex schedparam_ex;
00088         char *name;
00089         int fp;
00090         xnarch_cpumask_t affinity;
00091 
00092 } pthread_attr_t;
00093 
00094 /* pthread_mutexattr_t and pthread_condattr_t fit on 32 bits, for compatibility
00095    with libc. */
00096 struct pse51_key;
00097 typedef struct pse51_key *pthread_key_t;
00098 
00099 typedef struct pse51_once {
00100         unsigned magic;
00101         int routine_called;
00102 } pthread_once_t;
00103 
00104 #ifdef __KERNEL__
00105 /* The following definitions are copied from linuxthread pthreadtypes.h. */
00106 struct _pthread_fastlock
00107 {
00108   long int __status;
00109   int __spinlock;
00110 };
00111 
00112 typedef struct
00113 {
00114   struct _pthread_fastlock __c_lock;
00115   long __c_waiting;
00116   char __padding[48 - sizeof (struct _pthread_fastlock)
00117                  - sizeof (long) - sizeof (long long)];
00118   long long __align;
00119 } pthread_cond_t;
00120 
00121 typedef struct
00122 {
00123   int __m_reserved;
00124   int __m_count;
00125   long __m_owner;
00126   int __m_kind;
00127   struct _pthread_fastlock __m_lock;
00128 } pthread_mutex_t;
00129 
00130 #endif /* __KERNEL__ */
00131 
00132 #else /* !(__KERNEL__ || __XENO_SIM__) */
00133 
00134 #include <sched.h>
00135 #include_next <pthread.h>
00136 #include <nucleus/thread.h>
00137 #include <nucleus/intr.h>
00138 
00139 struct timespec;
00140 
00141 #endif /* __KERNEL__ || __XENO_SIM__ */
00142 
00143 #ifndef PTHREAD_PRIO_NONE
00144 #define PTHREAD_PRIO_NONE    0
00145 #endif /* !PTHREAD_PRIO_NONE */
00146 #ifndef PTHREAD_PRIO_INHERIT
00147 #define PTHREAD_PRIO_INHERIT 1
00148 #endif /* !PTHREAD_PRIO_INHERIT */
00149 #ifndef PTHREAD_PRIO_PROTECT
00150 #define PTHREAD_PRIO_PROTECT 2
00151 #endif /* !PTHREAD_PRIO_PROTECT */
00152 
00153 #define PTHREAD_WARNSW     XNTRAPSW
00154 #define PTHREAD_LOCK_SCHED XNLOCK
00155 #define PTHREAD_RPIOFF     XNRPIOFF
00156 #define PTHREAD_PRIMARY    XNTHREAD_STATE_SPARE1
00157 
00158 #define PTHREAD_INOAUTOENA  XN_ISR_NOENABLE
00159 #define PTHREAD_IPROPAGATE  XN_ISR_PROPAGATE
00160 
00161 #define PTHREAD_IENABLE     0
00162 #define PTHREAD_IDISABLE    1
00163 
00164 struct pse51_mutexattr {
00165         unsigned magic: 24;
00166         unsigned type: 2;
00167         unsigned protocol: 2;
00168         unsigned pshared: 1;
00169 };
00170 
00171 struct pse51_condattr {
00172         unsigned magic: 24;
00173         unsigned clock: 2;
00174         unsigned pshared: 1;
00175 };
00176 
00177 struct pse51_cond;
00178 
00179 union __xeno_cond {
00180         pthread_cond_t native_cond;
00181         struct __shadow_cond {
00182                 unsigned magic;
00183                 struct pse51_cond *cond;
00184         } shadow_cond;
00185 };
00186 
00187 struct pse51_interrupt;
00188 
00189 typedef struct pse51_interrupt *pthread_intr_t;
00190 
00191 #if defined(__KERNEL__) || defined(__XENO_SIM__)
00192 typedef struct pse51_mutexattr pthread_mutexattr_t;
00193 
00194 typedef struct pse51_condattr pthread_condattr_t;
00195 
00196 #ifdef __cplusplus
00197 extern "C" {
00198 #endif
00199 
00200 int pthread_attr_init(pthread_attr_t *attr);
00201 
00202 int pthread_attr_destroy(pthread_attr_t *attr);
00203 
00204 int pthread_attr_getdetachstate(const pthread_attr_t *attr,
00205                                 int *detachstate);
00206 
00207 int pthread_attr_setdetachstate(pthread_attr_t *attr,
00208                                 int detachstate);
00209 
00210 int pthread_attr_getstackaddr(const pthread_attr_t *attr,
00211                               void **stackaddr);
00212 
00213 int pthread_attr_setstackaddr(pthread_attr_t *attr,
00214                               void *stackaddr);
00215 
00216 int pthread_attr_getstacksize(const pthread_attr_t *attr,
00217                               size_t *stacksize);
00218 
00219 int pthread_attr_setstacksize(pthread_attr_t *attr,
00220                               size_t stacksize);
00221 
00222 int pthread_attr_getinheritsched(const pthread_attr_t *attr,
00223                                  int *inheritsched);
00224 
00225 int pthread_attr_setinheritsched(pthread_attr_t *attr,
00226                                  int inheritsched);
00227 
00228 int pthread_attr_getschedpolicy(const pthread_attr_t *attr,
00229                                 int *policy);
00230 
00231 int pthread_attr_setschedpolicy(pthread_attr_t *attr,
00232                                 int policy);
00233 
00234 int pthread_attr_getschedparam(const pthread_attr_t *attr,
00235                                struct sched_param *par);
00236 
00237 int pthread_attr_getschedparam_ex(const pthread_attr_t *attr,
00238                                   struct sched_param_ex *par);
00239 
00240 int pthread_attr_setschedparam(pthread_attr_t *attr,
00241                                const struct sched_param *par);
00242 
00243 int pthread_attr_setschedparam_ex(pthread_attr_t *attr,
00244                                   const struct sched_param_ex *par);
00245 
00246 int pthread_attr_getscope(const pthread_attr_t *attr,
00247                           int *scope);
00248 
00249 int pthread_attr_setscope(pthread_attr_t *attr,
00250                           int scope);
00251 
00252 int pthread_attr_getname_np(const pthread_attr_t *attr,
00253                             const char **name);
00254 
00255 int pthread_attr_setname_np(pthread_attr_t *attr,
00256                             const char *name);
00257 
00258 int pthread_attr_getfp_np(const pthread_attr_t *attr,
00259                           int *use_fp);
00260 
00261 int pthread_attr_setfp_np(pthread_attr_t *attr,
00262                           int use_fp);
00263 
00264 int pthread_attr_getaffinity_np (const pthread_attr_t *attr,
00265                                  xnarch_cpumask_t *mask);
00266 
00267 int pthread_attr_setaffinity_np (pthread_attr_t *attr,
00268                                  xnarch_cpumask_t mask);
00269 
00270 int pthread_create(pthread_t *tid,
00271                    const pthread_attr_t *attr,
00272                    void *(*start) (void *),
00273                    void *arg ) __deprecated_in_kernel__;
00274 
00275 int pthread_detach(pthread_t thread);
00276 
00277 int pthread_equal(pthread_t t1,
00278                   pthread_t t2);
00279 
00280 void pthread_exit(void *value_ptr);
00281 
00282 int pthread_join(pthread_t thread,
00283                  void **value_ptr);
00284 
00285 pthread_t pthread_self(void);
00286 
00287 int pthread_getschedparam(pthread_t tid,
00288                           int *pol,
00289                           struct sched_param *par);
00290 
00291 int pthread_getschedparam_ex(pthread_t tid,
00292                              int *pol,
00293                              struct sched_param_ex *par);
00294 
00295 int pthread_setschedparam(pthread_t tid,
00296                           int pol,
00297                           const struct sched_param *par);
00298 
00299 int pthread_setschedparam_ex(pthread_t tid,
00300                              int pol,
00301                              const struct sched_param_ex *par);
00302 
00303 int pthread_mutexattr_init(pthread_mutexattr_t *attr);
00304 
00305 int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
00306 
00307 int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr,
00308                               int *type);
00309 
00310 int pthread_mutexattr_settype(pthread_mutexattr_t *attr,
00311                               int type);
00312 
00313 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr,
00314                                   int *proto);
00315 
00316 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
00317                                   int proto);
00318 
00319 int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared);
00320 
00321 int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared);
00322 
00323 int pthread_mutex_init(pthread_mutex_t *mutex,
00324                        const pthread_mutexattr_t *attr);
00325 
00326 int pthread_mutex_destroy(pthread_mutex_t *mutex);
00327 
00328 int pthread_mutex_trylock(pthread_mutex_t *mutex);
00329 
00330 int pthread_mutex_lock(pthread_mutex_t *mutex);
00331 
00332 int pthread_mutex_timedlock(pthread_mutex_t *mutex,
00333                             const struct timespec *to);
00334 
00335 int pthread_mutex_unlock(pthread_mutex_t *mutex);
00336 
00337 int pthread_condattr_init(pthread_condattr_t *attr);
00338 
00339 int pthread_condattr_destroy(pthread_condattr_t *attr);
00340 
00341 int pthread_condattr_getclock(const pthread_condattr_t *attr,
00342                               clockid_t *clk_id);
00343 
00344 int pthread_condattr_setclock(pthread_condattr_t *attr,
00345                               clockid_t clk_id);
00346 
00347 int pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared);
00348 
00349 int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared);
00350 
00351 int pthread_cond_init(pthread_cond_t *cond,
00352                       const pthread_condattr_t *attr);
00353 
00354 int pthread_cond_destroy(pthread_cond_t *cond);
00355 
00356 int pthread_cond_wait(pthread_cond_t *cond,
00357                       pthread_mutex_t *mutex);
00358 
00359 int pthread_cond_timedwait(pthread_cond_t *cond,
00360                            pthread_mutex_t *mutex,
00361                            const struct timespec *abstime);
00362 
00363 int pthread_cond_signal(pthread_cond_t *cond);
00364 
00365 int pthread_cond_broadcast(pthread_cond_t *cond);
00366 
00367 int pthread_cancel(pthread_t thread);
00368 
00369 void pthread_cleanup_push(void (*routine)(void *),
00370                           void *arg);
00371 
00372 void pthread_cleanup_pop(int execute);
00373 
00374 int pthread_setcancelstate(int state,
00375                            int *oldstate);
00376 
00377 int pthread_setcanceltype(int type,
00378                           int *oldtype);
00379 
00380 void pthread_testcancel(void);
00381 
00382 int pthread_key_create(pthread_key_t *key,
00383                        void (*destructor)(void *));
00384 
00385 int pthread_key_delete(pthread_key_t key);
00386 
00387 void *pthread_getspecific(pthread_key_t key);
00388 
00389 int pthread_setspecific(pthread_key_t key,
00390                         const void *value);
00391 
00392 int pthread_once(pthread_once_t *once_control,
00393                  void (*init_routine)(void));
00394 
00395 int pthread_make_periodic_np(pthread_t thread,
00396                              struct timespec *starttp,
00397                              struct timespec *periodtp);
00398 
00399 int pthread_wait_np(unsigned long *overruns_r);
00400 
00401 int pthread_set_mode_np(int clrmask,
00402                         int setmask);
00403 
00404 int pthread_set_name_np(pthread_t thread,
00405                         const char *name);
00406 
00407 int pthread_intr_attach_np(pthread_intr_t *intr,
00408                            unsigned irq,
00409                            xnisr_t isr,
00410                            xniack_t iack);
00411 
00412 int pthread_intr_detach_np(pthread_intr_t intr);
00413 
00414 int pthread_intr_control_np(pthread_intr_t intr,
00415                             int cmd);
00416 
00417 #ifdef __cplusplus
00418 }
00419 #endif
00420 
00421 #else /* !(__KERNEL__ || __XENO_SIM__) */
00422 
00423 struct sched_param_ex;
00424 
00425 #ifdef __cplusplus
00426 extern "C" {
00427 #endif
00428 
00429 #ifndef HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL
00430 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr,
00431                                   int *proto);
00432 
00433 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
00434                                   int proto);
00435 #endif
00436 
00437 #ifndef HAVE_PTHREAD_CONDATTR_SETCLOCK
00438 int pthread_condattr_getclock(const pthread_condattr_t *attr,
00439                               clockid_t *clk_id);
00440 
00441 int pthread_condattr_setclock(pthread_condattr_t *attr,
00442                               clockid_t clk_id);
00443 #endif
00444 
00445 int pthread_make_periodic_np(pthread_t thread,
00446                              struct timespec *starttp,
00447                              struct timespec *periodtp);
00448 
00449 int pthread_wait_np(unsigned long *overruns_r);
00450 
00451 int pthread_set_mode_np(int clrmask,
00452                         int setmask);
00453 
00454 int pthread_set_name_np(pthread_t thread,
00455                         const char *name);
00456 
00457 int pthread_intr_attach_np(pthread_intr_t *intr,
00458                            unsigned irq,
00459                            int mode);
00460 
00461 int pthread_intr_detach_np(pthread_intr_t intr);
00462 
00463 int pthread_intr_wait_np(pthread_intr_t intr,
00464                          const struct timespec *to);
00465 
00466 int pthread_intr_control_np(pthread_intr_t intr,
00467                             int cmd);
00468 
00469 int pthread_getschedparam_ex(pthread_t tid,
00470                              int *pol,
00471                              struct sched_param_ex *par);
00472 
00473 int pthread_setschedparam_ex(pthread_t tid,
00474                              int pol,
00475                              const struct sched_param_ex *par);
00476 
00477 int __real_pthread_create(pthread_t *tid,
00478                           const pthread_attr_t *attr,
00479                           void *(*start) (void *),
00480                           void *arg);
00481 
00482 int __real_pthread_detach(pthread_t thread);
00483 
00484 int __real_pthread_getschedparam(pthread_t thread,
00485                                  int *policy,
00486                                  struct sched_param *param);
00487 
00488 int __real_pthread_setschedparam(pthread_t thread,
00489                                  int policy,
00490                                  const struct sched_param *param);
00491 int __real_pthread_yield(void);
00492 
00493 int __real_pthread_mutexattr_init(pthread_mutexattr_t *attr);
00494 
00495 int __real_pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
00496 
00497 int __real_pthread_mutexattr_gettype(const pthread_mutexattr_t *attr,
00498                                      int *type);
00499 
00500 int __real_pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
00501 
00502 #ifdef HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL
00503 int __real_pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr,
00504                                          int *proto);
00505 
00506 int __real_pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
00507                                          int proto);
00508 #endif
00509 
00510 int __real_pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr,
00511                                         int *pshared);
00512 
00513 int __real_pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
00514                                         int pshared);
00515 
00516 int __real_pthread_mutex_init(pthread_mutex_t *mutex,
00517                               const pthread_mutexattr_t *attr);
00518 
00519 int __real_pthread_mutex_destroy(pthread_mutex_t *mutex);
00520 
00521 int __real_pthread_mutex_lock(pthread_mutex_t *mutex);
00522 
00523 int __real_pthread_mutex_timedlock(pthread_mutex_t *mutex,
00524                                    const struct timespec *to);
00525 
00526 int __real_pthread_mutex_trylock(pthread_mutex_t *mutex);
00527 
00528 int __real_pthread_mutex_unlock(pthread_mutex_t *mutex);
00529 
00530 int __real_pthread_condattr_init(pthread_condattr_t *attr);
00531 
00532 int __real_pthread_condattr_destroy(pthread_condattr_t *attr);
00533 
00534 int __real_pthread_condattr_getclock(const pthread_condattr_t *attr,
00535                                      clockid_t *clk_id);
00536 
00537 int __real_pthread_condattr_setclock(pthread_condattr_t *attr,
00538                               clockid_t clk_id);
00539 
00540 int __real_pthread_condattr_getpshared(const pthread_condattr_t *attr,
00541                                        int *pshared);
00542 
00543 int __real_pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared);
00544 
00545 int __real_pthread_cond_init (pthread_cond_t *cond,
00546                               const pthread_condattr_t *attr);
00547 
00548 int __real_pthread_cond_destroy(pthread_cond_t *cond);
00549 
00550 int __real_pthread_cond_wait(pthread_cond_t *cond,
00551                              pthread_mutex_t *mutex);
00552 
00553 int __real_pthread_cond_timedwait(pthread_cond_t *cond,
00554                                   pthread_mutex_t *mutex,
00555                                   const struct timespec *abstime);
00556 
00557 int __real_pthread_cond_signal(pthread_cond_t *cond);
00558 
00559 int __real_pthread_cond_broadcast(pthread_cond_t *cond);
00560 
00561 int __real_pthread_kill(pthread_t tid, int sig);
00562 
00563 #ifdef __cplusplus
00564 }
00565 #endif
00566 
00567 #endif /* __KERNEL__ || __XENO_SIM__ */
00568 
00569 #endif /* _XENO_POSIX_PTHREAD_H */

Generated on Wed Jan 23 2013 13:24:01 for Xenomai API by  doxygen 1.7.1