Skip to content

Commit

Permalink
Use constructors for numa_init/exit
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Andi Kleen authored and filbranden committed Jul 23, 2014
1 parent 5769418 commit ec6e455
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions libnuma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}

/*
Expand Down

0 comments on commit ec6e455

Please sign in to comment.