cosmetic: penalty timers: constify, tweak doc

Change-Id: I28addc9a16a4c81978290303d368f630a8334228
This commit is contained in:
Neels Hofmeyr 2018-05-18 03:46:41 +02:00 committed by Harald Welte
parent dd24cd39c0
commit fb75d109a1
2 changed files with 15 additions and 10 deletions

View File

@ -10,24 +10,29 @@ struct penalty_timers;
* returns an empty struct penalty_timers. */ * returns an empty struct penalty_timers. */
struct penalty_timers *penalty_timers_init(void *ctx); struct penalty_timers *penalty_timers_init(void *ctx);
/* Add a penalty timer for a BTS. /* Add a penalty timer for an arbitary object.
* Note: the ownership of for_object remains with the caller; it is handled as a mere void* value, so
* invalid pointers can be handled without problems, while common sense dictates that invalidated
* pointers (freed objects) should probably be removed from this list. More importantly, the pointer must
* match any pointers used to query penalty timers, so for_object should reference some global/singleton
* object that tends to stay around longer than the penalty timers.
* param pt: penalty timers list as from penalty_timers_init(). * param pt: penalty timers list as from penalty_timers_init().
* param for_object: arbitrary pointer reference to store a penalty timer for (passing NULL is possible, * param for_object: arbitrary pointer reference to store a penalty timer for (passing NULL is possible,
* but note that penalty_timers_clear() will clear all timers if given for_object=NULL). * but note that penalty_timers_clear() will clear all timers if given for_object=NULL).
* param timeout: penalty time in seconds. */ * param timeout: penalty time in seconds. */
void penalty_timers_add(struct penalty_timers *pt, void *for_object, int timeout); void penalty_timers_add(struct penalty_timers *pt, const void *for_object, int timeout);
/* Return the amount of penalty time remaining for a BTS. /* Return the amount of penalty time remaining for an object.
* param pt: penalty timers list as from penalty_timers_init(). * param pt: penalty timers list as from penalty_timers_init().
* param for_object: arbitrary pointer reference to query penalty timers for. * param for_object: arbitrary pointer reference to query penalty timers for.
* returns seconds remaining until all penalty time has expired. */ * returns seconds remaining until all penalty time has expired. */
unsigned int penalty_timers_remaining(struct penalty_timers *pt, void *for_object); unsigned int penalty_timers_remaining(struct penalty_timers *pt, const void *for_object);
/* Clear penalty timers for one or all BTS. /* Clear penalty timers for one or all objects.
* param pt: penalty timers list as from penalty_timers_init(). * param pt: penalty timers list as from penalty_timers_init().
* param for_object: arbitrary pointer reference to clear penalty time for, * param for_object: arbitrary pointer reference to clear penalty time for,
* or NULL to clear all timers. */ * or NULL to clear all timers. */
void penalty_timers_clear(struct penalty_timers *pt, void *for_object); void penalty_timers_clear(struct penalty_timers *pt, const void *for_object);
/* Free a struct as returned from penalty_timers_init(). /* Free a struct as returned from penalty_timers_init().
* Clear all timers from the list, deallocate the list and set the pointer to NULL. * Clear all timers from the list, deallocate the list and set the pointer to NULL.

View File

@ -34,7 +34,7 @@ struct penalty_timers {
struct penalty_timer { struct penalty_timer {
struct llist_head entry; struct llist_head entry;
void *for_object; const void *for_object;
unsigned int timeout; unsigned int timeout;
}; };
@ -55,7 +55,7 @@ struct penalty_timers *penalty_timers_init(void *ctx)
return pt; return pt;
} }
void penalty_timers_add(struct penalty_timers *pt, void *for_object, int timeout) void penalty_timers_add(struct penalty_timers *pt, const void *for_object, int timeout)
{ {
struct penalty_timer *timer; struct penalty_timer *timer;
unsigned int now; unsigned int now;
@ -89,7 +89,7 @@ void penalty_timers_add(struct penalty_timers *pt, void *for_object, int timeout
llist_add_tail(&timer->entry, &pt->timers); llist_add_tail(&timer->entry, &pt->timers);
} }
unsigned int penalty_timers_remaining(struct penalty_timers *pt, void *for_object) unsigned int penalty_timers_remaining(struct penalty_timers *pt, const void *for_object)
{ {
struct penalty_timer *timer; struct penalty_timer *timer;
unsigned int now = time_now(); unsigned int now = time_now();
@ -107,7 +107,7 @@ unsigned int penalty_timers_remaining(struct penalty_timers *pt, void *for_objec
return max_remaining; return max_remaining;
} }
void penalty_timers_clear(struct penalty_timers *pt, void *for_object) void penalty_timers_clear(struct penalty_timers *pt, const void *for_object)
{ {
struct penalty_timer *timer, *timer2; struct penalty_timer *timer, *timer2;
llist_for_each_entry_safe(timer, timer2, &pt->timers, entry) { llist_for_each_entry_safe(timer, timer2, &pt->timers, entry) {