]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgomp/config/linux/bar.h
c-cppbuiltin.c (c_cpp_builtins): Change _OPENMP value to 200805.
[thirdparty/gcc.git] / libgomp / config / linux / bar.h
CommitLineData
a68ab351 1/* Copyright (C) 2005, 2008 Free Software Foundation, Inc.
953ff289
DN
2 Contributed by Richard Henderson <rth@redhat.com>.
3
4 This file is part of the GNU OpenMP Library (libgomp).
5
6 Libgomp is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with libgomp; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 MA 02110-1301, USA. */
20
21/* As a special exception, if you link this library with other files, some
22 of which are compiled with GCC, to produce an executable, this library
23 does not by itself cause the resulting executable to be covered by the
24 GNU General Public License. This exception does not however invalidate
25 any other reasons why the executable file might be covered by the GNU
26 General Public License. */
27
28/* This is a Linux specific implementation of a barrier synchronization
29 mechanism for libgomp. This type is private to the library. This
30 implementation uses atomic instructions and the futex syscall. */
31
32#ifndef GOMP_BARRIER_H
33#define GOMP_BARRIER_H 1
34
35#include "mutex.h"
36
37typedef struct
38{
a68ab351
JJ
39 /* Make sure total/generation is in a mostly read cacheline, while
40 awaited in a separate cacheline. */
41 unsigned total __attribute__((aligned (64)));
42 unsigned generation;
43 unsigned awaited __attribute__((aligned (64)));
953ff289 44} gomp_barrier_t;
a68ab351 45typedef unsigned int gomp_barrier_state_t;
953ff289
DN
46
47static inline void gomp_barrier_init (gomp_barrier_t *bar, unsigned count)
48{
953ff289 49 bar->total = count;
a68ab351 50 bar->awaited = count;
953ff289
DN
51 bar->generation = 0;
52}
53
54static inline void gomp_barrier_reinit (gomp_barrier_t *bar, unsigned count)
55{
a68ab351 56 __sync_fetch_and_add (&bar->awaited, count - bar->total);
953ff289 57 bar->total = count;
953ff289
DN
58}
59
60static inline void gomp_barrier_destroy (gomp_barrier_t *bar)
61{
953ff289
DN
62}
63
64extern void gomp_barrier_wait (gomp_barrier_t *);
a68ab351
JJ
65extern void gomp_barrier_wait_last (gomp_barrier_t *);
66extern void gomp_barrier_wait_end (gomp_barrier_t *, gomp_barrier_state_t);
67extern void gomp_team_barrier_wait (gomp_barrier_t *);
68extern void gomp_team_barrier_wait_end (gomp_barrier_t *,
69 gomp_barrier_state_t);
70extern void gomp_team_barrier_wake (gomp_barrier_t *, int);
953ff289 71
a68ab351
JJ
72static inline gomp_barrier_state_t
73gomp_barrier_wait_start (gomp_barrier_t *bar)
953ff289 74{
a68ab351
JJ
75 unsigned int ret = bar->generation & ~3;
76 /* Do we need any barrier here or is __sync_add_and_fetch acting
77 as the needed LoadLoad barrier already? */
78 ret += __sync_add_and_fetch (&bar->awaited, -1) == 0;
79 return ret;
80}
81
82static inline bool
83gomp_barrier_last_thread (gomp_barrier_state_t state)
84{
85 return state & 1;
86}
87
88/* All the inlines below must be called with team->task_lock
89 held. */
90
91static inline void
92gomp_team_barrier_set_task_pending (gomp_barrier_t *bar)
93{
94 bar->generation |= 1;
95}
96
97static inline void
98gomp_team_barrier_clear_task_pending (gomp_barrier_t *bar)
99{
100 bar->generation &= ~1;
101}
102
103static inline void
104gomp_team_barrier_set_waiting_for_tasks (gomp_barrier_t *bar)
105{
106 bar->generation |= 2;
107}
108
109static inline bool
110gomp_team_barrier_waiting_for_tasks (gomp_barrier_t *bar)
111{
112 return (bar->generation & 2) != 0;
113}
114
115static inline void
116gomp_team_barrier_done (gomp_barrier_t *bar, gomp_barrier_state_t state)
117{
118 bar->generation = (state & ~3) + 4;
953ff289
DN
119}
120
121#endif /* GOMP_BARRIER_H */