Cancellable timers: sorted_list::remove, timer cancel, replace done flag with timer cancellation
This commit is contained in:
@@ -28,8 +28,8 @@ struct sorted_list {
|
||||
T& front() { return head->value(); }
|
||||
const T& front() const { return head->value(); }
|
||||
|
||||
void insert(T value) {
|
||||
if (full()) return;
|
||||
node* insert(T value) {
|
||||
if (full()) return nullptr;
|
||||
node* n = free_head;
|
||||
free_head = n->next;
|
||||
new (n->storage) T(std::move(value));
|
||||
@@ -37,7 +37,7 @@ struct sorted_list {
|
||||
if (!head || n->value() < head->value()) {
|
||||
n->next = head;
|
||||
head = n;
|
||||
return;
|
||||
return n;
|
||||
}
|
||||
|
||||
node* cur = head;
|
||||
@@ -45,6 +45,7 @@ struct sorted_list {
|
||||
cur = cur->next;
|
||||
n->next = cur->next;
|
||||
cur->next = n;
|
||||
return n;
|
||||
}
|
||||
|
||||
void pop_front() {
|
||||
@@ -55,4 +56,21 @@ struct sorted_list {
|
||||
n->next = free_head;
|
||||
free_head = n;
|
||||
}
|
||||
|
||||
bool remove(node* target) {
|
||||
if (!target || empty()) return false;
|
||||
if (head == target) {
|
||||
pop_front();
|
||||
return true;
|
||||
}
|
||||
node* cur = head;
|
||||
while (cur->next && cur->next != target)
|
||||
cur = cur->next;
|
||||
if (cur->next != target) return false;
|
||||
cur->next = target->next;
|
||||
target->value().~T();
|
||||
target->next = free_head;
|
||||
free_head = target;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user