Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3176)

Unified Diff: third_party/libjingle_xmpp/task_runner/taskrunner.h

Issue 2694903005: Add a copy of webrtc's TaskRunner abstraction, which is going to be deleted in webrtc. (Closed)
Patch Set: Delete dependencies on webrtc's rtc_task_runner. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/libjingle_xmpp/task_runner/taskrunner.h
diff --git a/third_party/libjingle_xmpp/task_runner/taskrunner.h b/third_party/libjingle_xmpp/task_runner/taskrunner.h
new file mode 100644
index 0000000000000000000000000000000000000000..44ac99420726c2c59ac3e7ff68f031e5daabc8fd
--- /dev/null
+++ b/third_party/libjingle_xmpp/task_runner/taskrunner.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2004 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 WEBRTC_BASE_TASKRUNNER_H__
+#define WEBRTC_BASE_TASKRUNNER_H__
+
+#include <stdint.h>
+
+#include <vector>
+
+#include "third_party/libjingle_xmpp/task_runner/taskparent.h"
+#include "third_party/webrtc/base/checks.h"
+#include "third_party/webrtc/base/sigslot.h"
+
+namespace rtc {
+class Task;
+
+const int64_t kSecToMsec = 1000;
+const int64_t kMsecTo100ns = 10000;
+const int64_t kSecTo100ns = kSecToMsec * kMsecTo100ns;
+
+class TaskRunner : public TaskParent, public sigslot::has_slots<> {
+ public:
+ TaskRunner();
+ ~TaskRunner() override;
+
+ virtual void WakeTasks() = 0;
+
+ // Returns the current time in 100ns units. It is used for
+ // determining timeouts. The origin is not important, only
+ // the units and that rollover while the computer is running.
+ //
+ // On Windows, GetSystemTimeAsFileTime is the typical implementation.
+ virtual int64_t CurrentTime() = 0;
+
+ void StartTask(Task *task);
+ void RunTasks();
+ void PollTasks();
+
+ void UpdateTaskTimeout(Task* task, int64_t previous_task_timeout_time);
+
+#if RTC_DCHECK_IS_ON
+ bool is_ok_to_delete(Task* task) {
+ return task == deleting_task_;
+ }
+
+ void IncrementAbortCount() {
+ ++abort_count_;
+ }
+
+ void DecrementAbortCount() {
+ --abort_count_;
+ }
+#endif
+
+ // Returns the next absolute time when a task times out
+ // OR "0" if there is no next timeout.
+ int64_t next_task_timeout() const;
+
+ protected:
+ // The primary usage of this method is to know if
+ // a callback timer needs to be set-up or adjusted.
+ // This method will be called
+ // * when the next_task_timeout() becomes a smaller value OR
+ // * when next_task_timeout() has changed values and the previous
+ // value is in the past.
+ //
+ // If the next_task_timeout moves to the future, this method will *not*
+ // get called (because it subclass should check next_task_timeout()
+ // when its timer goes off up to see if it needs to set-up a new timer).
+ //
+ // Note that this maybe called conservatively. In that it may be
+ // called when no time change has happened.
+ virtual void OnTimeoutChange() {
+ // by default, do nothing.
+ }
+
+ private:
+ void InternalRunTasks(bool in_destructor);
+ void CheckForTimeoutChange(int64_t previous_timeout_time);
+
+ std::vector<Task *> tasks_;
+ Task *next_timeout_task_ = nullptr;
+ bool tasks_running_ = false;
+#if RTC_DCHECK_IS_ON
+ int abort_count_ = 0;
+ Task* deleting_task_ = nullptr;
+#endif
+
+ void RecalcNextTimeout(Task *exclude_task);
+};
+
+} // namespace rtc
+
+#endif // TASK_BASE_TASKRUNNER_H__
« no previous file with comments | « third_party/libjingle_xmpp/task_runner/taskparent.cc ('k') | third_party/libjingle_xmpp/task_runner/taskrunner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698