Skip to content

Commit 71e9048

Browse files
Fix comments
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
1 parent 06e2608 commit 71e9048

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

sycl/source/detail/global_handler.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ namespace detail {
3333
// Origin idea is to track usage of Scheduler from main and other used threads -
3434
// they increment MCounter; and to use but not add extra reference by our
3535
// thread_pool threads. For this control MIncrementCounter class member is used.
36-
// MObj and MReleaseCalled is extra protection needed to handle case when main
37-
// thread finished but thread_pool is still running and we will join that
38-
// threads in releaseResources call.
3936
template <class ResourceHandler> class ObjectUsageCounter {
4037
public:
4138
ObjectUsageCounter(std::unique_ptr<ResourceHandler> &Obj, bool ModifyCounter)
@@ -81,7 +78,7 @@ T &GlobalHandler::getOrCreate(InstWithLock<T> &IWL, Types... Args) {
8178
}
8279

8380
void GlobalHandler::attachScheduler(Scheduler *Scheduler) {
84-
// The method is for testing purposes. Do not protect with lock since
81+
// The method is used in unit tests only. Do not protect with lock since
8582
// releaseResources will cause dead lock due to host queue release
8683
if (MScheduler.Inst)
8784
MScheduler.Inst->releaseResources();

sycl/source/detail/scheduler/scheduler.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,13 @@ class Scheduler {
450450
const QueueImplPtr &getDefaultHostQueue() const { return DefaultHostQueue; }
451451

452452
static MemObjRecord *getMemObjRecord(const Requirement *const Req);
453-
// Virtual for testing purposes only
453+
454454
void deferMemObjRelease(const std::shared_ptr<detail::SYCLMemObjI> &MemObj);
455455

456456
Scheduler();
457457
~Scheduler();
458458
void releaseResources();
459-
inline bool isDeferredMemObjectsEmpty();
459+
bool isDeferredMemObjectsEmpty();
460460

461461
protected:
462462
using RWLockT = std::shared_timed_mutex;

sycl/source/detail/sycl_mem_obj_t.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ void SYCLMemObjT::updateHostMemory() {
9090

9191
// If we're attached to a memory record, process the deletion of the memory
9292
// record. We may get detached before we do this.
93-
if (MRecord)
94-
assert(Scheduler::getInstance().removeMemoryObject(this));
93+
if (MRecord) {
94+
bool Result = Scheduler::getInstance().removeMemoryObject(this);
95+
assert(
96+
Result &&
97+
"removeMemoryObject should not return false in mem object destructor");
98+
}
9599
releaseHostMem(MShadowCopy);
96100

97101
if (MOpenCLInterop) {

sycl/source/detail/thread_pool.hpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ class ThreadPool {
3030
std::mutex MJobQueueMutex;
3131
std::condition_variable MDoSmthOrStop;
3232
std::atomic_bool MStop;
33-
std::atomic_uint MJobsInExecution;
33+
std::atomic_uint MJobsInPool;
3434

3535
void worker() {
3636
GlobalHandler::instance().registerSchedulerUsage(/*ModifyCounter*/ false);
3737
std::unique_lock<std::mutex> Lock(MJobQueueMutex);
38-
std::thread::id ThisThreadId = std::this_thread::get_id();
3938
while (true) {
40-
MDoSmthOrStop.wait(Lock, [this, &ThisThreadId]() {
41-
return !MJobQueue.empty() || MStop.load();
42-
});
39+
MDoSmthOrStop.wait(
40+
Lock, [this]() { return !MJobQueue.empty() || MStop.load(); });
4341

4442
if (MStop.load())
4543
break;
@@ -52,23 +50,23 @@ class ThreadPool {
5250

5351
Lock.lock();
5452

55-
MJobsInExecution--;
53+
MJobsInPool--;
5654
}
5755
}
5856

5957
void start() {
6058
MLaunchedThreads.reserve(MThreadCount);
6159

6260
MStop.store(false);
63-
MJobsInExecution.store(0);
61+
MJobsInPool.store(0);
6462

6563
for (size_t Idx = 0; Idx < MThreadCount; ++Idx)
6664
MLaunchedThreads.emplace_back([this] { worker(); });
6765
}
6866

6967
public:
7068
void drain() {
71-
while (MJobsInExecution != 0)
69+
while (MJobsInPool != 0)
7270
std::this_thread::yield();
7371
}
7472

@@ -93,7 +91,7 @@ class ThreadPool {
9391
std::lock_guard<std::mutex> Lock(MJobQueueMutex);
9492
MJobQueue.emplace([F = std::move(Func)]() { F(); });
9593
}
96-
MJobsInExecution++;
94+
MJobsInPool++;
9795
MDoSmthOrStop.notify_one();
9896
}
9997

@@ -102,7 +100,7 @@ class ThreadPool {
102100
std::lock_guard<std::mutex> Lock(MJobQueueMutex);
103101
MJobQueue.emplace(Func);
104102
}
105-
MJobsInExecution++;
103+
MJobsInPool++;
106104
MDoSmthOrStop.notify_one();
107105
}
108106
};

0 commit comments

Comments
 (0)