Merge trunk version 204345 into gupc branch.
[official-gcc.git] / libgupc / smp / upc_libg.c
blob59f6f0530079fa2e7dca0598118ed34cc3910bd2
1 /* Copyright (C) 2009-2013 Free Software Foundation, Inc.
2 This file is part of the UPC runtime library.
3 Written by Gary Funck <gary@intrepid.com>
4 and Nenad Vukicevic <nenad@intrepid.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
28 #include "upc_config.h"
29 #include "upc_sysdep.h"
30 #include "upc_defs.h"
31 #include "upc_sup.h"
32 #include "upc_lib.h"
33 #include "gasp_upc.h"
34 #include "upc_pupc.h"
36 void
37 __upc_barrierg (int barrier_id, const char *filename, const int linenum)
39 int named = (barrier_id != INT_MIN);
40 p_start (GASP_UPC_BARRIER, named, barrier_id);
41 GUPCR_SET_ERR_LOC();
42 __upc_barrier (barrier_id);
43 GUPCR_CLEAR_ERR_LOC();
44 p_end (GASP_UPC_BARRIER, named, barrier_id);
47 void
48 __upc_notifyg (int barrier_id, const char *filename, const int linenum)
50 int named = (barrier_id != INT_MIN);
51 p_start (GASP_UPC_NOTIFY, named, barrier_id);
52 GUPCR_SET_ERR_LOC();
53 __upc_notify (barrier_id);
54 GUPCR_CLEAR_ERR_LOC();
55 p_end (GASP_UPC_NOTIFY, named, barrier_id);
58 void
59 __upc_waitg (int barrier_id, const char *filename, const int linenum)
61 int named = (barrier_id != INT_MIN);
62 p_start (GASP_UPC_WAIT, named, barrier_id);
63 GUPCR_SET_ERR_LOC();
64 __upc_wait (barrier_id);
65 GUPCR_CLEAR_ERR_LOC();
66 p_end (GASP_UPC_WAIT, named, barrier_id);
69 upc_shared_ptr_t
70 upc_global_lock_allocg (const char *filename, int linenum)
72 upc_shared_ptr_t result;
73 p_start (GASP_UPC_GLOBAL_LOCK_ALLOC);
74 GUPCR_SET_ERR_LOC();
75 result = upc_global_lock_alloc();
76 GUPCR_CLEAR_ERR_LOC();
77 p_end (GASP_UPC_GLOBAL_LOCK_ALLOC, &result);
78 return result;
81 void
82 upc_all_lock_freeg (upc_shared_ptr_t ptr, const char *filename, int linenum)
84 p_start (GASP_UPC_LOCK_FREE, &ptr);
85 GUPCR_SET_ERR_LOC();
86 upc_all_lock_free(ptr);
87 GUPCR_CLEAR_ERR_LOC();
88 p_end (GASP_UPC_LOCK_FREE, &ptr);
91 void
92 upc_lock_freeg (upc_shared_ptr_t ptr, const char *filename, int linenum)
94 p_start (GASP_UPC_LOCK_FREE, &ptr);
95 GUPCR_SET_ERR_LOC();
96 upc_lock_free(ptr);
97 GUPCR_CLEAR_ERR_LOC();
98 p_end (GASP_UPC_LOCK_FREE, &ptr);
101 upc_shared_ptr_t
102 upc_all_lock_allocg (const char *filename, int linenum)
104 upc_shared_ptr_t result;
105 p_start (GASP_UPC_ALL_LOCK_ALLOC);
106 GUPCR_SET_ERR_LOC();
107 result = upc_all_lock_alloc();
108 GUPCR_CLEAR_ERR_LOC();
109 p_end (GASP_UPC_ALL_LOCK_ALLOC, &result);
110 return result;
113 void
114 upc_lockg (upc_shared_ptr_t ptr, const char *filename, int linenum)
116 p_start (GASP_UPC_LOCK, &ptr);
117 GUPCR_SET_ERR_LOC();
118 upc_lock(ptr);
119 GUPCR_CLEAR_ERR_LOC();
120 p_end (GASP_UPC_LOCK, &ptr);
124 upc_lock_attemptg (upc_shared_ptr_t ptr, const char *filename, int linenum)
126 int status;
127 p_start (GASP_UPC_LOCK_ATTEMPT, &ptr);
128 GUPCR_SET_ERR_LOC();
129 status = upc_lock_attempt(ptr);
130 GUPCR_CLEAR_ERR_LOC();
131 p_end (GASP_UPC_LOCK_ATTEMPT, &ptr, status);
132 return status;
135 void
136 upc_unlockg (upc_shared_ptr_t ptr, const char *filename, int linenum)
138 p_start (GASP_UPC_UNLOCK, &ptr);
139 GUPCR_SET_ERR_LOC();
140 upc_unlock(ptr);
141 GUPCR_CLEAR_ERR_LOC();
142 p_end (GASP_UPC_UNLOCK, &ptr);
145 void
146 __upc_funcg (int start, const char *funcname,
147 const char *filename, const int linenum)
149 if (start)
150 p_start (GASP_C_FUNC, funcname);
151 else
152 p_end (GASP_C_FUNC, funcname);
155 void
156 __upc_forallg (int start, const char *filename, const int linenum)
158 if (start)
159 p_start (GASP_UPC_FORALL);
160 else
161 p_end (GASP_UPC_FORALL);
164 extern void __upc_exitg (int status, const char *filename, int linenum)
165 __attribute__ ((__noreturn__));
167 void
168 __upc_exitg (int status, const char *filename, int linenum)
170 p_start (GASP_UPC_COLLECTIVE_EXIT, status);
171 p_end (GASP_UPC_COLLECTIVE_EXIT, status);
172 __upc_exit (status);
175 void
176 upc_global_exitg (int status, const char *filename, int linenum)
178 p_atomic (GASP_UPC_NONCOLLECTIVE_EXIT, status);
179 upc_global_exit (status);
182 void *
183 __cvtaddrg (upc_shared_ptr_t p, const char *filename, int linenum)
185 void *result;
186 GUPCR_SET_ERR_LOC();
187 result = __cvtaddr (p);
188 GUPCR_CLEAR_ERR_LOC();
189 return result;
192 void *
193 __getaddrg (upc_shared_ptr_t p, const char *filename, int linenum)
195 void *result;
196 GUPCR_SET_ERR_LOC();
197 result = __getaddr (p);
198 GUPCR_CLEAR_ERR_LOC();
199 return result;
202 size_t
203 upc_addrfieldg (upc_shared_ptr_t p, const char *filename, int linenum)
205 size_t result;
206 GUPCR_SET_ERR_LOC();
207 result = upc_addrfield (p);
208 GUPCR_CLEAR_ERR_LOC();
209 return result;
212 size_t
213 upc_affinitysizeg (size_t totalsize, size_t nbytes, size_t threadid,
214 const char *filename, int linenum)
216 size_t result;
217 GUPCR_SET_ERR_LOC();
218 result = upc_affinitysize (totalsize, nbytes, threadid);
219 GUPCR_CLEAR_ERR_LOC();
220 return result;
223 size_t
224 upc_phaseofg (upc_shared_ptr_t p, const char *filename, int linenum)
226 size_t result;
227 GUPCR_SET_ERR_LOC();
228 result = upc_phaseof (p);
229 GUPCR_CLEAR_ERR_LOC();
230 return result;
233 upc_shared_ptr_t
234 upc_resetphaseg (upc_shared_ptr_t p, const char *filename, int linenum)
236 upc_shared_ptr_t result;
237 GUPCR_SET_ERR_LOC();
238 result = upc_resetphase (p);
239 GUPCR_CLEAR_ERR_LOC();
240 return result;
243 size_t
244 upc_threadofg (upc_shared_ptr_t p, const char *filename, int linenum)
246 size_t result;
247 GUPCR_SET_ERR_LOC();
248 result = upc_threadof (p);
249 GUPCR_CLEAR_ERR_LOC();
250 return result;