2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2015-07-13 19:47:26 +02:00
|
|
|
#pragma once
|
|
|
|
|
2015-11-30 21:43:37 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2015-07-16 14:06:11 +02:00
|
|
|
#include "hashmap.h"
|
2015-11-18 22:46:33 +01:00
|
|
|
#include "macro.h"
|
2015-07-13 19:47:26 +02:00
|
|
|
|
shared/exit-status: use Bitmap instead of Sets
I opted to embed the Bitmap structure directly in the ExitStatusSet.
This means that memory usage is a bit higher for units which don't define
this setting:
Service changes:
/* size: 2720, cachelines: 43, members: 73 */
/* sum members: 2680, holes: 9, sum holes: 39 */
/* sum bitfield members: 7 bits, bit holes: 1, sum bit holes: 1 bits */
/* last cacheline: 32 bytes */
/* size: 2816, cachelines: 44, members: 73 */
/* sum members: 2776, holes: 9, sum holes: 39 */
/* sum bitfield members: 7 bits, bit holes: 1, sum bit holes: 1 bits */
But this way the code is simpler and we do less pointer chasing.
2019-07-28 11:14:46 +02:00
|
|
|
typedef struct Bitmap {
|
|
|
|
uint64_t *bitmaps;
|
|
|
|
size_t n_bitmaps;
|
|
|
|
size_t bitmaps_allocated;
|
|
|
|
} Bitmap;
|
2015-07-13 19:47:26 +02:00
|
|
|
|
|
|
|
Bitmap *bitmap_new(void);
|
2016-06-20 21:24:46 +02:00
|
|
|
Bitmap *bitmap_copy(Bitmap *b);
|
2015-07-13 19:47:26 +02:00
|
|
|
int bitmap_ensure_allocated(Bitmap **b);
|
2016-06-20 21:24:46 +02:00
|
|
|
void bitmap_free(Bitmap *b);
|
2015-07-13 19:47:26 +02:00
|
|
|
|
|
|
|
int bitmap_set(Bitmap *b, unsigned n);
|
|
|
|
void bitmap_unset(Bitmap *b, unsigned n);
|
2019-07-28 11:04:12 +02:00
|
|
|
bool bitmap_isset(const Bitmap *b, unsigned n);
|
|
|
|
bool bitmap_isclear(const Bitmap *b);
|
2015-07-13 19:47:26 +02:00
|
|
|
void bitmap_clear(Bitmap *b);
|
|
|
|
|
2019-07-28 11:04:12 +02:00
|
|
|
bool bitmap_iterate(const Bitmap *b, Iterator *i, unsigned *n);
|
2015-07-13 19:47:26 +02:00
|
|
|
|
2019-07-28 11:04:12 +02:00
|
|
|
bool bitmap_equal(const Bitmap *a, const Bitmap *b);
|
2015-07-13 19:47:26 +02:00
|
|
|
|
2015-07-16 14:06:11 +02:00
|
|
|
#define BITMAP_FOREACH(n, b, i) \
|
|
|
|
for ((i).idx = 0; bitmap_iterate((b), &(i), (unsigned*)&(n)); )
|
2015-07-13 19:47:26 +02:00
|
|
|
|
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(Bitmap*, bitmap_free);
|
|
|
|
|
|
|
|
#define _cleanup_bitmap_free_ _cleanup_(bitmap_freep)
|