Skip to content

Commit cbb876a

Browse files
committed
API: add hwloc_topology_free_group()
Closes #619 Signed-off-by: Brice Goglin <[email protected]>
1 parent 9889360 commit cbb876a

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

doc/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ man3_tinker_DATA = \
466466
$(DOX_MAN_DIR)/man3/hwloc_topology_allow.3 \
467467
$(DOX_MAN_DIR)/man3/hwloc_topology_insert_misc_object.3 \
468468
$(DOX_MAN_DIR)/man3/hwloc_topology_alloc_group_object.3 \
469+
$(DOX_MAN_DIR)/man3/hwloc_topology_free_group_object.3 \
469470
$(DOX_MAN_DIR)/man3/hwloc_topology_insert_group_object.3 \
470471
$(DOX_MAN_DIR)/man3/hwloc_obj_add_other_obj_sets.3 \
471472
$(DOX_MAN_DIR)/man3/hwloc_topology_refresh.3

hwloc/topology.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,22 @@ hwloc_topology_alloc_group_object(struct hwloc_topology *topology)
20312031
return hwloc_alloc_setup_object(topology, HWLOC_OBJ_GROUP, HWLOC_UNKNOWN_INDEX);
20322032
}
20332033

2034+
int
2035+
hwloc_topology_free_group_object(struct hwloc_topology *topology, hwloc_obj_t obj)
2036+
{
2037+
if (!(topology->state & HWLOC_TOPOLOGY_STATE_IS_LOADED)) {
2038+
/* this could actually work when IS_LOADING, see insert() below */
2039+
errno = EINVAL;
2040+
return -1;
2041+
}
2042+
if (topology->adopted_shmem_addr) {
2043+
errno = EPERM;
2044+
return -1;
2045+
}
2046+
hwloc_free_unlinked_object(obj);
2047+
return 0;
2048+
}
2049+
20342050
static void hwloc_propagate_symmetric_subtree(hwloc_topology_t topology, hwloc_obj_t root);
20352051
static void propagate_total_memory(hwloc_obj_t obj);
20362052
static void hwloc_set_group_depth(hwloc_topology_t topology);

include/hwloc.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,6 +2801,19 @@ HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_misc_object(hwloc_topology_t to
28012801
*/
28022802
HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_alloc_group_object(hwloc_topology_t topology);
28032803

2804+
/** \brief Free a group object allocated with hwloc_topology_alloc_group_object().
2805+
*
2806+
* This function is only useful if the group object was not given
2807+
* to hwloc_topology_insert_group_object() as planned.
2808+
*
2809+
* \note \p topology must be the same as the one previously passed
2810+
* to hwloc_topology_alloc_group_object().
2811+
*
2812+
* \return \c 0 on success.
2813+
* \return \c -1 on error, for instance if an invalid topology is given.
2814+
*/
2815+
HWLOC_DECLSPEC int hwloc_topology_free_group_object(hwloc_topology_t topology, hwloc_obj_t group);
2816+
28042817
/** \brief Add more structure to the topology by adding an intermediate Group
28052818
*
28062819
* The caller should first allocate a new Group object with hwloc_topology_alloc_group_object().

include/hwloc/rename.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ extern "C" {
178178

179179
#define hwloc_topology_insert_misc_object HWLOC_NAME(topology_insert_misc_object)
180180
#define hwloc_topology_alloc_group_object HWLOC_NAME(topology_alloc_group_object)
181+
#define hwloc_topology_free_group_object HWLOC_NAME(topology_free_group_object)
181182
#define hwloc_topology_insert_group_object HWLOC_NAME(topology_insert_group_object)
182183
#define hwloc_obj_add_other_obj_sets HWLOC_NAME(obj_add_other_obj_sets)
183184
#define hwloc_topology_refresh HWLOC_NAME(topology_refresh)

tests/hwloc/hwloc_groups.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ int main(void)
3131
hwloc_topology_load(topology);
3232
root = hwloc_get_root_obj(topology);
3333
assert(hwloc_topology_get_depth(topology) == 3);
34+
/* free instead of inserting */
35+
group = hwloc_topology_alloc_group_object(topology);
36+
assert(group);
37+
group->cpuset = hwloc_bitmap_dup(root->cpuset);
38+
err = hwloc_topology_free_group_object(topology, group);
39+
assert(err == 0);
3440
/* insert without sets, fails */
3541
group = hwloc_topology_alloc_group_object(topology);
3642
assert(group);

0 commit comments

Comments
 (0)