Skip to content

Commit 1a57d60

Browse files
committed
Refactor acl_usm.cpp with new multi-threading routines
1 parent ee91ab9 commit 1a57d60

File tree

3 files changed

+147
-117
lines changed

3 files changed

+147
-117
lines changed

include/acl_thread.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
// System headers.
1616
#include <thread>
17+
#include <mutex>
1718

1819
#if defined(__cplusplus)
1920
extern "C" {
@@ -35,7 +36,7 @@ extern ACL_TLS int acl_inside_sig_old_lock_count;
3536

3637
extern aclMutex amtex;
3738

38-
#define ALC_LOCK_GUARD std::lock_guard<aclMutex> l(amtex)
39+
using acl_lock_guard = std::lock_guard<aclMutex>;
3940

4041
// -- signal handler functions --
4142
// When we enter a signal handler, we save "acl_global_lock_count" to

include/acl_util.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ void acl_dump_mem(cl_mem mem);
115115
#define acl_dump_mem(x)
116116
#endif
117117
/////////////////////
118+
#define RETURN(ret) \
119+
do { \
120+
return (ret); \
121+
} while (0)
122+
123+
#define RETURN_VOID \
124+
do { \
125+
return; \
126+
} while (0)
118127

119128
#define UNLOCK_RETURN(ret) \
120129
do { \
@@ -190,6 +199,26 @@ void acl_dump_mem(cl_mem mem);
190199
} \
191200
} while (0)
192201

202+
#define VALIDATE_ARRAY_OUT_ARGS(buf_size, buf, answer_size_out, \
203+
context) \
204+
do { \
205+
if (buf && buf_size <= 0) { \
206+
acl_context_callback(context, \
207+
#buf " is specified but " #buf_size " is zero"); \
208+
RETURN(CL_INVALID_VALUE); \
209+
} \
210+
if (buf == 0 && buf_size > 0) { \
211+
acl_context_callback(context, #buf " is not specified but " #buf_size \
212+
" is positive"); \
213+
RETURN(CL_INVALID_VALUE); \
214+
} \
215+
if (answer_size_out == 0 && buf == 0) { \
216+
acl_context_callback(context, \
217+
#buf " and " #answer_size_out " are both zero"); \
218+
RETURN(CL_INVALID_VALUE); \
219+
} \
220+
} while (0)
221+
193222
// On 32-bit ARM, pointers are 32-bit. 2GB value becomes a huge negative number
194223
// unless it's cast to a 64-bit integer. Need to cast to size_t first to avoid
195224
// warning of "casting pointer to integer of different size". Note that using

0 commit comments

Comments
 (0)