Remove circular #include's between wait_event.h and wait_event_types.h
authorMichael Paquier <michael@paquier.xyz>
Mon, 28 Apr 2025 00:08:15 +0000 (09:08 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 28 Apr 2025 00:08:15 +0000 (09:08 +0900)
wait_event_types.h is generated by the code, and included wait_event.h.
wait_event.h did the opposite move, including wait_event_types.h,
causing a circular dependency between both.

wait_event_types.h only needs to now about the wait event classes, so
this information is moved into its own file, and wait_event_types.h uses
this new header so as it does not depend anymore on wait_event.h.

Note that such errors can be found with clang-tidy, with commands like
this one:
clang-tidy source_file.c --checks=misc-header-include-cycle -- \
  -I/install/path/include/ -I/install/path/include/server/

Issue introduced by fa88928470b5.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/350192.1745768770@sss.pgh.pa.us

src/backend/utils/activity/generate-wait_event_types.pl
src/include/utils/wait_classes.h [new file with mode: 0644]
src/include/utils/wait_event.h

index 171bf2ae632c8fcf4d49765650f6bce35964b6dc..424ad9f115d3476a895bc42ffdda02811611f1be 100644 (file)
@@ -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_classes.h\"\n\n";
 
    printf $c $header_comment, 'pgstat_wait_event.c';
 
diff --git a/src/include/utils/wait_classes.h b/src/include/utils/wait_classes.h
new file mode 100644 (file)
index 0000000..51ee683
--- /dev/null
@@ -0,0 +1,29 @@
+/*-------------------------------------------------------------------------
+ * wait_classes.h
+ *   Definitions related to wait event classes
+ *
+ * Copyright (c) 2001-2025, PostgreSQL Global Development Group
+ *
+ * src/include/utils/wait_classes.h
+ * ----------
+ */
+#ifndef WAIT_CLASSES_H
+#define WAIT_CLASSES_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_CLASSES_H */
index b8cb3e5a4309da187476e796ce22f97720dca39b..f5815b4994ab4a00922b4d3a5aefe72133c3627a 100644 (file)
 #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
-
 /* enums for wait events */
 #include "utils/wait_event_types.h"