PipeWire  0.3.27
pw_map Class Reference

A map. More...

Public Member Functions

#define PW_MAP_ID_TO_PTR(id)   (SPA_UINT32_TO_PTR((id)<<1))
 Convert an id to a pointer that can be inserted into the map. More...
#define PW_MAP_PTR_TO_ID(p)   (SPA_PTR_TO_UINT32(p)>>1)
 Convert a pointer to an id that can be retrieved from the map. More...
static void pw_map_init (struct pw_map *map, size_t size, size_t extend)
 Initialize a map. More...
static void pw_map_clear (struct pw_map *map)
 Clear a map. More...
static uint32_t pw_map_insert_new (struct pw_map *map, void *data)
 Insert data in the map. More...
static int pw_map_insert_at (struct pw_map *map, uint32_t id, void *data)
 Insert data in the map at an index. More...
static void pw_map_remove (struct pw_map *map, uint32_t id)
 Remove an item at index. More...
static void * pw_map_lookup (struct pw_map *map, uint32_t id)
 Find an item in the map. More...
static int pw_map_for_each (struct pw_map *map, int(*func)(void *item_data, void *data), void *data)
 Iterate all map items. More...

Data Fields

struct pw_array items
 an array with the map items More...
uint32_t free_list
 the free items More...

Detailed Description

A map.

A map that holds objects indexed by id.

Member Function Documentation

◆ pw_map_clear()

static void pw_map_clear ( struct pw_map map)

Clear a map.

mapthe map to clear

Referenced by pw_mempool_destroy().

◆ pw_map_for_each()

static int pw_map_for_each ( struct pw_map map,
int(*)(void *item_data, void *data func,
void *  data 

Iterate all map items.

mapthe map to iterate
functhe function to call for each item, the item data and data is passed to the function. When func returns a non-zero result, iteration ends and the result is returned.
datadata to pass to func
the result of the last call to func or 0 when all callbacks returned 0.

References pw_map_item::data, items, pw_array_for_each, pw_map_item_is_free, and res.

Referenced by pw_impl_client::pw_impl_client_destroy().

◆ pw_map_init()

static void pw_map_init ( struct pw_map map,
size_t  size,
size_t  extend 

Initialize a map.

mapthe map to initialize
sizethe initial size of the map
extendthe amount to bytes to grow the map with when needed

References pw_array::extend, free_list, items, pw_array::pw_array_ensure_size(), pw_array::pw_array_init(), and pw_array::size.

Referenced by pw_mempool_new().

◆ pw_map_insert_at()

static int pw_map_insert_at ( struct pw_map map,
uint32_t  id,
void *  data 

Insert data in the map at an index.

mapthe map to inser into
idthe index to insert at
datathe data to insert
0 on success, -ENOSPC value when the index is invalid or a < 0 errno value.

References pw_map_item::data, items, pw_array::pw_array_add(), pw_map_get_item, and pw_map_get_size.

Referenced by pw_global::pw_global_bind(), pw_impl_port_add(), pw_resource_destroy(), and pw_resource_new().

◆ pw_map_insert_new()

static uint32_t pw_map_insert_new ( struct pw_map map,
void *  data 

Insert data in the map.

mapthe map to insert into
datathe item to add
the id where the item was inserted or SPA_ID_INVALID when the item can not be inserted.

References pw_array::data, pw_map_item::data, free_list, id, items, pw_map_item::next, and pw_array::pw_array_add().

Referenced by pw_global::pw_global_new(), pw_impl_node_get_free_port_id(), pw_impl_port_init_mix(), and pw_proxy_init().

◆ pw_map_lookup()

static void * pw_map_lookup ( struct pw_map map,
uint32_t  id 

Find an item in the map.

mapthe map to use
idthe index to look at
the item at id or NULL when no such item exists

References pw_map_item::data, pw_map_check_id, pw_map_get_item, and pw_map_item_is_free.

Referenced by pw_core_find_proxy(), pw_impl_client_find_resource(), pw_impl_node_find_port(), pw_impl_port_add(), pw_mempool_find_id(), pw_mempool_map_id(), and pw_mempool_remove_id().

◆ pw_map_remove()

static void pw_map_remove ( struct pw_map map,
uint32_t  id 

Remove an item at index.

mapthe map to remove from
idthe index to remove

References free_list, and pw_map_get_item.

Referenced by pw_impl_port_release_mix(), pw_memblock::pw_memblock_free(), pw_mempool_remove_id(), and pw_proxy_init().

Field Documentation

◆ free_list

uint32_t pw_map::free_list

the free items

Referenced by pw_map_init(), pw_map_insert_new(), and pw_map_remove().

◆ items

struct pw_array pw_map::items

an array with the map items

Referenced by pw_map_for_each(), pw_map_init(), pw_map_insert_at(), and pw_map_insert_new().

The documentation for this class was generated from the following file: