1 /* Copyright (C) 2005-2014 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>.
4 This file is part of the GNU OpenMP Library (libgomp).
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)
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
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.
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/>. */
25 /* This file handles the SINGLE construct. */
30 /* This routine is called when first encountering a SINGLE construct that
31 doesn't have a COPYPRIVATE clause. Returns true if this is the thread
32 that should execute the clause. */
35 GOMP_single_start (void)
37 #ifdef HAVE_SYNC_BUILTINS
38 struct gomp_thread
*thr
= gomp_thread ();
39 struct gomp_team
*team
= thr
->ts
.team
;
40 unsigned long single_count
;
42 if (__builtin_expect (team
== NULL
, 0))
45 single_count
= thr
->ts
.single_count
++;
46 return __sync_bool_compare_and_swap (&team
->single_count
, single_count
,
49 bool ret
= gomp_work_share_start (false);
51 gomp_work_share_init_done ();
52 gomp_work_share_end_nowait ();
57 /* This routine is called when first encountering a SINGLE construct that
58 does have a COPYPRIVATE clause. Returns NULL if this is the thread
59 that should execute the clause; otherwise the return value is pointer
60 given to GOMP_single_copy_end by the thread that did execute the clause. */
63 GOMP_single_copy_start (void)
65 struct gomp_thread
*thr
= gomp_thread ();
70 first
= gomp_work_share_start (false);
74 gomp_work_share_init_done ();
79 gomp_team_barrier_wait (&thr
->ts
.team
->barrier
);
81 ret
= thr
->ts
.work_share
->copyprivate
;
82 gomp_work_share_end_nowait ();
88 /* This routine is called when the thread that entered a SINGLE construct
89 with a COPYPRIVATE clause gets to the end of the construct. */
92 GOMP_single_copy_end (void *data
)
94 struct gomp_thread
*thr
= gomp_thread ();
95 struct gomp_team
*team
= thr
->ts
.team
;
99 thr
->ts
.work_share
->copyprivate
= data
;
100 gomp_team_barrier_wait (&team
->barrier
);
103 gomp_work_share_end_nowait ();