mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-16 15:20:42 +01:00

using shared pointer to boolean flag. Bug: None Change-Id: I9d7ad7d7b187fefa7daa0247a1379e1ddd7e2b24 Reviewed-on: https://webrtc-review.googlesource.com/96300 Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Per Kjellander <perkj@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24511}
65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
/*
|
|
* Copyright 2018 The WebRTC Project Authors. All rights reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#ifndef RTC_BASE_CANCELABLE_TASK_HANDLE_H_
|
|
#define RTC_BASE_CANCELABLE_TASK_HANDLE_H_
|
|
|
|
#include "rtc_base/scoped_ref_ptr.h"
|
|
#include "rtc_base/task_queue.h"
|
|
|
|
namespace rtc {
|
|
|
|
class BaseCancelableTask;
|
|
|
|
// Allows to cancel a cancelable task. Non-empty handle can be acquired by
|
|
// calling GetCancellationHandle() on a cancelable task.
|
|
class CancelableTaskHandle {
|
|
public:
|
|
// This class is copyable and cheaply movable.
|
|
CancelableTaskHandle();
|
|
CancelableTaskHandle(const CancelableTaskHandle&);
|
|
CancelableTaskHandle(CancelableTaskHandle&&);
|
|
CancelableTaskHandle& operator=(const CancelableTaskHandle&);
|
|
CancelableTaskHandle& operator=(CancelableTaskHandle&&);
|
|
// Deleting the handler doesn't Cancel the task.
|
|
~CancelableTaskHandle();
|
|
|
|
// Prevents the cancelable task to run.
|
|
// Must be executed on the same task queue as the task itself.
|
|
void Cancel() const;
|
|
|
|
private:
|
|
friend class BaseCancelableTask;
|
|
class CancellationToken;
|
|
explicit CancelableTaskHandle(
|
|
rtc::scoped_refptr<CancellationToken> cancelation_token);
|
|
|
|
rtc::scoped_refptr<CancellationToken> cancellation_token_;
|
|
};
|
|
|
|
class BaseCancelableTask : public QueuedTask {
|
|
public:
|
|
~BaseCancelableTask() override;
|
|
|
|
CancelableTaskHandle GetCancellationHandle() const;
|
|
|
|
protected:
|
|
BaseCancelableTask();
|
|
|
|
bool Canceled() const;
|
|
|
|
private:
|
|
rtc::scoped_refptr<CancelableTaskHandle::CancellationToken>
|
|
cancellation_token_;
|
|
};
|
|
|
|
} // namespace rtc
|
|
|
|
#endif // RTC_BASE_CANCELABLE_TASK_HANDLE_H_
|