timer_modify check new_expires

pull/37/head
YuQing 2020-12-02 13:57:28 +08:00
parent 0995f447cb
commit 5a04c1c656
4 changed files with 11 additions and 2 deletions

View File

@ -96,6 +96,11 @@ int fast_timer_modify(FastTimer *timer, FastTimerEntry *entry,
const int64_t new_expires) const int64_t new_expires)
{ {
int result; int result;
if (new_expires <= timer->current_time) {
return ETIMEDOUT;
}
if (new_expires > entry->expires) { if (new_expires > entry->expires) {
entry->rehash = TIMER_GET_SLOT_INDEX(timer, new_expires) != entry->rehash = TIMER_GET_SLOT_INDEX(timer, new_expires) !=
TIMER_GET_SLOT_INDEX(timer, entry->expires); TIMER_GET_SLOT_INDEX(timer, entry->expires);

View File

@ -36,7 +36,7 @@ typedef struct fast_timer_slot {
typedef struct fast_timer { typedef struct fast_timer {
int slot_count; //time wheel slot count int slot_count; //time wheel slot count
int64_t base_time; //base time for slot 0 int64_t base_time; //base time for slot 0
int64_t current_time; volatile int64_t current_time;
FastTimerSlot *slots; FastTimerSlot *slots;
} FastTimer; } FastTimer;

View File

@ -240,6 +240,10 @@ int locked_timer_modify(LockedTimer *timer, LockedTimerEntry *entry,
int result; int result;
int slot_index; int slot_index;
if (new_expires <= timer->current_time) {
return ETIMEDOUT;
}
if (new_expires > entry->expires) { if (new_expires > entry->expires) {
if ((result=check_entry_status(timer, entry, &slot_index)) != 0) { if ((result=check_entry_status(timer, entry, &slot_index)) != 0) {
return result; return result;

View File

@ -58,7 +58,7 @@ typedef struct locked_timer {
int slot_count; //time wheel slot count int slot_count; //time wheel slot count
LockedTimerSharedLocks entry_shares; //shared locks for entry LockedTimerSharedLocks entry_shares; //shared locks for entry
int64_t base_time; //base time for slot 0 int64_t base_time; //base time for slot 0
int64_t current_time; volatile int64_t current_time;
LockedTimerSlot *slots; LockedTimerSlot *slots;
} LockedTimer; } LockedTimer;