1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
23 class SafeTimerThread;
32 friend class SafeTimerThread;
33 SafeTimerThread *thread;
38 std::multimap<utime_t, Context*> schedule;
39 std::map<Context*, std::multimap<utime_t, Context*>::iterator> events;
42 void dump(const char *caller = 0) const;
45 // This class isn't supposed to be copied
46 SafeTimer(const SafeTimer&) = delete;
47 SafeTimer& operator=(const SafeTimer&) = delete;
49 /* Safe callbacks determines whether callbacks are called with the lock
52 * safe_callbacks = true (default option) guarantees that a cancelled
53 * event's callback will never be called.
55 * Under some circumstances, holding the lock can cause lock cycles.
56 * If you are able to relax requirements on cancelled callbacks, then
57 * setting safe_callbacks = false eliminates the lock cycle issue.
59 SafeTimer(CephContext *cct, Mutex &l, bool safe_callbacks=true);
62 /* Call with the event_lock UNLOCKED.
64 * Cancel all events and stop the timer thread.
66 * If there are any events that still have to run, they will need to take
67 * the event_lock first. */
71 /* Schedule an event in the future
72 * Call with the event_lock LOCKED */
73 Context* add_event_after(double seconds, Context *callback);
74 Context* add_event_at(utime_t when, Context *callback);
77 * Call with the event_lock LOCKED
79 * Returns true if the callback was cancelled.
80 * Returns false if you never addded the callback in the first place.
82 bool cancel_event(Context *callback);
85 * Call with the event_lock LOCKED
87 * When this function returns, all events have been cancelled, and there are no
90 void cancel_all_events();