Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u8W5R-0062XW-Rh for pgsql-hackers@arkaria.postgresql.org; Sat, 26 Apr 2025 03:20:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u8W5Q-0009NL-0z for pgsql-hackers@arkaria.postgresql.org; Sat, 26 Apr 2025 03:20:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u8W5P-0009ND-Jh for pgsql-hackers@lists.postgresql.org; Sat, 26 Apr 2025 03:20:16 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u8W5M-00272g-2h for pgsql-hackers@postgresql.org; Sat, 26 Apr 2025 03:20:16 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-39c1ef4acf2so2115625f8f.0 for ; Fri, 25 Apr 2025 20:20:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745637611; x=1746242411; darn=postgresql.org; h=content-transfer-encoding:content-disposition:mime-version :message-id:subject:to:from:date:from:to:cc:subject:date:message-id :reply-to; bh=ozxB5X16dytOQn3Dv3JI+KJ6KGRGkH2vNkR/lgkdHVM=; b=ku0wehZMtjLifuoRz03VDBoiy0geDTH4kNaFkJX39WvyKbgKa58Kh01IRaN4PVd+dI 9vMJXr23j9C+BZFz+kF9n+JtksLLQhVTSnOz/VkM9W5wyAYLqrbJS+9kbIl9BGkJrs9Y 6awKn4Vb1cnem2v3S17MswPwztC3sFiyI/QNhektDOsaMjm2gGEwl9OHWLZraVi/t9uu E4tHwXlSvraTBv4JmlsgG62CdbXeA9c7IUputCpH9Me0wwoyvsLvAuhbHWOZsL926wE+ uR6tGRJzGcWeSZWCh7bZ/hOtGGzR95Afh+kPx0bs5/b8vc3NbomJy9Ufq9xToR+4C9NV eFwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745637611; x=1746242411; h=content-transfer-encoding:content-disposition:mime-version :message-id:subject:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ozxB5X16dytOQn3Dv3JI+KJ6KGRGkH2vNkR/lgkdHVM=; b=Df7UoA7sl/BUFtvo+BSMkrLwkjp2YfnstjKN7MsRW2H8ZMqh237hcK1Qn20amS25dZ HwvnXZH98Pt4+uZMEmtknpRFJqtcF6A8C0zcPJcpNZlUYZuZQuKJXmx6Il5IrcrO+6sH sjYy/yn3fPG/hFONpD5Gffhun+RDFHynnqSlPbxccXrz/OBosWEkPgvKcj32GdUkDXNl w16zoWllXM+2M2euE6YeAnzlIAFq2F2xe1TI/iR85dlM0Pl+QBl4LIHt9ENur4mi9+Lb h++lUMBkjctuSjlxxaTvxjrB6T27j9TOvBpZlI3iRzPtLDOapc90H91M2/LTHxFBeKG7 PLTQ== X-Gm-Message-State: AOJu0YzyHE4vjtxt9yXJyZ0duKPp6IiW6Nb5csE9kvkQdIShHfprmKJh mSiRwHFjT+ChARyESqkbzkt5SEDuOVitqCrvp/ZOQC6gyhhwvy1mD1oF6g== X-Gm-Gg: ASbGnct5E+1+j7lYiHkzaKHu8WtAWRLZQNs/OpTsn3kXZhEeWnvm011aoKqIwHGSMX/ CHGhsU4iYZP+W900BGi3YW4/otZa4KKMWW1tsYwboMad25aFkzDgOEuSJ3TbSgRi0VxAMqylaTg wE5mbXEw6rnsWPuW0Jr1GM8IRYSNvqfuOM/JmdMW+OZ8uktY4wxAaqgUa6+ei5niqUn7ZivBOsr 9Z471J2e0djuIAzksIBWCD2U6FEqkP1EoeeaPxOho12R/u2r0AMticbhQGRtsc2QVBWgGhDFB8E m9L90BwZFeYjdx9P+XEvOwoe5fH2yXkP+hX0Kne/4RC/YwTs5dxlXQ0IRJ3LfxflThQ0rmUWEen oC+IZzEgg8L9J/027sXwR3fYGc7CPIjC7zOwroC1Z4enWxJ3vYThUDHVAzi02E20UzJrLDfpLVW Jy3YaY9IQ= X-Google-Smtp-Source: AGHT+IGfMEjDdxb7kc1hXXWmidfawZxk+6uTPxX4ltUavrLEmdg2SZjEONpBQTEezvyBzKYJkcxZhg== X-Received: by 2002:a05:6000:1885:b0:39a:ca40:7bfb with SMTP id ffacd0b85a97d-3a074f60f2bmr3462997f8f.54.1745637611504; Fri, 25 Apr 2025 20:20:11 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-237-181-182.eu-west-3.compute.amazonaws.com. [15.237.181.182]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a073cc4679sm4102176f8f.58.2025.04.25.20.20.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 20:20:10 -0700 (PDT) Date: Sat, 26 Apr 2025 03:20:09 +0000 From: Bertrand Drouvot To: PostgreSQL Hackers Subject: Avoid circular header file dependency Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="6mFmyaUyFobjuDOz" Content-Disposition: inline Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --6mFmyaUyFobjuDOz Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Hi hackers, While working on wait events I faced some compilation issues due to circular header file dependency (introduced in fa88928470b5) between wait_event.h and wait_event_types.h. Those files have include guards but could still lead to compilation issues in some cases due to the circular dependency. Currently, on HEAD, this doesn't cause any issues but I think it's better to avoid circular header file dependencies (harder to maintain and understand). Please find attached a patch to $SUBJECT between those 2 header files: it extracts (in a new header file) from wait_event.h what is strictly needed in wait_event_types.h. Out of curiosity, I ran clang-tidy with misc-header-include-cycle ([1]) and it also reports: ../src/pl/plpython/plpy_util.h:9:10: warning: circular header file dependency detected while including 'plpython.h' This one worries me less because plpy_util.h only contains simple external function declarations. I was surprised that clang-tidy does report only the plpy_util.h one (in addition to the wait_event_types.h one) so I wondered if misc-header-include-cycle was failing to discover circular dependencies in nested cases. I did a quick test with: a.h → c.h → b.h → d.h → a.h and it found it: " ../d.h:6:10: warning: circular header file dependency detected while including 'a.h' 6 | #include "a.h" | ^ ../b.h:6:10: note: 'd.h' included from here 6 | #include "d.h" | ^ ../c.h:6:10: note: 'b.h' included from here 6 | #include "b.h" | ^ ../a.h:6:10: note: 'c.h' included from here 6 | #include "c.h" | ^ ../main.c:2:10: note: 'a.h' included from here 2 | #include "a.h" " So it looks like that our code base only contains those 2: plpy_util.h and wait_event_types.h cases. Thoughts? [1]: https://clang.llvm.org/extra/clang-tidy/checks/misc/header-include-cycle.html Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com --6mFmyaUyFobjuDOz Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v1-0001-Avoid-including-wait_event.h-in-wait_event_types..patch" From e001863ab8645b5b6c2021c857ac541e230398dd Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot Date: Thu, 24 Apr 2025 17:11:03 +0000 Subject: [PATCH v1] Avoid including wait_event.h in wait_event_types.h Adding wait_class_constants.h to avoid including wait_event.h in wait_event_types.h (that produced a circular include). --- .../activity/generate-wait_event_types.pl | 2 +- src/include/utils/wait_class_constants.h | 29 +++++++++++++++++++ src/include/utils/wait_event.h | 17 ++--------- 3 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 src/include/utils/wait_class_constants.h diff --git a/src/backend/utils/activity/generate-wait_event_types.pl b/src/backend/utils/activity/generate-wait_event_types.pl index 171bf2ae632..52b6b7b2ae6 100644 --- a/src/backend/utils/activity/generate-wait_event_types.pl +++ b/src/backend/utils/activity/generate-wait_event_types.pl @@ -168,7 +168,7 @@ if ($gen_code) printf $h $header_comment, 'wait_event_types.h'; printf $h "#ifndef WAIT_EVENT_TYPES_H\n"; printf $h "#define WAIT_EVENT_TYPES_H\n\n"; - printf $h "#include \"utils/wait_event.h\"\n\n"; + printf $h "#include \"utils/wait_class_constants.h\"\n\n"; printf $c $header_comment, 'pgstat_wait_event.c'; diff --git a/src/include/utils/wait_class_constants.h b/src/include/utils/wait_class_constants.h new file mode 100644 index 00000000000..286f9c2daec --- /dev/null +++ b/src/include/utils/wait_class_constants.h @@ -0,0 +1,29 @@ +/*------------------------------------------------------------------------- + * wait_class_constants.h + * Constants related to wait classes + * + * Copyright (c) 2001-2025, PostgreSQL Global Development Group + * + * src/include/utils/wait_class_constants.h + * ---------- + */ +#ifndef WAIT_CLASS_CONSTANTS_H +#define WAIT_CLASS_CONSTANTS_H + + +/* ---------- + * Wait Classes + * ---------- + */ +#define PG_WAIT_LWLOCK 0x01000000U +#define PG_WAIT_LOCK 0x03000000U +#define PG_WAIT_BUFFERPIN 0x04000000U +#define PG_WAIT_ACTIVITY 0x05000000U +#define PG_WAIT_CLIENT 0x06000000U +#define PG_WAIT_EXTENSION 0x07000000U +#define PG_WAIT_IPC 0x08000000U +#define PG_WAIT_TIMEOUT 0x09000000U +#define PG_WAIT_IO 0x0A000000U +#define PG_WAIT_INJECTIONPOINT 0x0B000000U + +#endif /* WAIT_CLASS_CONSTANTS_H */ diff --git a/src/include/utils/wait_event.h b/src/include/utils/wait_event.h index b8cb3e5a430..c3c1ce6ef2e 100644 --- a/src/include/utils/wait_event.h +++ b/src/include/utils/wait_event.h @@ -10,21 +10,8 @@ #ifndef WAIT_EVENT_H #define WAIT_EVENT_H - -/* ---------- - * Wait Classes - * ---------- - */ -#define PG_WAIT_LWLOCK 0x01000000U -#define PG_WAIT_LOCK 0x03000000U -#define PG_WAIT_BUFFERPIN 0x04000000U -#define PG_WAIT_ACTIVITY 0x05000000U -#define PG_WAIT_CLIENT 0x06000000U -#define PG_WAIT_EXTENSION 0x07000000U -#define PG_WAIT_IPC 0x08000000U -#define PG_WAIT_TIMEOUT 0x09000000U -#define PG_WAIT_IO 0x0A000000U -#define PG_WAIT_INJECTIONPOINT 0x0B000000U +/* wait class constants */ +#include "utils/wait_class_constants.h" /* enums for wait events */ #include "utils/wait_event_types.h" -- 2.34.1 --6mFmyaUyFobjuDOz--