source: trunk/sys/libgomp/include/gomp/bar.h @ 50

Last change on this file since 50 was 1, checked in by alain, 8 years ago

First import

File size: 3.2 KB
Line 
1/* Copyright (C) 2005, 2008, 2009 Free Software Foundation, Inc.
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 General Public License as published by
8   the Free Software Foundation; either version 3, or (at your option)
9   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 General Public License for
14   more details.
15
16   Under Section 7 of GPL version 3, you are granted additional
17   permissions described in the GCC Runtime Library Exception, version
18   3.1, as published by the Free Software Foundation.
19
20   You should have received a copy of the GNU General Public License and
21   a copy of the GCC Runtime Library Exception along with this program;
22   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23   <http://www.gnu.org/licenses/>.  */
24
25/* This is the default implementation of a barrier synchronization mechanism
26   for libgomp.  This type is private to the library.  Note that we rely on
27   being able to adjust the barrier count while threads are blocked, so the
28   POSIX pthread_barrier_t won't work.  */
29
30#ifndef GOMP_BARRIER_H
31#define GOMP_BARRIER_H 1
32
33#include <pthread.h>
34
35typedef struct
36{
37  gomp_mutex_t mutex1;
38#ifndef HAVE_SYNC_BUILTINS
39  gomp_mutex_t mutex2;
40#endif
41  gomp_sem_t sem1;
42  gomp_sem_t sem2;
43  unsigned total;
44  unsigned arrived;
45  unsigned generation;
46} gomp_barrier_t;
47typedef unsigned int gomp_barrier_state_t;
48
49extern void gomp_barrier_init (gomp_barrier_t *, unsigned);
50extern void gomp_barrier_reinit (gomp_barrier_t *, unsigned);
51extern void gomp_barrier_destroy (gomp_barrier_t *);
52
53extern void gomp_barrier_wait (gomp_barrier_t *);
54extern void gomp_barrier_wait_end (gomp_barrier_t *, gomp_barrier_state_t);
55extern void gomp_team_barrier_wait (gomp_barrier_t *);
56extern void gomp_team_barrier_wait_end (gomp_barrier_t *,
57                                        gomp_barrier_state_t);
58extern void gomp_team_barrier_wake (gomp_barrier_t *, int);
59
60static inline gomp_barrier_state_t
61gomp_barrier_wait_start (gomp_barrier_t *bar)
62{
63  unsigned int ret;
64  gomp_mutex_lock (&bar->mutex1);
65  ret = bar->generation & ~3;
66  ret += ++bar->arrived == bar->total;
67  return ret;
68}
69
70static inline bool
71gomp_barrier_last_thread (gomp_barrier_state_t state)
72{
73  return state & 1;
74}
75
76static inline void
77gomp_barrier_wait_last (gomp_barrier_t *bar)
78{
79  gomp_barrier_wait (bar);
80}
81
82/* All the inlines below must be called with team->task_lock
83   held.  */
84
85static inline void
86gomp_team_barrier_set_task_pending (gomp_barrier_t *bar)
87{
88  bar->generation |= 1;
89}
90
91static inline void
92gomp_team_barrier_clear_task_pending (gomp_barrier_t *bar)
93{
94  bar->generation &= ~1;
95}
96
97static inline void
98gomp_team_barrier_set_waiting_for_tasks (gomp_barrier_t *bar)
99{
100  bar->generation |= 2;
101}
102
103static inline bool
104gomp_team_barrier_waiting_for_tasks (gomp_barrier_t *bar)
105{
106  return (bar->generation & 2) != 0;
107}
108
109static inline void
110gomp_team_barrier_done (gomp_barrier_t *bar, gomp_barrier_state_t state)
111{
112  bar->generation = (state & ~3) + 4;
113}
114
115#endif /* GOMP_BARRIER_H */
Note: See TracBrowser for help on using the repository browser.