]>
Commit | Line | Data |
---|---|---|
748086b7 | 1 | /* Copyright (C) 2005, 2008, 2009 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 | |
748086b7 JJ |
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. | |
953ff289 DN |
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 | |
748086b7 | 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
953ff289 DN |
14 | more details. |
15 | ||
748086b7 JJ |
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/>. */ | |
953ff289 DN |
24 | |
25 | /* This file handles the SINGLE construct. */ | |
26 | ||
27 | #include "libgomp.h" | |
28 | ||
29 | ||
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. */ | |
33 | ||
34 | bool | |
35 | GOMP_single_start (void) | |
36 | { | |
a68ab351 JJ |
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; | |
41 | ||
42 | if (__builtin_expect (team == NULL, 0)) | |
43 | return true; | |
44 | ||
45 | single_count = thr->ts.single_count++; | |
46 | return __sync_bool_compare_and_swap (&team->single_count, single_count, | |
47 | single_count + 1L); | |
48 | #else | |
953ff289 | 49 | bool ret = gomp_work_share_start (false); |
a68ab351 JJ |
50 | if (ret) |
51 | gomp_work_share_init_done (); | |
953ff289 DN |
52 | gomp_work_share_end_nowait (); |
53 | return ret; | |
a68ab351 | 54 | #endif |
953ff289 DN |
55 | } |
56 | ||
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. */ | |
61 | ||
62 | void * | |
63 | GOMP_single_copy_start (void) | |
64 | { | |
65 | struct gomp_thread *thr = gomp_thread (); | |
66 | ||
67 | bool first; | |
68 | void *ret; | |
69 | ||
70 | first = gomp_work_share_start (false); | |
953ff289 DN |
71 | |
72 | if (first) | |
a68ab351 JJ |
73 | { |
74 | gomp_work_share_init_done (); | |
75 | ret = NULL; | |
76 | } | |
953ff289 DN |
77 | else |
78 | { | |
a68ab351 | 79 | gomp_team_barrier_wait (&thr->ts.team->barrier); |
953ff289 DN |
80 | |
81 | ret = thr->ts.work_share->copyprivate; | |
82 | gomp_work_share_end_nowait (); | |
83 | } | |
84 | ||
85 | return ret; | |
86 | } | |
87 | ||
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. */ | |
90 | ||
91 | void | |
92 | GOMP_single_copy_end (void *data) | |
93 | { | |
94 | struct gomp_thread *thr = gomp_thread (); | |
95 | struct gomp_team *team = thr->ts.team; | |
96 | ||
97 | if (team != NULL) | |
98 | { | |
99 | thr->ts.work_share->copyprivate = data; | |
a68ab351 | 100 | gomp_team_barrier_wait (&team->barrier); |
953ff289 DN |
101 | } |
102 | ||
103 | gomp_work_share_end_nowait (); | |
104 | } |