xref: /dragonfly/contrib/gcc-4.7/libgomp/libgomp.h (revision 629ff9f7)
1*629ff9f7SJohn Marino /* Copyright (C) 2005, 2007, 2008, 2009, 2010, 2011
2*629ff9f7SJohn Marino    Free Software Foundation, Inc.
3*629ff9f7SJohn Marino    Contributed by Richard Henderson <rth@redhat.com>.
4*629ff9f7SJohn Marino 
5*629ff9f7SJohn Marino    This file is part of the GNU OpenMP Library (libgomp).
6*629ff9f7SJohn Marino 
7*629ff9f7SJohn Marino    Libgomp is free software; you can redistribute it and/or modify it
8*629ff9f7SJohn Marino    under the terms of the GNU General Public License as published by
9*629ff9f7SJohn Marino    the Free Software Foundation; either version 3, or (at your option)
10*629ff9f7SJohn Marino    any later version.
11*629ff9f7SJohn Marino 
12*629ff9f7SJohn Marino    Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
13*629ff9f7SJohn Marino    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14*629ff9f7SJohn Marino    FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15*629ff9f7SJohn Marino    more details.
16*629ff9f7SJohn Marino 
17*629ff9f7SJohn Marino    Under Section 7 of GPL version 3, you are granted additional
18*629ff9f7SJohn Marino    permissions described in the GCC Runtime Library Exception, version
19*629ff9f7SJohn Marino    3.1, as published by the Free Software Foundation.
20*629ff9f7SJohn Marino 
21*629ff9f7SJohn Marino    You should have received a copy of the GNU General Public License and
22*629ff9f7SJohn Marino    a copy of the GCC Runtime Library Exception along with this program;
23*629ff9f7SJohn Marino    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24*629ff9f7SJohn Marino    <http://www.gnu.org/licenses/>.  */
25*629ff9f7SJohn Marino 
26*629ff9f7SJohn Marino /* This file contains data types and function declarations that are not
27*629ff9f7SJohn Marino    part of the official OpenMP user interface.  There are declarations
28*629ff9f7SJohn Marino    in here that are part of the GNU OpenMP ABI, in that the compiler is
29*629ff9f7SJohn Marino    required to know about them and use them.
30*629ff9f7SJohn Marino 
31*629ff9f7SJohn Marino    The convention is that the all caps prefix "GOMP" is used group items
32*629ff9f7SJohn Marino    that are part of the external ABI, and the lower case prefix "gomp"
33*629ff9f7SJohn Marino    is used group items that are completely private to the library.  */
34*629ff9f7SJohn Marino 
35*629ff9f7SJohn Marino #ifndef LIBGOMP_H
36*629ff9f7SJohn Marino #define LIBGOMP_H 1
37*629ff9f7SJohn Marino 
38*629ff9f7SJohn Marino #include "config.h"
39*629ff9f7SJohn Marino #include "gstdint.h"
40*629ff9f7SJohn Marino 
41*629ff9f7SJohn Marino #include <pthread.h>
42*629ff9f7SJohn Marino #include <stdbool.h>
43*629ff9f7SJohn Marino 
44*629ff9f7SJohn Marino #ifdef HAVE_ATTRIBUTE_VISIBILITY
45*629ff9f7SJohn Marino # pragma GCC visibility push(hidden)
46*629ff9f7SJohn Marino #endif
47*629ff9f7SJohn Marino 
48*629ff9f7SJohn Marino /* If we were a C++ library, we'd get this from <std/atomic>.  */
49*629ff9f7SJohn Marino enum memmodel
50*629ff9f7SJohn Marino {
51*629ff9f7SJohn Marino   MEMMODEL_RELAXED = 0,
52*629ff9f7SJohn Marino   MEMMODEL_CONSUME = 1,
53*629ff9f7SJohn Marino   MEMMODEL_ACQUIRE = 2,
54*629ff9f7SJohn Marino   MEMMODEL_RELEASE = 3,
55*629ff9f7SJohn Marino   MEMMODEL_ACQ_REL = 4,
56*629ff9f7SJohn Marino   MEMMODEL_SEQ_CST = 5
57*629ff9f7SJohn Marino };
58*629ff9f7SJohn Marino 
59*629ff9f7SJohn Marino #include "sem.h"
60*629ff9f7SJohn Marino #include "mutex.h"
61*629ff9f7SJohn Marino #include "bar.h"
62*629ff9f7SJohn Marino #include "ptrlock.h"
63*629ff9f7SJohn Marino 
64*629ff9f7SJohn Marino 
65*629ff9f7SJohn Marino /* This structure contains the data to control one work-sharing construct,
66*629ff9f7SJohn Marino    either a LOOP (FOR/DO) or a SECTIONS.  */
67*629ff9f7SJohn Marino 
68*629ff9f7SJohn Marino enum gomp_schedule_type
69*629ff9f7SJohn Marino {
70*629ff9f7SJohn Marino   GFS_RUNTIME,
71*629ff9f7SJohn Marino   GFS_STATIC,
72*629ff9f7SJohn Marino   GFS_DYNAMIC,
73*629ff9f7SJohn Marino   GFS_GUIDED,
74*629ff9f7SJohn Marino   GFS_AUTO
75*629ff9f7SJohn Marino };
76*629ff9f7SJohn Marino 
77*629ff9f7SJohn Marino struct gomp_work_share
78*629ff9f7SJohn Marino {
79*629ff9f7SJohn Marino   /* This member records the SCHEDULE clause to be used for this construct.
80*629ff9f7SJohn Marino      The user specification of "runtime" will already have been resolved.
81*629ff9f7SJohn Marino      If this is a SECTIONS construct, this value will always be DYNAMIC.  */
82*629ff9f7SJohn Marino   enum gomp_schedule_type sched;
83*629ff9f7SJohn Marino 
84*629ff9f7SJohn Marino   int mode;
85*629ff9f7SJohn Marino 
86*629ff9f7SJohn Marino   union {
87*629ff9f7SJohn Marino     struct {
88*629ff9f7SJohn Marino       /* This is the chunk_size argument to the SCHEDULE clause.  */
89*629ff9f7SJohn Marino       long chunk_size;
90*629ff9f7SJohn Marino 
91*629ff9f7SJohn Marino       /* This is the iteration end point.  If this is a SECTIONS construct,
92*629ff9f7SJohn Marino 	 this is the number of contained sections.  */
93*629ff9f7SJohn Marino       long end;
94*629ff9f7SJohn Marino 
95*629ff9f7SJohn Marino       /* This is the iteration step.  If this is a SECTIONS construct, this
96*629ff9f7SJohn Marino 	 is always 1.  */
97*629ff9f7SJohn Marino       long incr;
98*629ff9f7SJohn Marino     };
99*629ff9f7SJohn Marino 
100*629ff9f7SJohn Marino     struct {
101*629ff9f7SJohn Marino       /* The same as above, but for the unsigned long long loop variants.  */
102*629ff9f7SJohn Marino       unsigned long long chunk_size_ull;
103*629ff9f7SJohn Marino       unsigned long long end_ull;
104*629ff9f7SJohn Marino       unsigned long long incr_ull;
105*629ff9f7SJohn Marino     };
106*629ff9f7SJohn Marino   };
107*629ff9f7SJohn Marino 
108*629ff9f7SJohn Marino   /* This is a circular queue that details which threads will be allowed
109*629ff9f7SJohn Marino      into the ordered region and in which order.  When a thread allocates
110*629ff9f7SJohn Marino      iterations on which it is going to work, it also registers itself at
111*629ff9f7SJohn Marino      the end of the array.  When a thread reaches the ordered region, it
112*629ff9f7SJohn Marino      checks to see if it is the one at the head of the queue.  If not, it
113*629ff9f7SJohn Marino      blocks on its RELEASE semaphore.  */
114*629ff9f7SJohn Marino   unsigned *ordered_team_ids;
115*629ff9f7SJohn Marino 
116*629ff9f7SJohn Marino   /* This is the number of threads that have registered themselves in
117*629ff9f7SJohn Marino      the circular queue ordered_team_ids.  */
118*629ff9f7SJohn Marino   unsigned ordered_num_used;
119*629ff9f7SJohn Marino 
120*629ff9f7SJohn Marino   /* This is the team_id of the currently acknowledged owner of the ordered
121*629ff9f7SJohn Marino      section, or -1u if the ordered section has not been acknowledged by
122*629ff9f7SJohn Marino      any thread.  This is distinguished from the thread that is *allowed*
123*629ff9f7SJohn Marino      to take the section next.  */
124*629ff9f7SJohn Marino   unsigned ordered_owner;
125*629ff9f7SJohn Marino 
126*629ff9f7SJohn Marino   /* This is the index into the circular queue ordered_team_ids of the
127*629ff9f7SJohn Marino      current thread that's allowed into the ordered reason.  */
128*629ff9f7SJohn Marino   unsigned ordered_cur;
129*629ff9f7SJohn Marino 
130*629ff9f7SJohn Marino   /* This is a chain of allocated gomp_work_share blocks, valid only
131*629ff9f7SJohn Marino      in the first gomp_work_share struct in the block.  */
132*629ff9f7SJohn Marino   struct gomp_work_share *next_alloc;
133*629ff9f7SJohn Marino 
134*629ff9f7SJohn Marino   /* The above fields are written once during workshare initialization,
135*629ff9f7SJohn Marino      or related to ordered worksharing.  Make sure the following fields
136*629ff9f7SJohn Marino      are in a different cache line.  */
137*629ff9f7SJohn Marino 
138*629ff9f7SJohn Marino   /* This lock protects the update of the following members.  */
139*629ff9f7SJohn Marino   gomp_mutex_t lock __attribute__((aligned (64)));
140*629ff9f7SJohn Marino 
141*629ff9f7SJohn Marino   /* This is the count of the number of threads that have exited the work
142*629ff9f7SJohn Marino      share construct.  If the construct was marked nowait, they have moved on
143*629ff9f7SJohn Marino      to other work; otherwise they're blocked on a barrier.  The last member
144*629ff9f7SJohn Marino      of the team to exit the work share construct must deallocate it.  */
145*629ff9f7SJohn Marino   unsigned threads_completed;
146*629ff9f7SJohn Marino 
147*629ff9f7SJohn Marino   union {
148*629ff9f7SJohn Marino     /* This is the next iteration value to be allocated.  In the case of
149*629ff9f7SJohn Marino        GFS_STATIC loops, this the iteration start point and never changes.  */
150*629ff9f7SJohn Marino     long next;
151*629ff9f7SJohn Marino 
152*629ff9f7SJohn Marino     /* The same, but with unsigned long long type.  */
153*629ff9f7SJohn Marino     unsigned long long next_ull;
154*629ff9f7SJohn Marino 
155*629ff9f7SJohn Marino     /* This is the returned data structure for SINGLE COPYPRIVATE.  */
156*629ff9f7SJohn Marino     void *copyprivate;
157*629ff9f7SJohn Marino   };
158*629ff9f7SJohn Marino 
159*629ff9f7SJohn Marino   union {
160*629ff9f7SJohn Marino     /* Link to gomp_work_share struct for next work sharing construct
161*629ff9f7SJohn Marino        encountered after this one.  */
162*629ff9f7SJohn Marino     gomp_ptrlock_t next_ws;
163*629ff9f7SJohn Marino 
164*629ff9f7SJohn Marino     /* gomp_work_share structs are chained in the free work share cache
165*629ff9f7SJohn Marino        through this.  */
166*629ff9f7SJohn Marino     struct gomp_work_share *next_free;
167*629ff9f7SJohn Marino   };
168*629ff9f7SJohn Marino 
169*629ff9f7SJohn Marino   /* If only few threads are in the team, ordered_team_ids can point
170*629ff9f7SJohn Marino      to this array which fills the padding at the end of this struct.  */
171*629ff9f7SJohn Marino   unsigned inline_ordered_team_ids[0];
172*629ff9f7SJohn Marino };
173*629ff9f7SJohn Marino 
174*629ff9f7SJohn Marino /* This structure contains all of the thread-local data associated with
175*629ff9f7SJohn Marino    a thread team.  This is the data that must be saved when a thread
176*629ff9f7SJohn Marino    encounters a nested PARALLEL construct.  */
177*629ff9f7SJohn Marino 
178*629ff9f7SJohn Marino struct gomp_team_state
179*629ff9f7SJohn Marino {
180*629ff9f7SJohn Marino   /* This is the team of which the thread is currently a member.  */
181*629ff9f7SJohn Marino   struct gomp_team *team;
182*629ff9f7SJohn Marino 
183*629ff9f7SJohn Marino   /* This is the work share construct which this thread is currently
184*629ff9f7SJohn Marino      processing.  Recall that with NOWAIT, not all threads may be
185*629ff9f7SJohn Marino      processing the same construct.  */
186*629ff9f7SJohn Marino   struct gomp_work_share *work_share;
187*629ff9f7SJohn Marino 
188*629ff9f7SJohn Marino   /* This is the previous work share construct or NULL if there wasn't any.
189*629ff9f7SJohn Marino      When all threads are done with the current work sharing construct,
190*629ff9f7SJohn Marino      the previous one can be freed.  The current one can't, as its
191*629ff9f7SJohn Marino      next_ws field is used.  */
192*629ff9f7SJohn Marino   struct gomp_work_share *last_work_share;
193*629ff9f7SJohn Marino 
194*629ff9f7SJohn Marino   /* This is the ID of this thread within the team.  This value is
195*629ff9f7SJohn Marino      guaranteed to be between 0 and N-1, where N is the number of
196*629ff9f7SJohn Marino      threads in the team.  */
197*629ff9f7SJohn Marino   unsigned team_id;
198*629ff9f7SJohn Marino 
199*629ff9f7SJohn Marino   /* Nesting level.  */
200*629ff9f7SJohn Marino   unsigned level;
201*629ff9f7SJohn Marino 
202*629ff9f7SJohn Marino   /* Active nesting level.  Only active parallel regions are counted.  */
203*629ff9f7SJohn Marino   unsigned active_level;
204*629ff9f7SJohn Marino 
205*629ff9f7SJohn Marino #ifdef HAVE_SYNC_BUILTINS
206*629ff9f7SJohn Marino   /* Number of single stmts encountered.  */
207*629ff9f7SJohn Marino   unsigned long single_count;
208*629ff9f7SJohn Marino #endif
209*629ff9f7SJohn Marino 
210*629ff9f7SJohn Marino   /* For GFS_RUNTIME loops that resolved to GFS_STATIC, this is the
211*629ff9f7SJohn Marino      trip number through the loop.  So first time a particular loop
212*629ff9f7SJohn Marino      is encountered this number is 0, the second time through the loop
213*629ff9f7SJohn Marino      is 1, etc.  This is unused when the compiler knows in advance that
214*629ff9f7SJohn Marino      the loop is statically scheduled.  */
215*629ff9f7SJohn Marino   unsigned long static_trip;
216*629ff9f7SJohn Marino };
217*629ff9f7SJohn Marino 
218*629ff9f7SJohn Marino /* These are the OpenMP 3.0 Internal Control Variables described in
219*629ff9f7SJohn Marino    section 2.3.1.  Those described as having one copy per task are
220*629ff9f7SJohn Marino    stored within the structure; those described as having one copy
221*629ff9f7SJohn Marino    for the whole program are (naturally) global variables.  */
222*629ff9f7SJohn Marino 
223*629ff9f7SJohn Marino struct gomp_task_icv
224*629ff9f7SJohn Marino {
225*629ff9f7SJohn Marino   unsigned long nthreads_var;
226*629ff9f7SJohn Marino   enum gomp_schedule_type run_sched_var;
227*629ff9f7SJohn Marino   int run_sched_modifier;
228*629ff9f7SJohn Marino   bool dyn_var;
229*629ff9f7SJohn Marino   bool nest_var;
230*629ff9f7SJohn Marino };
231*629ff9f7SJohn Marino 
232*629ff9f7SJohn Marino extern struct gomp_task_icv gomp_global_icv;
233*629ff9f7SJohn Marino extern unsigned long gomp_thread_limit_var;
234*629ff9f7SJohn Marino extern unsigned long gomp_remaining_threads_count;
235*629ff9f7SJohn Marino #ifndef HAVE_SYNC_BUILTINS
236*629ff9f7SJohn Marino extern gomp_mutex_t gomp_remaining_threads_lock;
237*629ff9f7SJohn Marino #endif
238*629ff9f7SJohn Marino extern unsigned long gomp_max_active_levels_var;
239*629ff9f7SJohn Marino extern unsigned long long gomp_spin_count_var, gomp_throttled_spin_count_var;
240*629ff9f7SJohn Marino extern unsigned long gomp_available_cpus, gomp_managed_threads;
241*629ff9f7SJohn Marino extern unsigned long *gomp_nthreads_var_list, gomp_nthreads_var_list_len;
242*629ff9f7SJohn Marino 
243*629ff9f7SJohn Marino enum gomp_task_kind
244*629ff9f7SJohn Marino {
245*629ff9f7SJohn Marino   GOMP_TASK_IMPLICIT,
246*629ff9f7SJohn Marino   GOMP_TASK_IFFALSE,
247*629ff9f7SJohn Marino   GOMP_TASK_WAITING,
248*629ff9f7SJohn Marino   GOMP_TASK_TIED
249*629ff9f7SJohn Marino };
250*629ff9f7SJohn Marino 
251*629ff9f7SJohn Marino /* This structure describes a "task" to be run by a thread.  */
252*629ff9f7SJohn Marino 
253*629ff9f7SJohn Marino struct gomp_task
254*629ff9f7SJohn Marino {
255*629ff9f7SJohn Marino   struct gomp_task *parent;
256*629ff9f7SJohn Marino   struct gomp_task *children;
257*629ff9f7SJohn Marino   struct gomp_task *next_child;
258*629ff9f7SJohn Marino   struct gomp_task *prev_child;
259*629ff9f7SJohn Marino   struct gomp_task *next_queue;
260*629ff9f7SJohn Marino   struct gomp_task *prev_queue;
261*629ff9f7SJohn Marino   struct gomp_task_icv icv;
262*629ff9f7SJohn Marino   void (*fn) (void *);
263*629ff9f7SJohn Marino   void *fn_data;
264*629ff9f7SJohn Marino   enum gomp_task_kind kind;
265*629ff9f7SJohn Marino   bool in_taskwait;
266*629ff9f7SJohn Marino   bool in_tied_task;
267*629ff9f7SJohn Marino   bool final_task;
268*629ff9f7SJohn Marino   gomp_sem_t taskwait_sem;
269*629ff9f7SJohn Marino };
270*629ff9f7SJohn Marino 
271*629ff9f7SJohn Marino /* This structure describes a "team" of threads.  These are the threads
272*629ff9f7SJohn Marino    that are spawned by a PARALLEL constructs, as well as the work sharing
273*629ff9f7SJohn Marino    constructs that the team encounters.  */
274*629ff9f7SJohn Marino 
275*629ff9f7SJohn Marino struct gomp_team
276*629ff9f7SJohn Marino {
277*629ff9f7SJohn Marino   /* This is the number of threads in the current team.  */
278*629ff9f7SJohn Marino   unsigned nthreads;
279*629ff9f7SJohn Marino 
280*629ff9f7SJohn Marino   /* This is number of gomp_work_share structs that have been allocated
281*629ff9f7SJohn Marino      as a block last time.  */
282*629ff9f7SJohn Marino   unsigned work_share_chunk;
283*629ff9f7SJohn Marino 
284*629ff9f7SJohn Marino   /* This is the saved team state that applied to a master thread before
285*629ff9f7SJohn Marino      the current thread was created.  */
286*629ff9f7SJohn Marino   struct gomp_team_state prev_ts;
287*629ff9f7SJohn Marino 
288*629ff9f7SJohn Marino   /* This semaphore should be used by the master thread instead of its
289*629ff9f7SJohn Marino      "native" semaphore in the thread structure.  Required for nested
290*629ff9f7SJohn Marino      parallels, as the master is a member of two teams.  */
291*629ff9f7SJohn Marino   gomp_sem_t master_release;
292*629ff9f7SJohn Marino 
293*629ff9f7SJohn Marino   /* This points to an array with pointers to the release semaphore
294*629ff9f7SJohn Marino      of the threads in the team.  */
295*629ff9f7SJohn Marino   gomp_sem_t **ordered_release;
296*629ff9f7SJohn Marino 
297*629ff9f7SJohn Marino   /* List of gomp_work_share structs chained through next_free fields.
298*629ff9f7SJohn Marino      This is populated and taken off only by the first thread in the
299*629ff9f7SJohn Marino      team encountering a new work sharing construct, in a critical
300*629ff9f7SJohn Marino      section.  */
301*629ff9f7SJohn Marino   struct gomp_work_share *work_share_list_alloc;
302*629ff9f7SJohn Marino 
303*629ff9f7SJohn Marino   /* List of gomp_work_share structs freed by free_work_share.  New
304*629ff9f7SJohn Marino      entries are atomically added to the start of the list, and
305*629ff9f7SJohn Marino      alloc_work_share can safely only move all but the first entry
306*629ff9f7SJohn Marino      to work_share_list alloc, as free_work_share can happen concurrently
307*629ff9f7SJohn Marino      with alloc_work_share.  */
308*629ff9f7SJohn Marino   struct gomp_work_share *work_share_list_free;
309*629ff9f7SJohn Marino 
310*629ff9f7SJohn Marino #ifdef HAVE_SYNC_BUILTINS
311*629ff9f7SJohn Marino   /* Number of simple single regions encountered by threads in this
312*629ff9f7SJohn Marino      team.  */
313*629ff9f7SJohn Marino   unsigned long single_count;
314*629ff9f7SJohn Marino #else
315*629ff9f7SJohn Marino   /* Mutex protecting addition of workshares to work_share_list_free.  */
316*629ff9f7SJohn Marino   gomp_mutex_t work_share_list_free_lock;
317*629ff9f7SJohn Marino #endif
318*629ff9f7SJohn Marino 
319*629ff9f7SJohn Marino   /* This barrier is used for most synchronization of the team.  */
320*629ff9f7SJohn Marino   gomp_barrier_t barrier;
321*629ff9f7SJohn Marino 
322*629ff9f7SJohn Marino   /* Initial work shares, to avoid allocating any gomp_work_share
323*629ff9f7SJohn Marino      structs in the common case.  */
324*629ff9f7SJohn Marino   struct gomp_work_share work_shares[8];
325*629ff9f7SJohn Marino 
326*629ff9f7SJohn Marino   gomp_mutex_t task_lock;
327*629ff9f7SJohn Marino   struct gomp_task *task_queue;
328*629ff9f7SJohn Marino   int task_count;
329*629ff9f7SJohn Marino   int task_running_count;
330*629ff9f7SJohn Marino 
331*629ff9f7SJohn Marino   /* This array contains structures for implicit tasks.  */
332*629ff9f7SJohn Marino   struct gomp_task implicit_task[];
333*629ff9f7SJohn Marino };
334*629ff9f7SJohn Marino 
335*629ff9f7SJohn Marino /* This structure contains all data that is private to libgomp and is
336*629ff9f7SJohn Marino    allocated per thread.  */
337*629ff9f7SJohn Marino 
338*629ff9f7SJohn Marino struct gomp_thread
339*629ff9f7SJohn Marino {
340*629ff9f7SJohn Marino   /* This is the function that the thread should run upon launch.  */
341*629ff9f7SJohn Marino   void (*fn) (void *data);
342*629ff9f7SJohn Marino   void *data;
343*629ff9f7SJohn Marino 
344*629ff9f7SJohn Marino   /* This is the current team state for this thread.  The ts.team member
345*629ff9f7SJohn Marino      is NULL only if the thread is idle.  */
346*629ff9f7SJohn Marino   struct gomp_team_state ts;
347*629ff9f7SJohn Marino 
348*629ff9f7SJohn Marino   /* This is the task that the thread is currently executing.  */
349*629ff9f7SJohn Marino   struct gomp_task *task;
350*629ff9f7SJohn Marino 
351*629ff9f7SJohn Marino   /* This semaphore is used for ordered loops.  */
352*629ff9f7SJohn Marino   gomp_sem_t release;
353*629ff9f7SJohn Marino 
354*629ff9f7SJohn Marino   /* user pthread thread pool */
355*629ff9f7SJohn Marino   struct gomp_thread_pool *thread_pool;
356*629ff9f7SJohn Marino };
357*629ff9f7SJohn Marino 
358*629ff9f7SJohn Marino 
359*629ff9f7SJohn Marino struct gomp_thread_pool
360*629ff9f7SJohn Marino {
361*629ff9f7SJohn Marino   /* This array manages threads spawned from the top level, which will
362*629ff9f7SJohn Marino      return to the idle loop once the current PARALLEL construct ends.  */
363*629ff9f7SJohn Marino   struct gomp_thread **threads;
364*629ff9f7SJohn Marino   unsigned threads_size;
365*629ff9f7SJohn Marino   unsigned threads_used;
366*629ff9f7SJohn Marino   struct gomp_team *last_team;
367*629ff9f7SJohn Marino 
368*629ff9f7SJohn Marino   /* This barrier holds and releases threads waiting in threads.  */
369*629ff9f7SJohn Marino   gomp_barrier_t threads_dock;
370*629ff9f7SJohn Marino };
371*629ff9f7SJohn Marino 
372*629ff9f7SJohn Marino /* ... and here is that TLS data.  */
373*629ff9f7SJohn Marino 
374*629ff9f7SJohn Marino #ifdef HAVE_TLS
375*629ff9f7SJohn Marino extern __thread struct gomp_thread gomp_tls_data;
gomp_thread(void)376*629ff9f7SJohn Marino static inline struct gomp_thread *gomp_thread (void)
377*629ff9f7SJohn Marino {
378*629ff9f7SJohn Marino   return &gomp_tls_data;
379*629ff9f7SJohn Marino }
380*629ff9f7SJohn Marino #else
381*629ff9f7SJohn Marino extern pthread_key_t gomp_tls_key;
gomp_thread(void)382*629ff9f7SJohn Marino static inline struct gomp_thread *gomp_thread (void)
383*629ff9f7SJohn Marino {
384*629ff9f7SJohn Marino   return pthread_getspecific (gomp_tls_key);
385*629ff9f7SJohn Marino }
386*629ff9f7SJohn Marino #endif
387*629ff9f7SJohn Marino 
388*629ff9f7SJohn Marino extern struct gomp_task_icv *gomp_new_icv (void);
389*629ff9f7SJohn Marino 
390*629ff9f7SJohn Marino /* Here's how to access the current copy of the ICVs.  */
391*629ff9f7SJohn Marino 
gomp_icv(bool write)392*629ff9f7SJohn Marino static inline struct gomp_task_icv *gomp_icv (bool write)
393*629ff9f7SJohn Marino {
394*629ff9f7SJohn Marino   struct gomp_task *task = gomp_thread ()->task;
395*629ff9f7SJohn Marino   if (task)
396*629ff9f7SJohn Marino     return &task->icv;
397*629ff9f7SJohn Marino   else if (write)
398*629ff9f7SJohn Marino     return gomp_new_icv ();
399*629ff9f7SJohn Marino   else
400*629ff9f7SJohn Marino     return &gomp_global_icv;
401*629ff9f7SJohn Marino }
402*629ff9f7SJohn Marino 
403*629ff9f7SJohn Marino /* The attributes to be used during thread creation.  */
404*629ff9f7SJohn Marino extern pthread_attr_t gomp_thread_attr;
405*629ff9f7SJohn Marino 
406*629ff9f7SJohn Marino /* Other variables.  */
407*629ff9f7SJohn Marino 
408*629ff9f7SJohn Marino extern unsigned short *gomp_cpu_affinity;
409*629ff9f7SJohn Marino extern size_t gomp_cpu_affinity_len;
410*629ff9f7SJohn Marino 
411*629ff9f7SJohn Marino /* Function prototypes.  */
412*629ff9f7SJohn Marino 
413*629ff9f7SJohn Marino /* affinity.c */
414*629ff9f7SJohn Marino 
415*629ff9f7SJohn Marino extern void gomp_init_affinity (void);
416*629ff9f7SJohn Marino extern void gomp_init_thread_affinity (pthread_attr_t *);
417*629ff9f7SJohn Marino 
418*629ff9f7SJohn Marino /* alloc.c */
419*629ff9f7SJohn Marino 
420*629ff9f7SJohn Marino extern void *gomp_malloc (size_t) __attribute__((malloc));
421*629ff9f7SJohn Marino extern void *gomp_malloc_cleared (size_t) __attribute__((malloc));
422*629ff9f7SJohn Marino extern void *gomp_realloc (void *, size_t);
423*629ff9f7SJohn Marino 
424*629ff9f7SJohn Marino /* Avoid conflicting prototypes of alloca() in system headers by using
425*629ff9f7SJohn Marino    GCC's builtin alloca().  */
426*629ff9f7SJohn Marino #define gomp_alloca(x)  __builtin_alloca(x)
427*629ff9f7SJohn Marino 
428*629ff9f7SJohn Marino /* error.c */
429*629ff9f7SJohn Marino 
430*629ff9f7SJohn Marino extern void gomp_error (const char *, ...)
431*629ff9f7SJohn Marino 	__attribute__((format (printf, 1, 2)));
432*629ff9f7SJohn Marino extern void gomp_fatal (const char *, ...)
433*629ff9f7SJohn Marino 	__attribute__((noreturn, format (printf, 1, 2)));
434*629ff9f7SJohn Marino 
435*629ff9f7SJohn Marino /* iter.c */
436*629ff9f7SJohn Marino 
437*629ff9f7SJohn Marino extern int gomp_iter_static_next (long *, long *);
438*629ff9f7SJohn Marino extern bool gomp_iter_dynamic_next_locked (long *, long *);
439*629ff9f7SJohn Marino extern bool gomp_iter_guided_next_locked (long *, long *);
440*629ff9f7SJohn Marino 
441*629ff9f7SJohn Marino #ifdef HAVE_SYNC_BUILTINS
442*629ff9f7SJohn Marino extern bool gomp_iter_dynamic_next (long *, long *);
443*629ff9f7SJohn Marino extern bool gomp_iter_guided_next (long *, long *);
444*629ff9f7SJohn Marino #endif
445*629ff9f7SJohn Marino 
446*629ff9f7SJohn Marino /* iter_ull.c */
447*629ff9f7SJohn Marino 
448*629ff9f7SJohn Marino extern int gomp_iter_ull_static_next (unsigned long long *,
449*629ff9f7SJohn Marino 				      unsigned long long *);
450*629ff9f7SJohn Marino extern bool gomp_iter_ull_dynamic_next_locked (unsigned long long *,
451*629ff9f7SJohn Marino 					       unsigned long long *);
452*629ff9f7SJohn Marino extern bool gomp_iter_ull_guided_next_locked (unsigned long long *,
453*629ff9f7SJohn Marino 					      unsigned long long *);
454*629ff9f7SJohn Marino 
455*629ff9f7SJohn Marino #if defined HAVE_SYNC_BUILTINS && defined __LP64__
456*629ff9f7SJohn Marino extern bool gomp_iter_ull_dynamic_next (unsigned long long *,
457*629ff9f7SJohn Marino 					unsigned long long *);
458*629ff9f7SJohn Marino extern bool gomp_iter_ull_guided_next (unsigned long long *,
459*629ff9f7SJohn Marino 				       unsigned long long *);
460*629ff9f7SJohn Marino #endif
461*629ff9f7SJohn Marino 
462*629ff9f7SJohn Marino /* ordered.c */
463*629ff9f7SJohn Marino 
464*629ff9f7SJohn Marino extern void gomp_ordered_first (void);
465*629ff9f7SJohn Marino extern void gomp_ordered_last (void);
466*629ff9f7SJohn Marino extern void gomp_ordered_next (void);
467*629ff9f7SJohn Marino extern void gomp_ordered_static_init (void);
468*629ff9f7SJohn Marino extern void gomp_ordered_static_next (void);
469*629ff9f7SJohn Marino extern void gomp_ordered_sync (void);
470*629ff9f7SJohn Marino 
471*629ff9f7SJohn Marino /* parallel.c */
472*629ff9f7SJohn Marino 
473*629ff9f7SJohn Marino extern unsigned gomp_resolve_num_threads (unsigned, unsigned);
474*629ff9f7SJohn Marino 
475*629ff9f7SJohn Marino /* proc.c (in config/) */
476*629ff9f7SJohn Marino 
477*629ff9f7SJohn Marino extern void gomp_init_num_threads (void);
478*629ff9f7SJohn Marino extern unsigned gomp_dynamic_max_threads (void);
479*629ff9f7SJohn Marino 
480*629ff9f7SJohn Marino /* task.c */
481*629ff9f7SJohn Marino 
482*629ff9f7SJohn Marino extern void gomp_init_task (struct gomp_task *, struct gomp_task *,
483*629ff9f7SJohn Marino 			    struct gomp_task_icv *);
484*629ff9f7SJohn Marino extern void gomp_end_task (void);
485*629ff9f7SJohn Marino extern void gomp_barrier_handle_tasks (gomp_barrier_state_t);
486*629ff9f7SJohn Marino 
487*629ff9f7SJohn Marino static void inline
gomp_finish_task(struct gomp_task * task)488*629ff9f7SJohn Marino gomp_finish_task (struct gomp_task *task)
489*629ff9f7SJohn Marino {
490*629ff9f7SJohn Marino   gomp_sem_destroy (&task->taskwait_sem);
491*629ff9f7SJohn Marino }
492*629ff9f7SJohn Marino 
493*629ff9f7SJohn Marino /* team.c */
494*629ff9f7SJohn Marino 
495*629ff9f7SJohn Marino extern struct gomp_team *gomp_new_team (unsigned);
496*629ff9f7SJohn Marino extern void gomp_team_start (void (*) (void *), void *, unsigned,
497*629ff9f7SJohn Marino 			     struct gomp_team *);
498*629ff9f7SJohn Marino extern void gomp_team_end (void);
499*629ff9f7SJohn Marino 
500*629ff9f7SJohn Marino /* work.c */
501*629ff9f7SJohn Marino 
502*629ff9f7SJohn Marino extern void gomp_init_work_share (struct gomp_work_share *, bool, unsigned);
503*629ff9f7SJohn Marino extern void gomp_fini_work_share (struct gomp_work_share *);
504*629ff9f7SJohn Marino extern bool gomp_work_share_start (bool);
505*629ff9f7SJohn Marino extern void gomp_work_share_end (void);
506*629ff9f7SJohn Marino extern void gomp_work_share_end_nowait (void);
507*629ff9f7SJohn Marino 
508*629ff9f7SJohn Marino static inline void
gomp_work_share_init_done(void)509*629ff9f7SJohn Marino gomp_work_share_init_done (void)
510*629ff9f7SJohn Marino {
511*629ff9f7SJohn Marino   struct gomp_thread *thr = gomp_thread ();
512*629ff9f7SJohn Marino   if (__builtin_expect (thr->ts.last_work_share != NULL, 1))
513*629ff9f7SJohn Marino     gomp_ptrlock_set (&thr->ts.last_work_share->next_ws, thr->ts.work_share);
514*629ff9f7SJohn Marino }
515*629ff9f7SJohn Marino 
516*629ff9f7SJohn Marino #ifdef HAVE_ATTRIBUTE_VISIBILITY
517*629ff9f7SJohn Marino # pragma GCC visibility pop
518*629ff9f7SJohn Marino #endif
519*629ff9f7SJohn Marino 
520*629ff9f7SJohn Marino /* Now that we're back to default visibility, include the globals.  */
521*629ff9f7SJohn Marino #include "libgomp_g.h"
522*629ff9f7SJohn Marino 
523*629ff9f7SJohn Marino /* Include omp.h by parts.  */
524*629ff9f7SJohn Marino #include "omp-lock.h"
525*629ff9f7SJohn Marino #define _LIBGOMP_OMP_LOCK_DEFINED 1
526*629ff9f7SJohn Marino #include "omp.h.in"
527*629ff9f7SJohn Marino 
528*629ff9f7SJohn Marino #if !defined (HAVE_ATTRIBUTE_VISIBILITY) \
529*629ff9f7SJohn Marino     || !defined (HAVE_ATTRIBUTE_ALIAS) \
530*629ff9f7SJohn Marino     || !defined (HAVE_AS_SYMVER_DIRECTIVE) \
531*629ff9f7SJohn Marino     || !defined (PIC) \
532*629ff9f7SJohn Marino     || !defined (HAVE_SYMVER_SYMBOL_RENAMING_RUNTIME_SUPPORT)
533*629ff9f7SJohn Marino # undef LIBGOMP_GNU_SYMBOL_VERSIONING
534*629ff9f7SJohn Marino #endif
535*629ff9f7SJohn Marino 
536*629ff9f7SJohn Marino #ifdef LIBGOMP_GNU_SYMBOL_VERSIONING
537*629ff9f7SJohn Marino extern void gomp_init_lock_30 (omp_lock_t *) __GOMP_NOTHROW;
538*629ff9f7SJohn Marino extern void gomp_destroy_lock_30 (omp_lock_t *) __GOMP_NOTHROW;
539*629ff9f7SJohn Marino extern void gomp_set_lock_30 (omp_lock_t *) __GOMP_NOTHROW;
540*629ff9f7SJohn Marino extern void gomp_unset_lock_30 (omp_lock_t *) __GOMP_NOTHROW;
541*629ff9f7SJohn Marino extern int gomp_test_lock_30 (omp_lock_t *) __GOMP_NOTHROW;
542*629ff9f7SJohn Marino extern void gomp_init_nest_lock_30 (omp_nest_lock_t *) __GOMP_NOTHROW;
543*629ff9f7SJohn Marino extern void gomp_destroy_nest_lock_30 (omp_nest_lock_t *) __GOMP_NOTHROW;
544*629ff9f7SJohn Marino extern void gomp_set_nest_lock_30 (omp_nest_lock_t *) __GOMP_NOTHROW;
545*629ff9f7SJohn Marino extern void gomp_unset_nest_lock_30 (omp_nest_lock_t *) __GOMP_NOTHROW;
546*629ff9f7SJohn Marino extern int gomp_test_nest_lock_30 (omp_nest_lock_t *) __GOMP_NOTHROW;
547*629ff9f7SJohn Marino 
548*629ff9f7SJohn Marino extern void gomp_init_lock_25 (omp_lock_25_t *) __GOMP_NOTHROW;
549*629ff9f7SJohn Marino extern void gomp_destroy_lock_25 (omp_lock_25_t *) __GOMP_NOTHROW;
550*629ff9f7SJohn Marino extern void gomp_set_lock_25 (omp_lock_25_t *) __GOMP_NOTHROW;
551*629ff9f7SJohn Marino extern void gomp_unset_lock_25 (omp_lock_25_t *) __GOMP_NOTHROW;
552*629ff9f7SJohn Marino extern int gomp_test_lock_25 (omp_lock_25_t *) __GOMP_NOTHROW;
553*629ff9f7SJohn Marino extern void gomp_init_nest_lock_25 (omp_nest_lock_25_t *) __GOMP_NOTHROW;
554*629ff9f7SJohn Marino extern void gomp_destroy_nest_lock_25 (omp_nest_lock_25_t *) __GOMP_NOTHROW;
555*629ff9f7SJohn Marino extern void gomp_set_nest_lock_25 (omp_nest_lock_25_t *) __GOMP_NOTHROW;
556*629ff9f7SJohn Marino extern void gomp_unset_nest_lock_25 (omp_nest_lock_25_t *) __GOMP_NOTHROW;
557*629ff9f7SJohn Marino extern int gomp_test_nest_lock_25 (omp_nest_lock_25_t *) __GOMP_NOTHROW;
558*629ff9f7SJohn Marino 
559*629ff9f7SJohn Marino # define strong_alias(fn, al) \
560*629ff9f7SJohn Marino   extern __typeof (fn) al __attribute__ ((alias (#fn)));
561*629ff9f7SJohn Marino # define omp_lock_symver(fn) \
562*629ff9f7SJohn Marino   __asm (".symver g" #fn "_30, " #fn "@@OMP_3.0"); \
563*629ff9f7SJohn Marino   __asm (".symver g" #fn "_25, " #fn "@OMP_1.0");
564*629ff9f7SJohn Marino #else
565*629ff9f7SJohn Marino # define gomp_init_lock_30 omp_init_lock
566*629ff9f7SJohn Marino # define gomp_destroy_lock_30 omp_destroy_lock
567*629ff9f7SJohn Marino # define gomp_set_lock_30 omp_set_lock
568*629ff9f7SJohn Marino # define gomp_unset_lock_30 omp_unset_lock
569*629ff9f7SJohn Marino # define gomp_test_lock_30 omp_test_lock
570*629ff9f7SJohn Marino # define gomp_init_nest_lock_30 omp_init_nest_lock
571*629ff9f7SJohn Marino # define gomp_destroy_nest_lock_30 omp_destroy_nest_lock
572*629ff9f7SJohn Marino # define gomp_set_nest_lock_30 omp_set_nest_lock
573*629ff9f7SJohn Marino # define gomp_unset_nest_lock_30 omp_unset_nest_lock
574*629ff9f7SJohn Marino # define gomp_test_nest_lock_30 omp_test_nest_lock
575*629ff9f7SJohn Marino #endif
576*629ff9f7SJohn Marino 
577*629ff9f7SJohn Marino #ifdef HAVE_ATTRIBUTE_VISIBILITY
578*629ff9f7SJohn Marino # define attribute_hidden __attribute__ ((visibility ("hidden")))
579*629ff9f7SJohn Marino #else
580*629ff9f7SJohn Marino # define attribute_hidden
581*629ff9f7SJohn Marino #endif
582*629ff9f7SJohn Marino 
583*629ff9f7SJohn Marino #ifdef HAVE_ATTRIBUTE_ALIAS
584*629ff9f7SJohn Marino # define ialias(fn) \
585*629ff9f7SJohn Marino   extern __typeof (fn) gomp_ialias_##fn \
586*629ff9f7SJohn Marino     __attribute__ ((alias (#fn))) attribute_hidden;
587*629ff9f7SJohn Marino #else
588*629ff9f7SJohn Marino # define ialias(fn)
589*629ff9f7SJohn Marino #endif
590*629ff9f7SJohn Marino 
591*629ff9f7SJohn Marino #endif /* LIBGOMP_H */
592