Index: base/serial_executor.h |
diff --git a/base/serial_executor.h b/base/serial_executor.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..04d8402ee493cf70ffb64f432c290cf2acd585f8 |
--- /dev/null |
+++ b/base/serial_executor.h |
@@ -0,0 +1,68 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef BASE_SERIAL_EXECUTOR_H_ |
+#define BASE_SERIAL_EXECUTOR_H_ |
+#pragma once |
+ |
+#include "base/base_export.h" |
+#include "base/executor.h" |
+ |
+namespace base { |
+ |
+// A SerialExecutor is an Executor with more guarantees. In |
+// particular: |
+// |
+// - Given two tasks T1 and T2 that are posted from the same thread, |
+// T2 will be executed after T1 iff: |
brettw
2012/02/03 22:42:15
Just write "if". "iff" is a non-word jumps out and
|
+// |
+// * T2 is posted after T1; |
+// * T2 has equal or higher delay than T1; and |
+// * T1 is nestable, or T1 and T2 are both non-nestable. |
+// |
+// - If task T2 is executed after T1, then all memory changes in T1 |
+// will be visible to T1. |
+// |
+// Note that SerialExecutor does not guarantee execution on a single |
+// thread (see SingleThreadExecutor instead). |
+// |
+// Some corollaries to the above guarantees, in order of increasing |
brettw
2012/02/03 22:42:15
Does "in order of increasing generality" help anyt
|
+// generality: |
+// |
+// - Tasks submitted via PostTask are executed in FIFO order. |
+// |
+// - Tasks submitted via PostNonNestableTask are executed in FIFO |
+// order. |
+// |
+// - Tasks submitted with the same delay and the same nestable state |
+// are executed in FIFO order. |
+// |
+// - A list of tasks with the same nestable state submitted in order |
+// of non-decreasing delay is executed in FIFO order. |
+// |
+// - A list of tasks submitted in order of non-decreasing delay with |
+// at most a single change in nestable state from nestable to |
+// non-nestable is executed in FIFO order. (This is equivalent to |
+// the statement of the first guarantee above.) |
+// |
+// Some theoretical implementations of SerialExecutor: |
+// |
+// - A SerialExecutor that wraps a regular Executor but makes sure |
+// that only one task at a time is posted to the Executor, with |
+// appropriate memory barriers in between tasks. |
+// |
+// - A SerialExecutor that, for each task, spawns a joinable thread |
+// to execute that task and immediately quit, and then immediately |
+// joins that thread. |
+// |
+// - A SerialExecutor that stores the list of submitted tasks and |
+// has a method Run() that executes each runnable task in FIFO |
+// order that can be called from any thread, but only if another |
+// (non-nested) Run() call isn't already happening. |
+class BASE_EXPORT SerialExecutor : public Executor { |
+}; |
+ |
+} // namespace base |
+ |
+#endif // BASE_SERIAL_EXECUTOR_H_ |