mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 23:27:04 +02:00
CLEANUP: global: introduce variable pid_bit to avoid shifts with relative_pid
At a number of places, bitmasks are used for process affinity and to map listeners to processes. Every time 1UL<<(relative_pid-1) is used. Let's create a "pid_bit" variable corresponding to this value to clean this up.
This commit is contained in:
parent
9a398beac3
commit
387bd4f69f
@ -176,6 +176,7 @@ struct global {
|
||||
extern struct global global;
|
||||
extern int pid; /* current process id */
|
||||
extern int relative_pid; /* process id starting at 1 */
|
||||
extern unsigned long pid_bit; /* bit corresponding to the process id */
|
||||
extern int actconn; /* # of active sessions */
|
||||
extern int listeners;
|
||||
extern int jobs; /* # of active jobs (listeners, sessions, open devices) */
|
||||
|
@ -118,6 +118,7 @@
|
||||
static struct list cfg_cfgfiles = LIST_HEAD_INIT(cfg_cfgfiles);
|
||||
int pid; /* current process id */
|
||||
int relative_pid = 1; /* process id starting at 1 */
|
||||
unsigned long pid_bit = 1; /* bit corresponding to the process id */
|
||||
|
||||
/* global options */
|
||||
struct global global = {
|
||||
@ -2655,6 +2656,7 @@ int main(int argc, char **argv)
|
||||
shut_your_big_mouth_gcc(write(pidfd, pidstr, strlen(pidstr)));
|
||||
}
|
||||
relative_pid++; /* each child will get a different one */
|
||||
pid_bit <<= 1;
|
||||
}
|
||||
|
||||
#ifdef USE_CPU_AFFINITY
|
||||
|
@ -64,7 +64,7 @@ static void enable_listener(struct listener *listener)
|
||||
if (listener->state == LI_LISTEN) {
|
||||
if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
|
||||
listener->bind_conf->bind_proc &&
|
||||
!(listener->bind_conf->bind_proc & (1UL << (relative_pid - 1)))) {
|
||||
!(listener->bind_conf->bind_proc & pid_bit)) {
|
||||
/* we don't want to enable this listener and don't
|
||||
* want any fd event to reach it.
|
||||
*/
|
||||
@ -168,7 +168,7 @@ static int __resume_listener(struct listener *l)
|
||||
|
||||
if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
|
||||
l->bind_conf->bind_proc &&
|
||||
!(l->bind_conf->bind_proc & (1UL << (relative_pid - 1))))
|
||||
!(l->bind_conf->bind_proc & pid_bit))
|
||||
goto end;
|
||||
|
||||
if (l->state == LI_ASSIGNED) {
|
||||
|
@ -1431,7 +1431,7 @@ static int dump_servers_state(struct stream_interface *si, struct chunk *buf)
|
||||
int bk_f_forced_id, srv_f_forced_id;
|
||||
|
||||
/* we don't want to report any state if the backend is not enabled on this process */
|
||||
if (px->bind_proc && !(px->bind_proc & (1UL << (relative_pid - 1))))
|
||||
if (px->bind_proc && !(px->bind_proc & pid_bit))
|
||||
return 1;
|
||||
|
||||
if (!appctx->ctx.cli.p1)
|
||||
@ -1546,7 +1546,7 @@ static int cli_io_handler_show_backend(struct appctx *appctx)
|
||||
continue;
|
||||
|
||||
/* we don't want to list a backend which is bound to this process */
|
||||
if (curproxy->bind_proc && !(curproxy->bind_proc & (1UL << (relative_pid - 1))))
|
||||
if (curproxy->bind_proc && !(curproxy->bind_proc & pid_bit))
|
||||
continue;
|
||||
|
||||
chunk_appendf(&trash, "%s\n", curproxy->id);
|
||||
|
Loading…
Reference in New Issue
Block a user