Remove hlist from kcompat's headers and code
[ust.git] / include / ust / kcompat / kref.h
CommitLineData
17bb07b4
PMF
1#ifndef _KCOMPAT_KREF_H
2#define _KCOMPAT_KREF_H
3
4/*
5 * Kernel sourcecode compatible reference counting implementation
6 *
7 * Copyright (C) 2009 Novell Inc.
8 *
9 * Author: Jan Blunck <jblunck@suse.de>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License version 2.1 as
13 * published by the Free Software Foundation.
14 */
15
16#include <assert.h>
17#include <urcu/uatomic_arch.h>
18
19struct kref {
20 long refcount; /* ATOMIC */
21};
22
23static inline void kref_set(struct kref *ref, int val)
24{
25 uatomic_set(&ref->refcount, val);
26}
27
28static inline void kref_init(struct kref *ref)
29{
30 kref_set(ref, 1);
31}
32
33static inline void kref_get(struct kref *ref)
34{
35 long result = uatomic_add_return(&ref->refcount, 1);
36 assert(result != 0);
37}
38
39static inline void kref_put(struct kref *ref, void (*release)(struct kref *))
40{
41 long res = uatomic_sub_return(&ref->refcount, 1);
42 if (res == 0)
43 release(ref);
44}
45
46#endif /* _KCOMPAT_KREF_H */
This page took 0.026601 seconds and 4 git commands to generate.