mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 13:51:26 +02:00
MINOR: logs: clarify the check of the log range
The test of the log range is not very clear, in part due to the reuse of the "curr_idx" name that happens at two levels. The call to in_smp_log_range() applies to the smp_info's index to which 1 is added: it verifies that the next index is still within the current range. Let's just have a local variable "next_index" in process_send_log() that gets assigned the next index (current+1) and compare it to the current range's boundaries. This makes the test much clearer. We can then simply remove in_smp_log_range() that's no longer needed.
This commit is contained in:
parent
61b6a4da6c
commit
4351364700
@ -155,17 +155,6 @@ char *update_log_hdr(const time_t time);
|
||||
char * get_format_pid_sep1(int format, size_t *len);
|
||||
char * get_format_pid_sep2(int format, size_t *len);
|
||||
|
||||
/*
|
||||
* Test if <idx> index numbered from 0 is in <rg> range with low and high
|
||||
* limits of indexes numbered from 1.
|
||||
*/
|
||||
static inline int in_smp_log_range(struct smp_log_range *rg, unsigned int idx)
|
||||
{
|
||||
if (idx + 1 <= rg->high && idx + 1 >= rg->low)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Builds a log line for the stream (must be valid).
|
||||
*/
|
||||
|
@ -1831,10 +1831,14 @@ void process_send_log(struct list *logsrvs, int level, int facility,
|
||||
|
||||
if (logsrv->lb.smp_rgs) {
|
||||
struct smp_log_range *curr_rg;
|
||||
unsigned int next_idx;
|
||||
|
||||
HA_SPIN_LOCK(LOGSRV_LOCK, &logsrv->lock);
|
||||
next_idx = logsrv->lb.curr_idx + 1;
|
||||
curr_rg = &logsrv->lb.smp_rgs[logsrv->lb.curr_rg];
|
||||
in_range = in_smp_log_range(curr_rg, logsrv->lb.curr_idx);
|
||||
|
||||
/* check if the index we're going to take is within range */
|
||||
in_range = curr_rg->low <= next_idx && next_idx <= curr_rg->high;
|
||||
if (in_range) {
|
||||
/* Let's consume this range. */
|
||||
curr_rg->curr_idx = (curr_rg->curr_idx + 1) % curr_rg->sz;
|
||||
@ -1843,7 +1847,7 @@ void process_send_log(struct list *logsrvs, int level, int facility,
|
||||
logsrv->lb.curr_rg = (logsrv->lb.curr_rg + 1) % logsrv->lb.smp_rgs_sz;
|
||||
}
|
||||
}
|
||||
logsrv->lb.curr_idx = (logsrv->lb.curr_idx + 1) % logsrv->lb.smp_sz;
|
||||
logsrv->lb.curr_idx = next_idx % logsrv->lb.smp_sz;
|
||||
HA_SPIN_UNLOCK(LOGSRV_LOCK, &logsrv->lock);
|
||||
}
|
||||
if (in_range)
|
||||
|
Loading…
x
Reference in New Issue
Block a user