]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/plr/lib/libpthread_romain/include/bits/pthreadtypes.h
update
[l4.git] / l4 / pkg / plr / lib / libpthread_romain / include / bits / pthreadtypes.h
1 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr)              */
2 /*                                                                      */
3 /* This program is free software; you can redistribute it and/or        */
4 /* modify it under the terms of the GNU Library General Public License  */
5 /* as published by the Free Software Foundation; either version 2       */
6 /* of the License, or (at your option) any later version.               */
7 /*                                                                      */
8 /* This program is distributed in the hope that it will be useful,      */
9 /* but WITHOUT ANY WARRANTY; without even the implied warranty of       */
10 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        */
11 /* GNU Library General Public License for more details.                 */
12
13 /* 2008 Alexander Warg --- L4 adaption                                  */
14
15 #pragma once
16
17 #include <stddef.h>
18 #include <l4/sys/types.h>
19 #include <l4/sys/scheduler.h>
20
21 #define __need_schedparam
22 #include <bits/sched.h>
23
24 /* Fast locks (not abstract because mutexes and conditions aren't abstract). */
25 struct _pthread_fastlock
26 {
27   long int __status;   /* "Free" or "taken" or head of waiting list */
28   int __spinlock;      /* Used by compare_and_swap emulation. Also,
29                           adaptive SMP lock stores spin count here. */
30 };
31
32 #ifndef _PTHREAD_DESCR_DEFINED
33 /* Thread descriptors */
34 typedef struct pthread *_pthread_descr;
35 # define _PTHREAD_DESCR_DEFINED
36 #endif
37
38
39 /* Attributes for threads.  */
40 typedef struct __pthread_attr_s
41 {
42   int __detachstate;
43   int __schedpolicy;
44   struct __sched_param __schedparam;
45   int __inheritsched;
46   int __scope;
47   size_t __guardsize;
48   int __stackaddr_set;
49   void *__stackaddr;
50   size_t __stacksize;
51
52   // L4 specifics
53   l4_sched_cpu_set_t affinity;
54   unsigned create_flags;
55
56 } pthread_attr_t;
57
58
59 /* Conditions (not abstract because of PTHREAD_COND_INITIALIZER */
60
61 #ifdef __GLIBC_HAVE_LONG_LONG
62 __extension__ typedef long long __pthread_cond_align_t;
63 #else
64 typedef long __pthread_cond_align_t;
65 #endif
66
67 typedef struct
68 {
69   struct _pthread_fastlock __c_lock; /* Protect against concurrent access */
70   _pthread_descr __c_waiting;        /* Threads waiting on this condition */
71   char __padding[48 - sizeof (struct _pthread_fastlock)
72                  - sizeof (_pthread_descr) - sizeof (__pthread_cond_align_t)];
73   __pthread_cond_align_t __align;
74 } pthread_cond_t;
75
76
77 /* Attribute for conditionally variables.  */
78 typedef struct
79 {
80   int __dummy;
81 } pthread_condattr_t;
82
83 /* Keys for thread-specific data */
84 typedef unsigned int pthread_key_t;
85
86
87 /* Mutexes (not abstract because of PTHREAD_MUTEX_INITIALIZER).  */
88 /* (The layout is unnatural to maintain binary compatibility
89     with earlier releases of LinuxThreads.) */
90 typedef struct
91 {
92   int __m_reserved;               /* Reserved for future use */
93   int __m_count;                  /* Depth of recursive locking */
94   _pthread_descr __m_owner;       /* Owner thread (if recursive or errcheck) */
95   int __m_kind;                   /* Mutex kind: fast, recursive or errcheck */
96   struct _pthread_fastlock __m_lock; /* Underlying fast lock */
97 } pthread_mutex_t;
98
99
100 /* Attribute for mutex.  */
101 typedef struct
102 {
103   int __mutexkind;
104 } pthread_mutexattr_t;
105
106
107 /* Once-only execution */
108 typedef int pthread_once_t;
109
110
111 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
112 /* Read-write locks.  */
113 typedef struct _pthread_rwlock_t
114 {
115   struct _pthread_fastlock __rw_lock; /* Lock to guarantee mutual exclusion */
116   int __rw_readers;                   /* Number of readers */
117   _pthread_descr __rw_writer;         /* Identity of writer, or NULL if none */
118   _pthread_descr __rw_read_waiting;   /* Threads waiting for reading */
119   _pthread_descr __rw_write_waiting;  /* Threads waiting for writing */
120   int __rw_kind;                      /* Reader/Writer preference selection */
121   int __rw_pshared;                   /* Shared between processes or not */
122 } pthread_rwlock_t;
123
124
125 /* Attribute for read-write locks.  */
126 typedef struct
127 {
128   int __lockkind;
129   int __pshared;
130 } pthread_rwlockattr_t;
131 #endif
132
133 #ifdef __USE_XOPEN2K
134 /* POSIX spinlock data type.  */
135 typedef __volatile__ int pthread_spinlock_t;
136
137 /* POSIX barrier. */
138 typedef struct {
139   struct _pthread_fastlock __ba_lock; /* Lock to guarantee mutual exclusion */
140   int __ba_required;                  /* Threads needed for completion */
141   int __ba_present;                   /* Threads waiting */
142   _pthread_descr __ba_waiting;        /* Queue of waiting threads */
143 } pthread_barrier_t;
144
145 /* barrier attribute */
146 typedef struct {
147   int __pshared;
148 } pthread_barrierattr_t;
149
150 #endif
151
152
153 /* Thread identifiers */
154 typedef void *pthread_t;