Skip to contentSkip to conversation

igt_core: add igt_constructor

PATCH Superseded Lyude 2 participants 3 messages Dec 21, 2016 Library code

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Lyude

author
#0 lore raw

PATCH 1/1 igt_core: add igt_constructor

This is a simple macro for executing a block of code at the beginning of intel-gpu-tools, before any tests have been ran. Useful for initialization of global resources used in IGT libraries.

---
 configure.ac   |  1 +
 lib/igt_core.h | 13 +++++++++++++
 2 files changed, 14 insertions(+)
configure.ac +1 -0
index fa31a52..411bfab 100644
@@ -65,6 +65,7 @@ AC_CHECK_TYPES([sighandler_t],[],[],[AC_INCLUDES_DEFAULT
 #include <signal.h>])
 AC_CHECK_FUNCS([swapctl])
 AC_CHECK_FUNCS([asprintf])
+AX_GCC_FUNC_ATTRIBUTE([constructor])
 
 dnl Check for POSIX timers
 AC_CHECK_FUNCS(timer_create, [], [
lib/igt_core.h +13 -0
index 661a634..e76fd5f 100644
@@ -281,6 +281,19 @@ void igt_simple_init_parse_opts(int *argc, char **argv,
 	} \
 	static void igt_tokencat(__real_main, __LINE__)(void) \
 
+/**
+ * igt_constructor:
+ *
+ * Convenience macro to run the provided code block when igt first starts,
+ * before any tests have been run. This should be used for parts of the igt
+ * library that require initialization of objects with global context.
+ *
+ * This code block will be executed exactly once.
+ */
+#define igt_constructor \
+	static void __igt_constructor_block(void) __attribute__((constructor)); \
+	static void __igt_constructor_block(void)
+
 __attribute__((format(printf, 1, 2)))
 void igt_skip(const char *f, ...) __attribute__((noreturn));
 __attribute__((format(printf, 5, 6)))
Signature · 6 lines
2.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 32 lines · Lyude

This is a simple macro for executing a block of code at the beginning of intel-gpu-tools, before any tests have been ran. Useful for initialization of global resources used in IGT libraries.

---
 configure.ac   |  1 +
 lib/igt_core.h | 13 +++++++++++++
 2 files changed, 14 insertions(+)
configure.ac +1 -0
index fa31a52..411bfab 100644
@@ -65,6 +65,7 @@ AC_CHECK_TYPES([sighandler_t],[],[],[AC_INCLUDES_DEFAULT
 #include <signal.h>])
 AC_CHECK_FUNCS([swapctl])
 AC_CHECK_FUNCS([asprintf])
+AX_GCC_FUNC_ATTRIBUTE([constructor])
 
 dnl Check for POSIX timers
 AC_CHECK_FUNCS(timer_create, [], [
lib/igt_core.h +2 -0
index 661a634..e76fd5f 100644
@@ -281,6 +281,19 @@ void igt_simple_init_parse_opts(int *argc, char **argv,
 	} \
 	static void igt_tokencat(__real_main, __LINE__)(void) \
 
+/**
+ * igt_constructor:

lib/igt_core.h void igt_simple_init_parse_opts(int *argc, char **argv, · line 295

Quoted 10 lines
lib/igt_core.h +10 -0
+ *
+ * Convenience macro to run the provided code block when igt first starts,
+ * before any tests have been run. This should be used for parts of the igt
+ * library that require initialization of objects with global context.
+ *
+ * This code block will be executed exactly once.
+ */
+#define igt_constructor \
+	static void __igt_constructor_block(void) __attribute__((constructor)); \
+	static void __igt_constructor_block(void)

#define igt_constructor \
__attribute__((constructor)) \
static void igt_tokencat(__igt_constructor, __LINE__)(void)

Allows for the flexibility to use multiple constructors from the file. -chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#2 lore raw
Quoted 55 lines · Chris Wilson
Quoted 48 lines · Lyude

This is a simple macro for executing a block of code at the beginning of
intel-gpu-tools, before any tests have been ran. Useful for initialization of global resources used in IGT libraries.

---
 configure.ac   |  1 +
 lib/igt_core.h | 13 +++++++++++++

 2 files changed, 14 insertions(+)
configure.ac +0 -0
index fa31a52..411bfab 100644
@@ -65,6 +65,7 @@

AC_CHECK_TYPES([sighandler_t],[],[],[AC_INCLUDES_DEFAULT #include <signal.h>]) AC_CHECK_FUNCS([swapctl]) AC_CHECK_FUNCS([asprintf]) +AX_GCC_FUNC_ATTRIBUTE([constructor])

 dnl Check for POSIX timers AC_CHECK_FUNCS(timer_create, [], [

lib/igt_core.h +0 -0
index 661a634..e76fd5f 100644
@@ -281,6 +281,19 @@ void igt_simple_init_parse_opts(int *argc,
 char **argv,
  	} \
  	static void igt_tokencat(__real_main, __LINE__)(void) \


+/**
+ * igt_constructor:
+ *
+ * Convenience macro to run the provided code block when igt first starts,
+ * before any tests have been run. This should be used for parts of the igt
+ * library that require initialization of objects with global context.
+ *
+ * This code block will be executed exactly once.
+ */

lib/igt_core.h +2 -0
+#define igt_constructor \
+	static void __igt_constructor_block(void)

__attribute__((constructor)); \

lib/igt_core.h void igt_simple_init_parse_opts(int *argc, char **argv, · line 295

Quoted 1 line
lib/igt_core.h +1 -0
+	static void __igt_constructor_block(void)

#define igt_constructor \
__attribute__((constructor)) \
static void igt_tokencat(__igt_constructor, __LINE__)(void)

Quoted 3 lines

Allows for the flexibility to use multiple constructors from the file.
-chris

ooh, clever. will respin in just a sec.

Quoted 1 line
Signature · 6 lines
Cheers,
	Lyude
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx