Skip to content

Commit 645f381

Browse files
committed
Finished more changes
1 parent f7f479a commit 645f381

10 files changed

+57
-59
lines changed

include/acl_thread.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ static inline void acl_sig_unblock_signals() {
8484

8585
// -- global lock functions --
8686

87-
void acl_lock();
88-
void acl_unlock();
89-
int acl_suspend_lock();
90-
void acl_resume_lock(int lock_count);
9187
void acl_wait_for_device_update(cl_context context);
9288
void acl_signal_device_update();
9389

@@ -124,17 +120,19 @@ void acl_yield_lock_and_thread();
124120
// This meets the BasicLockable requirement for std::lock_guard.
125121
class acl_mutex_wrapper_t {
126122
public:
127-
void lock() { acl_lock(); }
128-
void unlock() { acl_unlock(); }
123+
void lock();
124+
void unlock();
125+
int suspend_lock();
126+
void resume_lock(int lock_count);
129127
};
130128

131129
// RAII class warpper for acl specific functionality acl_suspend_lock()
132130
class acl_suspend_lock_guard {
133131
public:
134132
explicit acl_suspend_lock_guard(acl_mutex_wrapper_t &mtex) : mtex(mtex) {
135-
lock_count = acl_suspend_lock();
133+
lock_count = mtex.suspend_lock();
136134
};
137-
~acl_suspend_lock_guard() { acl_resume_lock(lock_count); }
135+
~acl_suspend_lock_guard() { mtex.resume_lock(lock_count); }
138136

139137
private:
140138
int lock_count;

src/acl_thread.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,54 +20,54 @@ static struct acl_condvar_s l_acl_global_condvar;
2020
// l_init_once() is defined in an OS-specific section below
2121
static void l_init_once();
2222

23-
void acl_lock() {
23+
int acl_is_locked_callback(void) { return (acl_global_lock_count > 0); }
24+
25+
void acl_wait_for_device_update(cl_context context) {
26+
acl_assert_locked();
27+
if (acl_get_hal()->get_debug_verbosity &&
28+
acl_get_hal()->get_debug_verbosity() > 0) {
29+
unsigned timeout = 5; // Seconds
30+
// Keep waiting until signal is received
31+
while (acl_timed_wait_condvar(&l_acl_global_condvar, timeout))
32+
acl_context_print_hung_device_status(context);
33+
} else {
34+
acl_wait_condvar(&l_acl_global_condvar);
35+
}
36+
}
37+
38+
void acl_signal_device_update() { acl_signal_condvar(&l_acl_global_condvar); }
39+
40+
void acl_mutex_wrapper_t::lock() {
2441
l_init_once();
2542
if (acl_global_lock_count == 0) {
2643
acl_acquire_condvar(&l_acl_global_condvar);
2744
}
2845
acl_global_lock_count++;
2946
}
3047

31-
void acl_unlock() {
48+
void acl_mutex_wrapper_t::unlock() {
3249
acl_assert_locked();
3350
acl_global_lock_count--;
3451
if (acl_global_lock_count == 0) {
3552
acl_release_condvar(&l_acl_global_condvar);
3653
}
3754
}
3855

39-
int acl_is_locked_callback(void) { return (acl_global_lock_count > 0); }
40-
41-
int acl_suspend_lock() {
56+
int acl_mutex_wrapper_t::suspend_lock() {
4257
int old_lock_count = acl_global_lock_count;
4358
acl_global_lock_count = 0;
4459
if (old_lock_count > 0)
4560
acl_release_condvar(&l_acl_global_condvar);
4661
return old_lock_count;
4762
}
4863

49-
void acl_resume_lock(int lock_count) {
64+
void acl_mutex_wrapper_t::resume_lock(int lock_count) {
5065
acl_assert_unlocked();
5166
if (lock_count > 0)
5267
acl_acquire_condvar(&l_acl_global_condvar);
5368
acl_global_lock_count = lock_count;
5469
}
5570

56-
void acl_wait_for_device_update(cl_context context) {
57-
acl_assert_locked();
58-
if (acl_get_hal()->get_debug_verbosity &&
59-
acl_get_hal()->get_debug_verbosity() > 0) {
60-
unsigned timeout = 5; // Seconds
61-
// Keep waiting until signal is received
62-
while (acl_timed_wait_condvar(&l_acl_global_condvar, timeout))
63-
acl_context_print_hung_device_status(context);
64-
} else {
65-
acl_wait_condvar(&l_acl_global_condvar);
66-
}
67-
}
68-
69-
void acl_signal_device_update() { acl_signal_condvar(&l_acl_global_condvar); }
70-
7171
#ifdef __linux__
7272

7373
#include <linux/unistd.h>

test/acl_device_op_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static struct _cl_event myevents[EVENT_NUM] = {{0}};
133133

134134
TEST_GROUP(device_op) {
135135
virtual void setup() {
136-
acl_lock();
136+
acl_mutex_wrapper.lock();
137137
acl_test_setup_generic_system();
138138
acl_init_device_op_queue(&m_doq);
139139
clear_queue_callbacks(&m_doq);
@@ -152,7 +152,7 @@ TEST_GROUP(device_op) {
152152
virtual void teardown() {
153153
unload();
154154
acl_test_teardown_generic_system();
155-
acl_unlock();
155+
acl_mutex_wrapper.unlock();
156156
acl_test_run_standard_teardown_checks();
157157
}
158158

test/acl_event_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ MT_TEST(acl_event, acl_create_event) {
292292

293293
// Bad command queue
294294
struct _cl_command_queue fake_cq = {0};
295-
acl_lock();
295+
acl_mutex_wrapper.lock();
296296
CHECK_EQUAL(CL_INVALID_COMMAND_QUEUE,
297297
acl_create_event(0, 0, 0, CL_COMMAND_MARKER, &user_event));
298298
CHECK_EQUAL(CL_INVALID_COMMAND_QUEUE,
@@ -338,7 +338,7 @@ MT_TEST(acl_event, acl_create_event) {
338338
CHECK(cq0);
339339
acl_update_queue(cq0);
340340

341-
acl_unlock();
341+
acl_mutex_wrapper.unlock();
342342

343343
// Check the callback functions initialization.
344344
CHECK_EQUAL(NULL, event[0]->callback_list);
@@ -614,7 +614,7 @@ MT_TEST(acl_event, event_liveness) {
614614
CHECK_EQUAL(CL_SUCCESS, status);
615615
CHECK(cq0);
616616

617-
acl_lock();
617+
acl_mutex_wrapper.lock();
618618
cl_event event;
619619
status = acl_create_event(cq0, 0, 0, CL_COMMAND_MARKER, &event);
620620
CHECK_EQUAL(CL_SUCCESS, status);
@@ -659,7 +659,7 @@ MT_TEST(acl_event, event_liveness) {
659659
acl_set_execution_status(event, CL_QUEUED);
660660
CHECK(acl_event_is_live(event));
661661
acl_retain(event);
662-
acl_unlock();
662+
acl_mutex_wrapper.unlock();
663663

664664
this->kill_event(event);
665665

@@ -690,7 +690,7 @@ MT_TEST(acl_event, event_callbacks) {
690690
CHECK_EQUAL(CL_SUCCESS, status);
691691
CHECK(cq0);
692692

693-
acl_lock();
693+
acl_mutex_wrapper.lock();
694694
cl_event event, event2, event3;
695695
status = acl_create_event(cq0, 0, 0, CL_COMMAND_MARKER, &event);
696696
CHECK_EQUAL(CL_SUCCESS, status);
@@ -807,7 +807,7 @@ MT_TEST(acl_event, event_callbacks) {
807807
CHECK_EQUAL(1, call_flags_event3[i]);
808808
}
809809
clReleaseEvent(user_event);
810-
acl_unlock();
810+
acl_mutex_wrapper.unlock();
811811

812812
this->kill_event(event);
813813
this->kill_event(event2);

test/acl_globals_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,12 @@ const acl_system_def_t *acl_test_get_empty_system_def() {
693693
return &acltest_empty_system;
694694
}
695695

696-
TEST_GROUP(acl_globals_undef){void setup(){acl_lock();
696+
TEST_GROUP(acl_globals_undef){void setup(){acl_mutex_wrapper.lock();
697697
acl_set_hal(acl_test_get_simple_hal());
698698
}
699699
void teardown() {
700700
acl_reset_hal();
701-
acl_unlock();
701+
acl_mutex_wrapper.unlock();
702702
acl_test_run_standard_teardown_checks();
703703
}
704704

test/acl_hal_mmd_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
#include <stdio.h>
2020
#include <string.h>
2121

22-
TEST_GROUP(acl_hal_mmd){void setup(){acl_lock();
22+
TEST_GROUP(acl_hal_mmd){void setup(){acl_mutex_wrapper.lock();
2323
acl_hal_test_setup_generic_system();
2424
this->load();
2525
}
2626
void teardown() {
2727
this->unload();
2828
acl_hal_test_teardown_generic_system();
29-
acl_unlock();
29+
acl_mutex_wrapper.unlock();
3030
acl_test_run_standard_teardown_checks();
3131
}
3232

test/acl_hal_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ bool acltest_hal_emulate_device_mem = false;
162162
static void *acltest_hal_device_mem = 0;
163163
static size_t acltest_hal_device_mem_size = 0;
164164

165-
TEST_GROUP(acl_hal){void setup(){acl_lock();
165+
TEST_GROUP(acl_hal){void setup(){acl_mutex_wrapper.lock();
166166
}
167167
void teardown() {
168-
acl_unlock();
168+
acl_mutex_wrapper.unlock();
169169
acl_assert_unlocked();
170170
}
171171
}

test/acl_support_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
#include <glob.h>
2424
#endif
2525

26-
TEST_GROUP(support){void setup(){acl_lock();
26+
TEST_GROUP(support){void setup(){acl_mutex_wrapper.lock();
2727
acl_test_setup_generic_system();
2828
}
2929
void teardown() {
3030
acl_test_teardown_generic_system();
31-
acl_unlock();
31+
acl_mutex_wrapper.unlock();
3232
acl_test_run_standard_teardown_checks();
3333
}
3434

test/acl_test.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,24 @@ int main(int argc, const char **argv) {
9191
}
9292

9393
void acl_test_setup_generic_system() {
94-
acl_lock();
94+
acl_mutex_wrapper.lock();
9595
acl_set_hal(acl_test_get_simple_hal());
9696
acl_init(acl_test_get_complex_system_def());
97-
acl_unlock();
97+
acl_mutex_wrapper.unlock();
9898
}
9999

100100
void acl_test_setup_empty_system() {
101-
acl_lock();
101+
acl_mutex_wrapper.lock();
102102
acl_set_hal(acl_test_get_simple_hal());
103103
acl_init(acl_test_get_empty_system_def());
104-
acl_unlock();
104+
acl_mutex_wrapper.unlock();
105105
}
106106

107107
void acl_test_setup_sample_default_board_system(void) {
108-
acl_lock();
108+
acl_mutex_wrapper.lock();
109109
acl_set_hal(acl_test_get_simple_hal());
110110
acl_init(&acl_test_example_binary_sysdef);
111-
acl_unlock();
111+
acl_mutex_wrapper.unlock();
112112
}
113113

114114
void acl_test_teardown_sample_default_board_system(void) {
@@ -117,11 +117,11 @@ void acl_test_teardown_sample_default_board_system(void) {
117117

118118
void acl_test_teardown_generic_system(void) { acl_test_teardown_system(); }
119119
void acl_test_teardown_system(void) {
120-
acl_lock();
120+
acl_mutex_wrapper.lock();
121121
acl_reset();
122122
acl_reset_hal();
123123
acltest_hal_teardown();
124-
acl_unlock();
124+
acl_mutex_wrapper.unlock();
125125
}
126126

127127
void acl_hal_test_setup_generic_system(void) { return; };
@@ -482,20 +482,20 @@ static void l_run_benchmark() {
482482
times = &results["acl_lock/acl_unlock"];
483483
for (int inner_rep = 0; inner_rep < INNER_REPS; ++inner_rep) {
484484
start_time = l_get_timestamp();
485-
acl_lock();
486-
acl_unlock();
485+
acl_mutex_wrapper.lock();
486+
acl_mutex_wrapper.unlock();
487487
end_time = l_get_timestamp();
488488
times->push_back(end_time - start_time);
489489
}
490490

491491
std::cout << "Measuring acl_assert_locked..." << std::endl;
492492
times = &results["acl_assert_locked"];
493493
for (int inner_rep = 0; inner_rep < INNER_REPS; ++inner_rep) {
494-
acl_lock();
494+
acl_mutex_wrapper.lock();
495495
start_time = l_get_timestamp();
496496
acl_assert_locked();
497497
end_time = l_get_timestamp();
498-
acl_unlock();
498+
acl_mutex_wrapper.unlock();
499499
times->push_back(end_time - start_time);
500500
}
501501

test/acl_test.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ void CL_CALLBACK acl_test_notify_print(const char *errinfo,
5555

5656
#define ACL_LOCKED(...) \
5757
do { \
58-
acl_lock(); \
58+
acl_mutex_wrapper.lock(); \
5959
{ __VA_ARGS__; } \
60-
acl_unlock(); \
60+
acl_mutex_wrapper.unlock(); \
6161
} while (0)
6262

6363
/* CAUTION. These are only used in self-tests.

0 commit comments

Comments
 (0)