OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_SYNC_BASE_CANCELATION_SIGNAL_H_ | 5 #ifndef COMPONENTS_SYNC_BASE_CANCELATION_SIGNAL_H_ |
6 #define COMPONENTS_SYNC_BASE_CANCELATION_SIGNAL_H_ | 6 #define COMPONENTS_SYNC_BASE_CANCELATION_SIGNAL_H_ |
7 | 7 |
8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
9 #include "components/sync/base/sync_export.h" | |
10 | 9 |
11 namespace syncer { | 10 namespace syncer { |
12 | 11 |
13 class CancelationObserver; | 12 class CancelationObserver; |
14 | 13 |
15 // This class is used to allow one thread to request that another abort and | 14 // This class is used to allow one thread to request that another abort and |
16 // return early. | 15 // return early. |
17 // | 16 // |
18 // The signalling thread owns this class and my call Signal() at any time. | 17 // The signalling thread owns this class and my call Signal() at any time. |
19 // After that call, this class' IsSignalled() will always return true. The | 18 // After that call, this class' IsSignalled() will always return true. The |
20 // intended use case is that the task intending to support early exit will | 19 // intended use case is that the task intending to support early exit will |
21 // periodically check the value of IsSignalled() to see if it should return | 20 // periodically check the value of IsSignalled() to see if it should return |
22 // early. | 21 // early. |
23 // | 22 // |
24 // The receiving task may also choose to register an CancelationObserver whose | 23 // The receiving task may also choose to register an CancelationObserver whose |
25 // OnSignalReceived() method will be executed on the signaller's thread when | 24 // OnSignalReceived() method will be executed on the signaller's thread when |
26 // Signal() is called. This may be used for sending an early Signal() to a | 25 // Signal() is called. This may be used for sending an early Signal() to a |
27 // WaitableEvent. The registration of the handler is necessarily racy. If | 26 // WaitableEvent. The registration of the handler is necessarily racy. If |
28 // Signal() is executes before TryRegisterHandler(), TryRegisterHandler() will | 27 // Signal() is executes before TryRegisterHandler(), TryRegisterHandler() will |
29 // not perform any registration and return false. That function's caller must | 28 // not perform any registration and return false. That function's caller must |
30 // handle this case. | 29 // handle this case. |
31 // | 30 // |
32 // This class supports only one handler, though it could easily support multiple | 31 // This class supports only one handler, though it could easily support multiple |
33 // observers if we found a use case for such a feature. | 32 // observers if we found a use case for such a feature. |
34 class SYNC_EXPORT CancelationSignal { | 33 class CancelationSignal { |
35 public: | 34 public: |
36 CancelationSignal(); | 35 CancelationSignal(); |
37 ~CancelationSignal(); | 36 ~CancelationSignal(); |
38 | 37 |
39 // Tries to register a handler to be invoked when Signal() is called. | 38 // Tries to register a handler to be invoked when Signal() is called. |
40 // | 39 // |
41 // If Signal() has already been called, returns false without registering | 40 // If Signal() has already been called, returns false without registering |
42 // the handler. Returns true when the registration is successful. | 41 // the handler. Returns true when the registration is successful. |
43 // | 42 // |
44 // If the registration was successful, the handler must be unregistered with | 43 // If the registration was successful, the handler must be unregistered with |
(...skipping 18 matching lines...) Expand all Loading... |
63 // True if Signal() has been invoked. | 62 // True if Signal() has been invoked. |
64 bool signalled_; | 63 bool signalled_; |
65 | 64 |
66 // The registered abort handler. May be NULL. | 65 // The registered abort handler. May be NULL. |
67 CancelationObserver* handler_; | 66 CancelationObserver* handler_; |
68 }; | 67 }; |
69 | 68 |
70 } // namespace syncer | 69 } // namespace syncer |
71 | 70 |
72 #endif // COMPONENTS_SYNC_BASE_CANCELATION_SIGNAL_H_ | 71 #endif // COMPONENTS_SYNC_BASE_CANCELATION_SIGNAL_H_ |
OLD | NEW |