From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andi Kleen Subject: [PATCH 2/8] Use constructors for numa_init/exit Date: Wed, 14 Dec 2011 11:38:32 -0800 Message-ID: <1323891518-1493-2-git-send-email-andi@firstfloor.org> References: <1323891518-1493-1-git-send-email-andi@firstfloor.org> Return-path: In-Reply-To: <1323891518-1493-1-git-send-email-andi@firstfloor.org> Sender: linux-numa-owner@vger.kernel.org List-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: cpw@sgi.com Cc: linux-numa@vger.kernel.org, Andi Kleen From: Andi Kleen 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