]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/util/timer_queue_test.cc
1 // Portions Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
7 // http://www.crazygaze.com/blog/2016/03/24/portable-c-timer-queue/
12 // The source code in this article is licensed under the CC0 license, so feel
14 // to copy, modify, share, do whatever you want with it.
15 // No attribution is required, but Ill be happy if you do.
18 // The person who associated a work with this deed has dedicated the work to the
19 // public domain by waiving all of his or her rights to the work worldwide
20 // under copyright law, including all related and neighboring rights, to the
21 // extent allowed by law. You can copy, modify, distribute and perform the
23 // commercial purposes, all without asking permission. See Other Information
27 #include "util/timer_queue.h"
32 using Clock
= std::chrono::high_resolution_clock
;
34 static auto start
= Clock::now();
35 return std::chrono::duration
<double, std::milli
>(Clock::now() - start
)
44 double tnow
= Timing::now();
46 q
.add(10000, [tnow
](bool aborted
) mutable {
47 printf("T 1: %d, Elapsed %4.2fms\n", aborted
, Timing::now() - tnow
);
48 return std::make_pair(false, 0);
50 q
.add(10001, [tnow
](bool aborted
) mutable {
51 printf("T 2: %d, Elapsed %4.2fms\n", aborted
, Timing::now() - tnow
);
52 return std::make_pair(false, 0);
55 q
.add(1000, [tnow
](bool aborted
) mutable {
56 printf("T 3: %d, Elapsed %4.2fms\n", aborted
, Timing::now() - tnow
);
57 return std::make_pair(!aborted
, 1000);
60 auto id
= q
.add(2000, [tnow
](bool aborted
) mutable {
61 printf("T 4: %d, Elapsed %4.2fms\n", aborted
, Timing::now() - tnow
);
62 return std::make_pair(!aborted
, 2000);
66 // auto ret = q.cancel(id);
72 //////////////////////////////////////////