summaryrefslogtreecommitdiffhomepage
path: root/pkg/control
diff options
context:
space:
mode:
authorGhanan Gowripalan <ghanan@google.com>2020-01-08 17:19:35 -0800
committergVisor bot <gvisor-bot@google.com>2020-01-08 17:50:54 -0800
commitd057871f410088fe6825b1dde695f015e36abf73 (patch)
tree3f137b4b314ac4ecbaaca4d26eb7fdc5a5a14784 /pkg/control
parentfbb2c008e26a7e9d860f6cbf796ea7c375858502 (diff)
CancellableTimer to encapsulate the work of safely stopping timers
Add a new CancellableTimer type to encapsulate the work of safely stopping timers when it fires at the same time some "related work" is being handled. The term "related work" is some work that needs to be done while having obtained some common lock (L). Example: Say we have an invalidation timer that may be extended or cancelled by some event. Creating a normal timer and simply cancelling may not be sufficient as the timer may have already fired when the event handler attemps to cancel it. Even if the timer and event handler obtains L before doing work, once the event handler releases L, the timer will eventually obtain L and do some unwanted work. To prevent the timer from doing unwanted work, it checks if it should early return instead of doing the normal work after obtaining L. When stopping the timer callers must have L locked so the timer can be safely informed that it should early return. Test: Tests that CancellableTimer fires and resets properly. Test to make sure the timer fn is not called after being stopped within the lock L. PiperOrigin-RevId: 288806984
Diffstat (limited to 'pkg/control')
0 files changed, 0 insertions, 0 deletions