linux-numa.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: cpw@sgi.com
Cc: linux-numa@vger.kernel.org, Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 2/8] Use constructors for numa_init/exit
Date: Wed, 14 Dec 2011 11:38:32 -0800	[thread overview]
Message-ID: <1323891518-1493-2-git-send-email-andi@firstfloor.org> (raw)
In-Reply-To: <1323891518-1493-1-git-send-email-andi@firstfloor.org>

From: Andi Kleen <ak@linux.intel.com>

This fixes the static library -- the init code is not called
here. So use a constructor. This may lead to the functions
being called twice, but we check for that
---
 libnuma.c |   27 +++++++++++++++------------
 1 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/libnuma.c b/libnuma.c
index e720ae6..b4773a2 100755
--- a/libnuma.c
+++ b/libnuma.c
@@ -82,11 +82,14 @@ static void set_sizes(void);
  *
  * The v1 library depends upon nodemask_t's of all nodes and no nodes.
  */
-void
+void __attribute__((constructor))
 numa_init(void)
 {
 	int max,i;
 
+	if (sizes_set)
+		return;
+
 	set_sizes();
 	/* numa_all_nodes should represent existing nodes on this system */
         max = numa_num_configured_nodes();
@@ -95,19 +98,19 @@ numa_init(void)
 	memset(&numa_no_nodes, 0, sizeof(numa_no_nodes));
 }
 
-void
+#define FREE_AND_ZERO(x) if (x) { 	\
+		numa_bitmask_free(x); 	\
+		x = NULL;		\
+	}
+
+void __attribute__((destructor))
 numa_fini(void)
 {
-	if (numa_all_cpus_ptr)
-		numa_bitmask_free(numa_all_cpus_ptr);
-	if (numa_all_nodes_ptr)
-		numa_bitmask_free(numa_all_nodes_ptr);
-	if (numa_no_nodes_ptr)
-		numa_bitmask_free(numa_no_nodes_ptr);
-	if (numa_memnode_ptr)
-		numa_bitmask_free(numa_memnode_ptr);
-	if (numa_nodes_ptr)
-		numa_bitmask_free(numa_nodes_ptr);
+	FREE_AND_ZERO(numa_all_cpus_ptr);
+	FREE_AND_ZERO(numa_all_nodes_ptr);
+	FREE_AND_ZERO(numa_no_nodes_ptr);
+	FREE_AND_ZERO(numa_memnode_ptr);
+	FREE_AND_ZERO(numa_nodes_ptr);
 }
 
 /*
-- 
1.7.5.4

  reply	other threads:[~2011-12-14 19:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-14 19:38 [PATCH 1/8] Add support for a "same" numamask to numactl Andi Kleen
2011-12-14 19:38 ` Andi Kleen [this message]
2011-12-14 19:38 ` [PATCH 3/8] Use glibc syscall if possible Andi Kleen
2011-12-14 19:38 ` [PATCH 4/8] Run full test suite before exiting Andi Kleen
2011-12-14 19:38 ` [PATCH 5/8] Add IO affinity support to libnuma Andi Kleen
2011-12-14 19:38 ` [PATCH 6/8] Clean regression test temp files Andi Kleen
2011-12-14 19:38 ` [PATCH 7/8] memhog: add option to disable transparent huge pages Andi Kleen
2011-12-14 19:38 ` [PATCH 8/8] Disable transparent huge pages in test suite Andi Kleen
2011-12-19 15:12 ` numactl/libnuma 2.0.8-rc3 Cliff Wickman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1323891518-1493-2-git-send-email-andi@firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=ak@linux.intel.com \
    --cc=cpw@sgi.com \
    --cc=linux-numa@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).