Skip to content

Commit 977daf1

Browse files
author
Pierluigi Petrelli
committed
task_id is now incremental to avoid collisions - also fixing a typo
1 parent 69b7323 commit 977daf1

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/timer.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ class Timer {
134134
repeat; /* repeat task */
135135
} tasks[max_tasks];
136136

137+
unsigned long id_counter = 1;
138+
137139
inline
138140
void
139141
remove(struct task *task)
@@ -158,6 +160,14 @@ class Timer {
158160
return NULL;
159161
}
160162

163+
unsigned long next_task_id() {
164+
165+
unsigned long id = id_counter;
166+
id_counter++;
167+
168+
return id;
169+
}
170+
161171
inline
162172
struct task *
163173
add_task(unsigned long start, unsigned long expires,
@@ -166,10 +176,10 @@ class Timer {
166176
struct task * const slot = next_task_slot();
167177

168178
if (!slot)
169-
slot->id = random(2147483646);
179+
slot->id = 0;
170180
else
171-
slot->id = 0;
172-
181+
slot->id = next_task_id();//random(2147483646);
182+
173183
slot->handler = h;
174184
slot->opaque = opaque;
175185
slot->start = start;

0 commit comments

Comments
 (0)