summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-hwdb
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-08-27 14:00:01 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-08-28 05:09:40 +0900
commit1c71f7f32940a5f3ec093b0e5a249a04f8c2f163 (patch)
tree12b95ac373e7a711e0dd7db3d411a17cff6701a5 /src/libsystemd/sd-hwdb
parent1d3044e275d9d933ad5a84b7ec259065b2c7e710 (diff)
downloadsystemd-1c71f7f32940a5f3ec093b0e5a249a04f8c2f163.tar.gz
libsystemd: use DEFINE_ATOMIC_REF_UNREF_FUNC or frineds where applicable
Diffstat (limited to 'src/libsystemd/sd-hwdb')
-rw-r--r--src/libsystemd/sd-hwdb/sd-hwdb.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/libsystemd/sd-hwdb/sd-hwdb.c b/src/libsystemd/sd-hwdb/sd-hwdb.c
index 5de716effb..371dac5308 100644
--- a/src/libsystemd/sd-hwdb/sd-hwdb.c
+++ b/src/libsystemd/sd-hwdb/sd-hwdb.c
@@ -359,25 +359,17 @@ _public_ int sd_hwdb_new(sd_hwdb **ret) {
return 0;
}
-_public_ sd_hwdb *sd_hwdb_ref(sd_hwdb *hwdb) {
- assert_return(hwdb, NULL);
-
- assert_se(REFCNT_INC(hwdb->n_ref) >= 2);
+static sd_hwdb *hwdb_free(sd_hwdb *hwdb) {
+ assert(hwdb);
- return hwdb;
+ if (hwdb->map)
+ munmap((void *)hwdb->map, hwdb->st.st_size);
+ safe_fclose(hwdb->f);
+ ordered_hashmap_free(hwdb->properties);
+ return mfree(hwdb);
}
-_public_ sd_hwdb *sd_hwdb_unref(sd_hwdb *hwdb) {
- if (hwdb && REFCNT_DEC(hwdb->n_ref) == 0) {
- if (hwdb->map)
- munmap((void *)hwdb->map, hwdb->st.st_size);
- safe_fclose(hwdb->f);
- ordered_hashmap_free(hwdb->properties);
- free(hwdb);
- }
-
- return NULL;
-}
+DEFINE_PUBLIC_ATOMIC_REF_UNREF_FUNC(sd_hwdb, sd_hwdb, hwdb_free)
bool hwdb_validate(sd_hwdb *hwdb) {
bool found = false;