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 Offloading and Multi Processing Library
7 Libgomp is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 /* This file handles the SINGLE construct. */
31 /* This routine is called when first encountering a SINGLE construct that
32 doesn't have a COPYPRIVATE clause. Returns true if this is the thread
33 that should execute the clause. */
36 GOMP_single_start (void)
38 #ifdef HAVE_SYNC_BUILTINS
39 struct gomp_thread
*thr
= gomp_thread ();
40 struct gomp_team
*team
= thr
->ts
.team
;
41 unsigned long single_count
;
43 if (__builtin_expect (team
== NULL
, 0))
46 single_count
= thr
->ts
.single_count
++;
47 return __sync_bool_compare_and_swap (&team
->single_count
, single_count
,
50 bool ret
= gomp_work_share_start (false);
52 gomp_work_share_init_done ();
53 gomp_work_share_end_nowait ();
58 /* This routine is called when first encountering a SINGLE construct that
59 does have a COPYPRIVATE clause. Returns NULL if this is the thread
60 that should execute the clause; otherwise the return value is pointer
61 given to GOMP_single_copy_end by the thread that did execute the clause. */
64 GOMP_single_copy_start (void)
66 struct gomp_thread
*thr
= gomp_thread ();
71 first
= gomp_work_share_start (false);
75 gomp_work_share_init_done ();
80 gomp_team_barrier_wait (&thr
->ts
.team
->barrier
);
82 ret
= thr
->ts
.work_share
->copyprivate
;
83 gomp_work_share_end_nowait ();
89 /* This routine is called when the thread that entered a SINGLE construct
90 with a COPYPRIVATE clause gets to the end of the construct. */
93 GOMP_single_copy_end (void *data
)
95 struct gomp_thread
*thr
= gomp_thread ();
96 struct gomp_team
*team
= thr
->ts
.team
;
100 thr
->ts
.work_share
->copyprivate
= data
;
101 gomp_team_barrier_wait (&team
->barrier
);
104 gomp_work_share_end_nowait ();