Skip to content

Commit b4c5e1c

Browse files
committed
Made changes to fix move semantics related errors when using newer clang compiler
Fixed deprecated gtest macro warnings Signed-off-by: Salman Faruqi <[email protected]>
1 parent 067e040 commit b4c5e1c

17 files changed

+196
-126
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,4 @@ if (QUANTUM_VERBOSE_MAKEFILE)
166166
message(STATUS "REQUIRED BOOST_VERSION = 1.61")
167167
message(STATUS "GTEST_ROOT = ${GTEST_ROOT}")
168168
endif()
169+

quantum/impl/quantum_coroutine_pool_allocator_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void CoroutinePoolAllocator<STACK_TRAITS>::deallocate(const boost::context::stac
219219
{
220220
SpinLock::Guard lock(_spinlock);
221221
--_numHeapAllocatedBlocks;
222-
assert(_numHeapAllocatedBlocks >= 0);
222+
assert(_numHeapAllocatedBlocks != (size_t)-1);
223223
}
224224
if (deallocateCoroutine(stackEnd(ctx)) != 0)
225225
{

quantum/impl/quantum_io_queue_impl.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ IoQueue::IoQueue(const IoQueue& other) :
7070
}
7171
}
7272

73+
inline
74+
IoQueue::IoQueue(IoQueue&& other) noexcept:
75+
_sharedIoQueues(other._sharedIoQueues),
76+
_loadBalanceSharedIoQueues(other._loadBalanceSharedIoQueues),
77+
_loadBalancePollIntervalMs(other._loadBalancePollIntervalMs),
78+
_loadBalancePollIntervalBackoffPolicy(other._loadBalancePollIntervalBackoffPolicy),
79+
_loadBalancePollIntervalNumBackoffs(other._loadBalancePollIntervalNumBackoffs),
80+
_loadBalanceBackoffNum(other._loadBalanceBackoffNum),
81+
_thread(std::move(other._thread)),
82+
_queue(std::move(other._queue)),
83+
_isEmpty(other._isEmpty.load()),
84+
_isInterrupted(other._isInterrupted.load()),
85+
_isIdle(other._isIdle.load()),
86+
_terminated(other._terminated.load())
87+
{
88+
}
89+
7390
inline
7491
IoQueue::~IoQueue()
7592
{

quantum/impl/quantum_io_task_impl.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ IoTask::IoTask(std::false_type,
6363
{
6464
}
6565

66+
inline
67+
IoTask::IoTask(IoTask&& other) noexcept :
68+
_func(std::move(other._func)),
69+
_terminated(other._terminated.load()),
70+
_queueId(other._queueId),
71+
_isHighPriority(other._isHighPriority),
72+
_taskId(ThreadContextTag{})
73+
{
74+
}
75+
76+
inline
77+
IoTask& IoTask::operator=(IoTask&& other) noexcept
78+
{
79+
if (this != &other) {
80+
_func = std::move(other._func);
81+
_terminated.store(other._terminated.load());
82+
_queueId = other._queueId;
83+
_isHighPriority = other._isHighPriority;
84+
_taskId = other._taskId;
85+
_localStorage = std::move(other._localStorage);
86+
}
87+
return *this;
88+
}
89+
6690
inline
6791
IoTask::~IoTask()
6892
{

quantum/impl/quantum_task_impl.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,38 @@ Task::Task(std::true_type,
7272
_suspendedState((int)State::Suspended)
7373
{}
7474

75+
inline
76+
Task::Task(Task&& other) noexcept :
77+
_coroContext(std::move(other._coroContext)),
78+
_coro(std::move(other._coro)),
79+
_isHighPriority(other._isHighPriority),
80+
_next(std::move(other._next)),
81+
_prev(std::move(other._prev)),
82+
_type(other._type),
83+
_taskId(other._taskId),
84+
_terminated(other._terminated.load()),
85+
_suspendedState(other._suspendedState.load()),
86+
_localStorage(std::move(other._localStorage))
87+
{}
88+
89+
inline
90+
Task& Task::operator=(Task&& other) noexcept
91+
{
92+
if (this != &other) {
93+
_coroContext = std::move(other._coroContext);
94+
_coro = std::move(other._coro);
95+
_isHighPriority = other._isHighPriority;
96+
_next = std::move(other._next);
97+
_prev = std::move(other._prev);
98+
_type = other._type;
99+
_taskId = other._taskId;
100+
_terminated.store(other._terminated.load());
101+
_suspendedState.store(other._suspendedState.load());
102+
_localStorage = std::move(other._localStorage);
103+
}
104+
return *this;
105+
}
106+
75107
inline
76108
Task::~Task()
77109
{

quantum/impl/quantum_task_queue_impl.h

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ namespace Bloomberg {
2525
namespace quantum {
2626

2727
inline
28-
TaskQueue::WorkItem::WorkItem(TaskPtr task,
28+
TaskQueue::WorkItem::WorkItem(ITaskPtr task,
2929
TaskListIter iter,
3030
bool isBlocked,
3131
unsigned int blockedQueueRound) :
32-
_task(task),
32+
_task(std::move(task)),
3333
_iter(iter),
3434
_isBlocked(isBlocked),
3535
_blockedQueueRound(blockedQueueRound)
@@ -52,9 +52,8 @@ TaskQueue::TaskQueue() :
5252

5353
inline
5454
TaskQueue::TaskQueue(const Configuration&, std::shared_ptr<TaskQueue> sharedQueue) :
55-
_alloc(Allocator<QueueListAllocator>::instance(AllocatorTraits::queueListAllocSize())),
56-
_runQueue(_alloc),
57-
_waitQueue(_alloc),
55+
_runQueue(Allocator<QueueListAllocator>::instance(AllocatorTraits::queueListAllocSize())),
56+
_waitQueue(Allocator<QueueListAllocator>::instance(AllocatorTraits::queueListAllocSize())),
5857
_queueIt(_runQueue.end()),
5958
_blockedIt(_runQueue.end()),
6059
_isBlocked(false),
@@ -64,7 +63,7 @@ TaskQueue::TaskQueue(const Configuration&, std::shared_ptr<TaskQueue> sharedQueu
6463
_isIdle(true),
6564
_terminated(false),
6665
_isAdvanced(false),
67-
_sharedQueue(sharedQueue),
66+
_sharedQueue(std::move(sharedQueue)),
6867
_queueRound(0),
6968
_lastSleptQueueRound(std::numeric_limits<unsigned int>::max()),
7069
_lastSleptSharedQueueRound(std::numeric_limits<unsigned int>::max())
@@ -80,7 +79,29 @@ inline
8079
TaskQueue::TaskQueue(const TaskQueue&) :
8180
TaskQueue()
8281
{
82+
}
8383

84+
inline
85+
TaskQueue::TaskQueue(TaskQueue&& other) noexcept:
86+
_thread(std::move(other._thread)),
87+
_runQueue(std::move(other._runQueue)),
88+
_waitQueue(std::move(other._waitQueue)),
89+
_queueIt(other._queueIt),
90+
_blockedIt(_runQueue.end()),
91+
_isBlocked(other._isBlocked),
92+
_isEmpty(other._isEmpty.load()),
93+
_isSharedQueueEmpty(other._isSharedQueueEmpty.load()),
94+
_isInterrupted(other._isInterrupted.load()),
95+
_isIdle(other._isIdle.load()),
96+
_terminated(other._terminated.load()),
97+
_isAdvanced(other._isAdvanced),
98+
_stats(other._stats),
99+
_sharedQueue(std::move(other._sharedQueue)),
100+
_helpers(other._helpers),
101+
_queueRound(other._queueRound),
102+
_lastSleptQueueRound(other._lastSleptQueueRound),
103+
_lastSleptSharedQueueRound(other._lastSleptSharedQueueRound)
104+
{
84105
}
85106

86107
inline
@@ -183,10 +204,10 @@ TaskQueue::ProcessTaskResult TaskQueue::processTask()
183204
//Process a task
184205
workItem = grabWorkItem();
185206

186-
TaskPtr task = workItem._task;
207+
ITaskPtr task = workItem._task;
187208
if (!task)
188209
{
189-
return ProcessTaskResult(workItem._isBlocked, workItem._blockedQueueRound);
210+
return { workItem._isBlocked, workItem._blockedQueueRound };
190211
}
191212

192213
int rc;
@@ -231,7 +252,7 @@ TaskQueue::ProcessTaskResult TaskQueue::processTask()
231252
{
232253
handleException(workItem);
233254
}
234-
return ProcessTaskResult(workItem._isBlocked, workItem._blockedQueueRound);
255+
return {workItem._isBlocked, workItem._blockedQueueRound};
235256
}
236257

237258
inline
@@ -453,7 +474,7 @@ bool TaskQueue::handleSuccess(const WorkItem& workItem)
453474
{
454475
ITaskContinuation::Ptr nextTask;
455476
//check if there's another task scheduled to run after this one
456-
nextTask = workItem._task->getNextTask();
477+
nextTask = std::static_pointer_cast<Task>(workItem._task)->getNextTask();
457478
if (nextTask && (nextTask->getType() == ITask::Type::ErrorHandler))
458479
{
459480
//skip error handler since we don't have any errors
@@ -473,7 +494,7 @@ bool TaskQueue::handleError(const WorkItem& workItem)
473494
{
474495
ITaskContinuation::Ptr nextTask;
475496
//Check if we have a final task to run
476-
nextTask = workItem._task->getErrorHandlerOrFinalTask();
497+
nextTask = std::static_pointer_cast<Task>(workItem._task)->getErrorHandlerOrFinalTask();
477498
//queue next task and de-queue current one
478499
enqueue(nextTask);
479500
doDequeue(_isIdle, workItem._iter);
@@ -537,9 +558,9 @@ TaskQueue::grabWorkItem()
537558
_isIdle = _runQueue.empty();
538559
if (_runQueue.empty())
539560
{
540-
return WorkItem(nullptr, _runQueue.end(), _isBlocked, _queueRound);
561+
return {nullptr, _runQueue.end(), _isBlocked, _queueRound};
541562
}
542-
return WorkItem((*_queueIt), _queueIt, false, 0);
563+
return {(*_queueIt), _queueIt, false, 0};
543564
}
544565

545566
inline

quantum/interface/quantum_itask.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ struct ITask : public ITerminate
5353
Sleeping = (int)Running-5, ///< Coroutine is sleeping
5454
Max = (int)Running-10, ///< Value of the max reserved return code
5555
};
56-
57-
~ITask() = default;
56+
57+
~ITask() override = default;
5858

5959
virtual int run() = 0;
6060

quantum/quantum_io_queue.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ namespace quantum {
4040
class IoQueue : public IQueue
4141
{
4242
public:
43-
using TaskList = std::list<IoTask::Ptr, IoQueueListAllocator>;
43+
using TaskList = std::list<ITask::Ptr, IoQueueListAllocator>;
4444
using TaskListIter = TaskList::iterator;
4545

4646
IoQueue();
4747

4848
IoQueue(const Configuration& config,
4949
std::vector<IoQueue>* sharedIoQueues);
5050

51-
IoQueue(const IoQueue& other);
51+
IoQueue(const IoQueue&);
5252

53-
IoQueue(IoQueue&& other) = default;
53+
IoQueue(IoQueue&& other) noexcept;
5454

55-
~IoQueue();
55+
~IoQueue() override;
5656

5757
void terminate() final;
5858

quantum/quantum_io_task.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ class IoTask : public ITask
5252
bool isHighPriority,
5353
FUNC&& func,
5454
ARGS&&... args);
55+
56+
IoTask(const IoTask&) = delete;
57+
IoTask(IoTask&& other) noexcept;
58+
IoTask& operator=(const IoTask&) = delete;
59+
IoTask& operator=(IoTask&& other) noexcept;
5560

56-
IoTask(const IoTask& task) = delete;
57-
IoTask(IoTask&& task) = default;
58-
IoTask& operator=(const IoTask& task) = delete;
59-
IoTask& operator=(IoTask&& task) = default;
60-
61-
~IoTask();
61+
~IoTask() override;
6262

6363
//ITerminate
6464
void terminate() final;
@@ -70,7 +70,7 @@ class IoTask : public ITask
7070
Type getType() const final;
7171
TaskId getTaskId() const final;
7272
bool isBlocked() const final;
73-
bool isSleeping(bool updateTimer = false) final;
73+
bool isSleeping(bool updateTimer) final;
7474
bool isHighPriority() const final;
7575
bool isSuspended() const final;
7676
ITask::LocalStorage& getLocalStorage() final;

quantum/quantum_read_write_mutex.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,8 @@ class ReadWriteMutex
3131

3232
/// @brief Copy constructor
3333
ReadWriteMutex(const ReadWriteMutex&) = delete;
34-
35-
/// @brief Move constructor
36-
ReadWriteMutex(ReadWriteMutex&&) = default;
37-
38-
/// @brief Copy assignment operator
3934
ReadWriteMutex& operator=(const ReadWriteMutex&) = delete;
4035

41-
/// @brief Move assignment operator
42-
ReadWriteMutex& operator=(ReadWriteMutex&&) = default;
43-
4436
/// @brief Lock this object as a reader (shared with other readers)
4537
/// @details The current context will be yielded until the lock is acquired.
4638
/// @note From a non-coroutine context, call the first. From a coroutine context,

0 commit comments

Comments
 (0)