MCPcopy Create free account
hub / github.com/bytedance/terarkdb / add

Method add

util/timer_queue.h:65–81  ·  view source on GitHub ↗

Adds a new timer \return Returns the ID of the new timer. You can use this ID to cancel the timer

Source from the content-addressed store, hash-verified

63 // Returns the ID of the new timer. You can use this ID to cancel the
64 // timer
65 uint64_t add(int64_t milliseconds,
66 std::function<std::pair<bool, int64_t>(bool)> handler) {
67 WorkItem item;
68 Clock::time_point tp = Clock::now();
69 item.end = tp + std::chrono::milliseconds(milliseconds);
70 item.period = milliseconds;
71 item.handler = std::move(handler);
72
73 std::unique_lock<std::mutex> lk(m_mtx);
74 uint64_t id = ++m_idcounter;
75 item.id = id;
76 m_items.push(std::move(item));
77
78 // Something changed, so wake up timer thread
79 m_checkWork.notify_one();
80 return id;
81 }
82
83 // Cancels the specified timer
84 // \return

Callers 1

mainFunction · 0.45

Calls 2

nowFunction · 0.85
pushMethod · 0.45

Tested by 1

mainFunction · 0.36