Skip to content

Commit 29c2bc1

Browse files
committed
Use std::scoped_lock instead
1 parent 2da64d6 commit 29c2bc1

17 files changed

+125
-127
lines changed

include/acl_thread.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ extern ACL_TLS int acl_inside_sig_old_lock_count;
3636

3737
extern acl_mutex_wrapper_t acl_wrapper_mutex;
3838

39-
using acl_lock_guard = std::lock_guard<acl_mutex_wrapper_t>;
40-
4139
// -- signal handler functions --
4240
// When we enter a signal handler, we save "acl_global_lock_count" to
4341
// "acl_inside_sig_old_lock_count" temporarily. This is because the signal

src/acl_command.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
ACL_EXPORT
3939
CL_API_ENTRY cl_int CL_API_CALL
4040
clEnqueueBarrierIntelFPGA(cl_command_queue command_queue) {
41-
acl_lock_guard lock{acl_wrapper_mutex};
41+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
4242

4343
if (!acl_command_queue_is_valid(command_queue)) {
4444
return CL_INVALID_COMMAND_QUEUE;
@@ -66,7 +66,7 @@ ACL_EXPORT
6666
CL_API_ENTRY cl_int CL_API_CALL
6767
clEnqueueMarkerIntelFPGA(cl_command_queue command_queue, cl_event *event) {
6868
cl_int result;
69-
acl_lock_guard lock{acl_wrapper_mutex};
69+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
7070

7171
if (!acl_command_queue_is_valid(command_queue)) {
7272
return CL_INVALID_COMMAND_QUEUE;
@@ -91,7 +91,7 @@ CL_API_ENTRY cl_int CL_API_CALL clEnqueueWaitForEventsIntelFPGA(
9191
cl_command_queue command_queue, cl_uint num_event, const cl_event *events) {
9292
cl_int result;
9393

94-
acl_lock_guard lock{acl_wrapper_mutex};
94+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
9595

9696
if (!acl_command_queue_is_valid(command_queue)) {
9797
return CL_INVALID_COMMAND_QUEUE;
@@ -129,7 +129,7 @@ clWaitForEventsIntelFPGA(cl_uint num_events, const cl_event *event_list) {
129129
cl_context context;
130130
bool first_yield_to_hal = true;
131131

132-
acl_lock_guard lock{acl_wrapper_mutex};
132+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
133133

134134
if (num_events == 0 || event_list == 0) {
135135
return CL_INVALID_VALUE;
@@ -214,7 +214,7 @@ CL_API_ENTRY cl_int CL_API_CALL clEnqueueMarkerWithWaitListIntelFPGA(
214214
cl_int result;
215215
cl_event ret_event = NULL;
216216

217-
acl_lock_guard lock{acl_wrapper_mutex};
217+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
218218

219219
if (!acl_command_queue_is_valid(command_queue)) {
220220
return CL_INVALID_COMMAND_QUEUE;
@@ -265,7 +265,7 @@ CL_API_ENTRY cl_int CL_API_CALL clEnqueueBarrierWithWaitListIntelFPGA(
265265
const cl_event *event_wait_list, cl_event *event) {
266266
cl_int result;
267267
cl_event local_event;
268-
acl_lock_guard lock{acl_wrapper_mutex};
268+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
269269

270270
result = clEnqueueMarkerWithWaitList(command_queue, num_events_in_wait_list,
271271
event_wait_list, &local_event);

src/acl_command_queue.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ clCreateCommandQueueWithPropertiesIntelFPGA(
114114
cl_command_queue result = 0;
115115
cl_command_queue_properties cq_properties = 0;
116116
cl_uint q_size_properties = 0, idx = 0;
117-
acl_lock_guard lock{acl_wrapper_mutex};
117+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
118118

119119
if (!acl_context_is_valid(context)) {
120120
BAIL(CL_INVALID_CONTEXT);
@@ -251,7 +251,7 @@ CL_API_ENTRY cl_command_queue CL_API_CALL clCreateCommandQueue(
251251
ACL_EXPORT
252252
CL_API_ENTRY cl_int CL_API_CALL
253253
clRetainCommandQueueIntelFPGA(cl_command_queue command_queue) {
254-
acl_lock_guard lock{acl_wrapper_mutex};
254+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
255255

256256
if (!acl_command_queue_is_valid(command_queue)) {
257257
return CL_INVALID_COMMAND_QUEUE;
@@ -269,7 +269,7 @@ clRetainCommandQueue(cl_command_queue command_queue) {
269269
ACL_EXPORT
270270
CL_API_ENTRY cl_int CL_API_CALL
271271
clReleaseCommandQueueIntelFPGA(cl_command_queue command_queue) {
272-
acl_lock_guard lock{acl_wrapper_mutex};
272+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
273273

274274
if (!acl_command_queue_is_valid(command_queue)) {
275275
return CL_INVALID_COMMAND_QUEUE;
@@ -298,7 +298,7 @@ CL_API_ENTRY cl_int CL_API_CALL clGetCommandQueueInfoIntelFPGA(
298298
cl_command_queue command_queue, cl_command_queue_info param_name,
299299
size_t param_value_size, void *param_value, size_t *param_value_size_ret) {
300300
acl_result_t result;
301-
acl_lock_guard lock{acl_wrapper_mutex};
301+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
302302

303303
if (!acl_command_queue_is_valid(command_queue)) {
304304
return CL_INVALID_COMMAND_QUEUE;
@@ -356,7 +356,7 @@ CL_API_ENTRY cl_int CL_API_CALL clSetCommandQueuePropertyIntelFPGA(
356356
cl_command_queue command_queue, cl_command_queue_properties properties,
357357
cl_bool enable, cl_command_queue_properties *old_properties) {
358358
cl_command_queue_properties bad_properties;
359-
acl_lock_guard lock{acl_wrapper_mutex};
359+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
360360

361361
bad_properties =
362362
~((cl_command_queue_properties)CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE |
@@ -411,7 +411,7 @@ CL_API_ENTRY cl_int CL_API_CALL
411411
clFlushIntelFPGA(cl_command_queue command_queue) {
412412
bool any_queued = false;
413413
const acl_hal_t *hal = acl_get_hal();
414-
acl_lock_guard lock{acl_wrapper_mutex};
414+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
415415

416416
if (!acl_command_queue_is_valid(command_queue)) {
417417
return CL_INVALID_COMMAND_QUEUE;
@@ -463,7 +463,7 @@ CL_API_ENTRY cl_int CL_API_CALL
463463
clFinishIntelFPGA(cl_command_queue command_queue) {
464464
cl_event event = 0;
465465
cl_int result;
466-
acl_lock_guard lock{acl_wrapper_mutex};
466+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
467467

468468
if (!acl_command_queue_is_valid(command_queue)) {
469469
return CL_INVALID_COMMAND_QUEUE;

src/acl_context.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ CL_API_ENTRY cl_context CL_API_CALL clCreateContextIntelFPGA(
8383
cl_int *errcode_ret) {
8484
cl_context context;
8585
cl_int status;
86-
acl_lock_guard lock{acl_wrapper_mutex};
86+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
8787

8888
context = l_create_context(properties, pfn_notify, user_data, &status);
8989
if (context == NULL || status != CL_SUCCESS) {
@@ -172,7 +172,7 @@ CL_API_ENTRY cl_context CL_API_CALL clCreateContextFromTypeIntelFPGA(
172172
cl_uint num_devices = 0;
173173
cl_int status;
174174
cl_device_id devices[ACL_MAX_DEVICE];
175-
acl_lock_guard lock{acl_wrapper_mutex};
175+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
176176

177177
context = l_create_context(properties, pfn_notify, user_data, &status);
178178
if (context == NULL || status != CL_SUCCESS) {
@@ -256,7 +256,7 @@ CL_API_ENTRY cl_context CL_API_CALL clCreateContextFromType(
256256

257257
ACL_EXPORT
258258
CL_API_ENTRY cl_int CL_API_CALL clRetainContextIntelFPGA(cl_context context) {
259-
acl_lock_guard lock{acl_wrapper_mutex};
259+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
260260

261261
// Note: Context creation uses acl_retain<> directly, but users must use
262262
// clRetainContext.
@@ -277,7 +277,7 @@ CL_API_ENTRY cl_int CL_API_CALL clRetainContext(cl_context context) {
277277

278278
ACL_EXPORT
279279
CL_API_ENTRY cl_int CL_API_CALL clReleaseContextIntelFPGA(cl_context context) {
280-
acl_lock_guard lock{acl_wrapper_mutex};
280+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
281281

282282
// Error out if the reference count is already 0
283283
if (!acl_context_is_valid(context)) {
@@ -371,7 +371,7 @@ CL_API_ENTRY cl_int CL_API_CALL clGetContextInfoIntelFPGA(
371371
cl_context context, cl_context_info param_name, size_t param_value_size,
372372
void *param_value, size_t *param_value_size_ret) {
373373
acl_result_t result;
374-
acl_lock_guard lock{acl_wrapper_mutex};
374+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
375375

376376
if (!acl_context_is_valid(context)) {
377377
return CL_INVALID_CONTEXT;
@@ -464,7 +464,7 @@ static cl_context l_create_context(const cl_context_properties *properties,
464464
cl_context context = 0;
465465
cl_int status;
466466

467-
acl_lock_guard lock{acl_wrapper_mutex};
467+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
468468

469469
if (user_data && !pfn_notify) {
470470
BAIL(CL_INVALID_VALUE);
@@ -520,7 +520,7 @@ static cl_context l_create_context(const cl_context_properties *properties,
520520
static cl_int l_finalize_context(cl_context context, cl_uint num_devices,
521521
const cl_device_id *devices) {
522522
cl_int status;
523-
acl_lock_guard lock{acl_wrapper_mutex};
523+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
524524

525525
status = acl_get_hal()->try_devices(num_devices, devices, &acl_platform);
526526
if (status) {

src/acl_device.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ CL_API_ENTRY cl_int CL_API_CALL clGetDeviceIDsIntelFPGA(
4141
cl_device_id *devices, cl_uint *num_devices) {
4242
cl_int status = CL_SUCCESS;
4343
cl_uint num_matched = 0;
44-
acl_lock_guard lock{acl_wrapper_mutex};
44+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
4545

4646
if (!acl_platform_is_valid(platform)) {
4747
return CL_INVALID_PLATFORM;
@@ -101,7 +101,7 @@ CL_API_ENTRY cl_int CL_API_CALL clGetDeviceInfoIntelFPGA(
101101
char name_buf[MAX_NAME_SIZE];
102102
acl_result_t result;
103103
cl_context context = 0;
104-
acl_lock_guard lock{acl_wrapper_mutex};
104+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
105105

106106
#ifndef REMOVE_VALID_CHECKS
107107
if (!acl_device_is_valid_ptr(device)) {
@@ -613,7 +613,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCreateSubDevicesIntelFPGA(
613613
// Since we don't support creating sub devices, we should follow the first
614614
// case if in_device is not valid, and the second case if it is.
615615

616-
acl_lock_guard lock{acl_wrapper_mutex};
616+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
617617
// Suppress compiler warnings.
618618
partition_properties = partition_properties;
619619
num_entries = num_entries;
@@ -638,7 +638,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCreateSubDevices(
638638

639639
ACL_EXPORT
640640
CL_API_ENTRY cl_int CL_API_CALL clRetainDeviceIntelFPGA(cl_device_id device) {
641-
acl_lock_guard lock{acl_wrapper_mutex};
641+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
642642

643643
// Spec says:
644644
// "increments the device reference count if device is a valid sub-device
@@ -676,7 +676,7 @@ CL_API_ENTRY cl_int CL_API_CALL clRetainDevice(cl_device_id device) {
676676

677677
ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL
678678
clReleaseDeviceIntelFPGA(cl_device_id device) {
679-
acl_lock_guard lock{acl_wrapper_mutex};
679+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
680680

681681
// Spec says:
682682
// "decrements the device reference count if device is a valid sub-device
@@ -712,7 +712,7 @@ clReconfigurePLLIntelFPGA(cl_device_id device, const char *pll_settings_str) {
712712
// comments specified for struct pll_setting_t in include/acl_pll.
713713
const acl_hal_t *hal;
714714
cl_int configure_status;
715-
acl_lock_guard lock{acl_wrapper_mutex};
715+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
716716

717717
if (!acl_device_is_valid(device)) {
718718
return CL_INVALID_DEVICE;
@@ -745,7 +745,7 @@ clSetDeviceExceptionCallbackIntelFPGA(
745745
acl_exception_notify_fn_t pfn_exception_notify, void *user_data) {
746746
unsigned i;
747747

748-
acl_lock_guard lock{acl_wrapper_mutex};
748+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
749749

750750
if (!pfn_exception_notify)
751751
return CL_INVALID_VALUE;

src/acl_event.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static void l_record_milestone(cl_event event, cl_profiling_info milestone);
8181

8282
ACL_EXPORT
8383
CL_API_ENTRY cl_int CL_API_CALL clRetainEventIntelFPGA(cl_event event) {
84-
acl_lock_guard lock{acl_wrapper_mutex};
84+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
8585
if (!acl_event_is_valid(event)) {
8686
return CL_INVALID_EVENT;
8787
}
@@ -96,7 +96,7 @@ CL_API_ENTRY cl_int CL_API_CALL clRetainEvent(cl_event event) {
9696

9797
ACL_EXPORT
9898
CL_API_ENTRY cl_int CL_API_CALL clReleaseEventIntelFPGA(cl_event event) {
99-
acl_lock_guard lock{acl_wrapper_mutex};
99+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
100100

101101
if (!acl_event_is_valid(event)) {
102102
return CL_INVALID_EVENT;
@@ -147,7 +147,7 @@ CL_API_ENTRY cl_int CL_API_CALL clGetEventInfoIntelFPGA(
147147
cl_event event, cl_event_info param_name, size_t param_value_size,
148148
void *param_value, size_t *param_value_size_ret) {
149149
acl_result_t result;
150-
acl_lock_guard lock{acl_wrapper_mutex};
150+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
151151

152152
if (!acl_event_is_valid(event)) {
153153
return CL_INVALID_EVENT;
@@ -226,7 +226,7 @@ CL_API_ENTRY cl_int CL_API_CALL clGetEventProfilingInfoIntelFPGA(
226226
cl_event event, cl_profiling_info param_name, size_t param_value_size,
227227
void *param_value, size_t *param_value_size_ret) {
228228
acl_result_t result;
229-
acl_lock_guard lock{acl_wrapper_mutex};
229+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
230230

231231
if (!acl_event_is_valid(event)) {
232232
return CL_INVALID_EVENT;
@@ -296,7 +296,7 @@ CL_API_ENTRY cl_event CL_API_CALL
296296
clCreateUserEventIntelFPGA(cl_context context, cl_int *errcode_ret) {
297297
cl_event result = 0;
298298
cl_int status;
299-
acl_lock_guard lock{acl_wrapper_mutex};
299+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
300300

301301
if (!acl_context_is_valid(context))
302302
BAIL(CL_INVALID_CONTEXT);
@@ -329,7 +329,7 @@ CL_API_ENTRY cl_event CL_API_CALL clCreateUserEvent(cl_context context,
329329
ACL_EXPORT
330330
CL_API_ENTRY cl_int CL_API_CALL
331331
clSetUserEventStatusIntelFPGA(cl_event event, cl_int execution_status) {
332-
acl_lock_guard lock{acl_wrapper_mutex};
332+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
333333

334334
if (!acl_event_is_valid(event)) {
335335
return CL_INVALID_EVENT;
@@ -369,7 +369,7 @@ CL_API_ENTRY cl_int clSetEventCallbackIntelFPGA(
369369
void *user_data),
370370
void *user_data) {
371371
acl_event_user_callback *cb;
372-
acl_lock_guard lock{acl_wrapper_mutex};
372+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
373373

374374
if (!acl_event_is_valid(event)) {
375375
return CL_INVALID_EVENT;

src/acl_hal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int acl_print_debug_msg(const char *msg, ...) {
132132
extern CL_API_ENTRY void CL_API_CALL
133133
clSetBoardLibraryIntelFPGA(char *library_name) {
134134
acl_mmd_library_names_t *next_library = NULL;
135-
acl_lock_guard lock{acl_wrapper_mutex};
135+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
136136

137137
acl_print_debug_msg("Adding library '%s' to list of libraries to open\n",
138138
library_name);

src/acl_hostch.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ CL_API_ENTRY cl_int CL_API_CALL clReadPipeIntelFPGA(cl_mem pipe, void *ptr) {
244244
cl_int status = 0;
245245

246246
{
247-
acl_lock_guard lock{acl_wrapper_mutex};
247+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
248248
acl_idle_update(pipe->context);
249249
}
250250

@@ -345,7 +345,7 @@ CL_API_ENTRY cl_int CL_API_CALL clWritePipeIntelFPGA(cl_mem pipe, void *ptr) {
345345
cl_int ret;
346346

347347
{
348-
acl_lock_guard lock{acl_wrapper_mutex};
348+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
349349
acl_idle_update(pipe->context);
350350
}
351351

@@ -461,7 +461,7 @@ CL_API_ENTRY void *CL_API_CALL clMapHostPipeIntelFPGA(cl_mem pipe,
461461
int status = 0;
462462

463463
{
464-
acl_lock_guard lock{acl_wrapper_mutex};
464+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
465465
acl_idle_update(pipe->context);
466466
}
467467

@@ -591,7 +591,7 @@ clUnmapHostPipeIntelFPGA(cl_mem pipe, void *mapped_ptr, size_t size_to_unmap,
591591
int first = 1;
592592

593593
{
594-
acl_lock_guard lock{acl_wrapper_mutex};
594+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
595595
acl_idle_update(pipe->context);
596596
}
597597

src/acl_icd_dispatch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ clGetExtensionFunctionAddressIntelFPGA(const char *func_name) {
7878
ACL_EXPORT
7979
CL_API_ENTRY void *CL_API_CALL clGetBoardExtensionFunctionAddressIntelFPGA(
8080
const char *func_name, cl_device_id device) {
81-
acl_lock_guard lock{acl_wrapper_mutex};
81+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
8282
{
8383
void *ret = acl_get_hal()->get_board_extension_function_address(
8484
func_name, device->def.physical_device_id);
@@ -97,7 +97,7 @@ CL_API_ENTRY void *CL_API_CALL
9797
clGetExtensionFunctionAddressForPlatformIntelFPGA(cl_platform_id platform,
9898
const char *func_name) {
9999
// We currently only have one platform
100-
acl_lock_guard lock{acl_wrapper_mutex};
100+
std::scoped_lock<acl_mutex_wrapper_t> lock{acl_wrapper_mutex};
101101
if (!acl_platform_is_valid(platform)) {
102102
return NULL;
103103
}

0 commit comments

Comments
 (0)