Skip to content

Commit

Permalink
Made changes to fix move semantics related errors when using newer cl…
Browse files Browse the repository at this point in the history
…ang compiler

Fixed deprecated gtest macro warnings

Signed-off-by: Salman Faruqi <[email protected]>
  • Loading branch information
safaruqi committed Oct 8, 2021
1 parent 067e040 commit b4c5e1c
Show file tree
Hide file tree
Showing 17 changed files with 196 additions and 126 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,4 @@ if (QUANTUM_VERBOSE_MAKEFILE)
message(STATUS "REQUIRED BOOST_VERSION = 1.61")
message(STATUS "GTEST_ROOT = ${GTEST_ROOT}")
endif()

2 changes: 1 addition & 1 deletion quantum/impl/quantum_coroutine_pool_allocator_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void CoroutinePoolAllocator<STACK_TRAITS>::deallocate(const boost::context::stac
{
SpinLock::Guard lock(_spinlock);
--_numHeapAllocatedBlocks;
assert(_numHeapAllocatedBlocks >= 0);
assert(_numHeapAllocatedBlocks != (size_t)-1);
}
if (deallocateCoroutine(stackEnd(ctx)) != 0)
{
Expand Down
17 changes: 17 additions & 0 deletions quantum/impl/quantum_io_queue_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ IoQueue::IoQueue(const IoQueue& other) :
}
}

inline
IoQueue::IoQueue(IoQueue&& other) noexcept:
_sharedIoQueues(other._sharedIoQueues),
_loadBalanceSharedIoQueues(other._loadBalanceSharedIoQueues),
_loadBalancePollIntervalMs(other._loadBalancePollIntervalMs),
_loadBalancePollIntervalBackoffPolicy(other._loadBalancePollIntervalBackoffPolicy),
_loadBalancePollIntervalNumBackoffs(other._loadBalancePollIntervalNumBackoffs),
_loadBalanceBackoffNum(other._loadBalanceBackoffNum),
_thread(std::move(other._thread)),
_queue(std::move(other._queue)),
_isEmpty(other._isEmpty.load()),
_isInterrupted(other._isInterrupted.load()),
_isIdle(other._isIdle.load()),
_terminated(other._terminated.load())
{
}

inline
IoQueue::~IoQueue()
{
Expand Down
24 changes: 24 additions & 0 deletions quantum/impl/quantum_io_task_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ IoTask::IoTask(std::false_type,
{
}

inline
IoTask::IoTask(IoTask&& other) noexcept :
_func(std::move(other._func)),
_terminated(other._terminated.load()),
_queueId(other._queueId),
_isHighPriority(other._isHighPriority),
_taskId(ThreadContextTag{})
{
}

inline
IoTask& IoTask::operator=(IoTask&& other) noexcept
{
if (this != &other) {
_func = std::move(other._func);
_terminated.store(other._terminated.load());
_queueId = other._queueId;
_isHighPriority = other._isHighPriority;
_taskId = other._taskId;
_localStorage = std::move(other._localStorage);
}
return *this;
}

inline
IoTask::~IoTask()
{
Expand Down
32 changes: 32 additions & 0 deletions quantum/impl/quantum_task_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,38 @@ Task::Task(std::true_type,
_suspendedState((int)State::Suspended)
{}

inline
Task::Task(Task&& other) noexcept :
_coroContext(std::move(other._coroContext)),
_coro(std::move(other._coro)),
_isHighPriority(other._isHighPriority),
_next(std::move(other._next)),
_prev(std::move(other._prev)),
_type(other._type),
_taskId(other._taskId),
_terminated(other._terminated.load()),
_suspendedState(other._suspendedState.load()),
_localStorage(std::move(other._localStorage))
{}

inline
Task& Task::operator=(Task&& other) noexcept
{
if (this != &other) {
_coroContext = std::move(other._coroContext);
_coro = std::move(other._coro);
_isHighPriority = other._isHighPriority;
_next = std::move(other._next);
_prev = std::move(other._prev);
_type = other._type;
_taskId = other._taskId;
_terminated.store(other._terminated.load());
_suspendedState.store(other._suspendedState.load());
_localStorage = std::move(other._localStorage);
}
return *this;
}

inline
Task::~Task()
{
Expand Down
47 changes: 34 additions & 13 deletions quantum/impl/quantum_task_queue_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ namespace Bloomberg {
namespace quantum {

inline
TaskQueue::WorkItem::WorkItem(TaskPtr task,
TaskQueue::WorkItem::WorkItem(ITaskPtr task,
TaskListIter iter,
bool isBlocked,
unsigned int blockedQueueRound) :
_task(task),
_task(std::move(task)),
_iter(iter),
_isBlocked(isBlocked),
_blockedQueueRound(blockedQueueRound)
Expand All @@ -52,9 +52,8 @@ TaskQueue::TaskQueue() :

inline
TaskQueue::TaskQueue(const Configuration&, std::shared_ptr<TaskQueue> sharedQueue) :
_alloc(Allocator<QueueListAllocator>::instance(AllocatorTraits::queueListAllocSize())),
_runQueue(_alloc),
_waitQueue(_alloc),
_runQueue(Allocator<QueueListAllocator>::instance(AllocatorTraits::queueListAllocSize())),
_waitQueue(Allocator<QueueListAllocator>::instance(AllocatorTraits::queueListAllocSize())),
_queueIt(_runQueue.end()),
_blockedIt(_runQueue.end()),
_isBlocked(false),
Expand All @@ -64,7 +63,7 @@ TaskQueue::TaskQueue(const Configuration&, std::shared_ptr<TaskQueue> sharedQueu
_isIdle(true),
_terminated(false),
_isAdvanced(false),
_sharedQueue(sharedQueue),
_sharedQueue(std::move(sharedQueue)),
_queueRound(0),
_lastSleptQueueRound(std::numeric_limits<unsigned int>::max()),
_lastSleptSharedQueueRound(std::numeric_limits<unsigned int>::max())
Expand All @@ -80,7 +79,29 @@ inline
TaskQueue::TaskQueue(const TaskQueue&) :
TaskQueue()
{
}

inline
TaskQueue::TaskQueue(TaskQueue&& other) noexcept:
_thread(std::move(other._thread)),
_runQueue(std::move(other._runQueue)),
_waitQueue(std::move(other._waitQueue)),
_queueIt(other._queueIt),
_blockedIt(_runQueue.end()),
_isBlocked(other._isBlocked),
_isEmpty(other._isEmpty.load()),
_isSharedQueueEmpty(other._isSharedQueueEmpty.load()),
_isInterrupted(other._isInterrupted.load()),
_isIdle(other._isIdle.load()),
_terminated(other._terminated.load()),
_isAdvanced(other._isAdvanced),
_stats(other._stats),
_sharedQueue(std::move(other._sharedQueue)),
_helpers(other._helpers),
_queueRound(other._queueRound),
_lastSleptQueueRound(other._lastSleptQueueRound),
_lastSleptSharedQueueRound(other._lastSleptSharedQueueRound)
{
}

inline
Expand Down Expand Up @@ -183,10 +204,10 @@ TaskQueue::ProcessTaskResult TaskQueue::processTask()
//Process a task
workItem = grabWorkItem();

TaskPtr task = workItem._task;
ITaskPtr task = workItem._task;
if (!task)
{
return ProcessTaskResult(workItem._isBlocked, workItem._blockedQueueRound);
return { workItem._isBlocked, workItem._blockedQueueRound };
}

int rc;
Expand Down Expand Up @@ -231,7 +252,7 @@ TaskQueue::ProcessTaskResult TaskQueue::processTask()
{
handleException(workItem);
}
return ProcessTaskResult(workItem._isBlocked, workItem._blockedQueueRound);
return {workItem._isBlocked, workItem._blockedQueueRound};
}

inline
Expand Down Expand Up @@ -453,7 +474,7 @@ bool TaskQueue::handleSuccess(const WorkItem& workItem)
{
ITaskContinuation::Ptr nextTask;
//check if there's another task scheduled to run after this one
nextTask = workItem._task->getNextTask();
nextTask = std::static_pointer_cast<Task>(workItem._task)->getNextTask();
if (nextTask && (nextTask->getType() == ITask::Type::ErrorHandler))
{
//skip error handler since we don't have any errors
Expand All @@ -473,7 +494,7 @@ bool TaskQueue::handleError(const WorkItem& workItem)
{
ITaskContinuation::Ptr nextTask;
//Check if we have a final task to run
nextTask = workItem._task->getErrorHandlerOrFinalTask();
nextTask = std::static_pointer_cast<Task>(workItem._task)->getErrorHandlerOrFinalTask();
//queue next task and de-queue current one
enqueue(nextTask);
doDequeue(_isIdle, workItem._iter);
Expand Down Expand Up @@ -537,9 +558,9 @@ TaskQueue::grabWorkItem()
_isIdle = _runQueue.empty();
if (_runQueue.empty())
{
return WorkItem(nullptr, _runQueue.end(), _isBlocked, _queueRound);
return {nullptr, _runQueue.end(), _isBlocked, _queueRound};
}
return WorkItem((*_queueIt), _queueIt, false, 0);
return {(*_queueIt), _queueIt, false, 0};
}

inline
Expand Down
4 changes: 2 additions & 2 deletions quantum/interface/quantum_itask.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ struct ITask : public ITerminate
Sleeping = (int)Running-5, ///< Coroutine is sleeping
Max = (int)Running-10, ///< Value of the max reserved return code
};
~ITask() = default;

~ITask() override = default;

virtual int run() = 0;

Expand Down
8 changes: 4 additions & 4 deletions quantum/quantum_io_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ namespace quantum {
class IoQueue : public IQueue
{
public:
using TaskList = std::list<IoTask::Ptr, IoQueueListAllocator>;
using TaskList = std::list<ITask::Ptr, IoQueueListAllocator>;
using TaskListIter = TaskList::iterator;

IoQueue();

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

IoQueue(const IoQueue& other);
IoQueue(const IoQueue&);

IoQueue(IoQueue&& other) = default;
IoQueue(IoQueue&& other) noexcept;

~IoQueue();
~IoQueue() override;

void terminate() final;

Expand Down
14 changes: 7 additions & 7 deletions quantum/quantum_io_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ class IoTask : public ITask
bool isHighPriority,
FUNC&& func,
ARGS&&... args);

IoTask(const IoTask&) = delete;
IoTask(IoTask&& other) noexcept;
IoTask& operator=(const IoTask&) = delete;
IoTask& operator=(IoTask&& other) noexcept;

IoTask(const IoTask& task) = delete;
IoTask(IoTask&& task) = default;
IoTask& operator=(const IoTask& task) = delete;
IoTask& operator=(IoTask&& task) = default;

~IoTask();
~IoTask() override;

//ITerminate
void terminate() final;
Expand All @@ -70,7 +70,7 @@ class IoTask : public ITask
Type getType() const final;
TaskId getTaskId() const final;
bool isBlocked() const final;
bool isSleeping(bool updateTimer = false) final;
bool isSleeping(bool updateTimer) final;
bool isHighPriority() const final;
bool isSuspended() const final;
ITask::LocalStorage& getLocalStorage() final;
Expand Down
8 changes: 0 additions & 8 deletions quantum/quantum_read_write_mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,8 @@ class ReadWriteMutex

/// @brief Copy constructor
ReadWriteMutex(const ReadWriteMutex&) = delete;

/// @brief Move constructor
ReadWriteMutex(ReadWriteMutex&&) = default;

/// @brief Copy assignment operator
ReadWriteMutex& operator=(const ReadWriteMutex&) = delete;

/// @brief Move assignment operator
ReadWriteMutex& operator=(ReadWriteMutex&&) = default;

/// @brief Lock this object as a reader (shared with other readers)
/// @details The current context will be yielded until the lock is acquired.
/// @note From a non-coroutine context, call the first. From a coroutine context,
Expand Down
8 changes: 0 additions & 8 deletions quantum/quantum_read_write_spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,8 @@ class ReadWriteSpinLock

/// @brief Copy constructor.
ReadWriteSpinLock(const ReadWriteSpinLock&) = delete;

/// @brief Move constructor.
ReadWriteSpinLock(ReadWriteSpinLock&&) = default;

/// @brief Copy assignment operator.
ReadWriteSpinLock& operator=(const ReadWriteSpinLock&) = delete;

/// @brief Move assignment operator.
ReadWriteSpinLock& operator=(ReadWriteSpinLock&&) = default;

/// @brief Lock this object as a reader (shared with other readers)
void lockRead();

Expand Down
8 changes: 0 additions & 8 deletions quantum/quantum_spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,8 @@ class SpinLock

/// @brief Copy constructor.
SpinLock(const SpinLock&) = delete;

/// @brief Move constructor.
SpinLock(SpinLock&&) = default;

/// @brief Copy assignment operator.
SpinLock& operator=(const SpinLock&) = delete;

/// @brief Move assignment operator.
SpinLock& operator=(SpinLock&&) = default;

/// @brief Locks this object.
/// @note Blocks the current thread until the lock is acquired. Blocking is achieved
/// via a busy loop and the thread is not re-scheduled by the operating system.
Expand Down
2 changes: 1 addition & 1 deletion quantum/quantum_stack_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct StackAllocator : public ContiguousPoolManager<T>

StackAllocator(const this_type&) : StackAllocator()
{}
StackAllocator(this_type&&) : StackAllocator()
StackAllocator(this_type&&) noexcept : StackAllocator()
{}
StackAllocator& operator=(const this_type&) = delete;
StackAllocator& operator=(this_type&&) = delete;
Expand Down
Loading

0 comments on commit b4c5e1c

Please sign in to comment.