Deleted Added
full compact
refcount.h (307265) refcount.h (307277)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012 by Delphix. All rights reserved.
23 * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
24 */
25
26#ifndef _SYS_REFCOUNT_H
27#define _SYS_REFCOUNT_H
28
29#include <sys/cdefs.h>
30#include <sys/types.h>
31#include_next <sys/refcount.h>

--- 27 unchanged lines hidden (view full) ---

59 uint64_t rc_count;
60 uint64_t rc_removed_count;
61} refcount_t;
62
63/* Note: refcount_t must be initialized with refcount_create[_untracked]() */
64
65void refcount_create(refcount_t *rc);
66void refcount_create_untracked(refcount_t *rc);
24 */
25
26#ifndef _SYS_REFCOUNT_H
27#define _SYS_REFCOUNT_H
28
29#include <sys/cdefs.h>
30#include <sys/types.h>
31#include_next <sys/refcount.h>

--- 27 unchanged lines hidden (view full) ---

59 uint64_t rc_count;
60 uint64_t rc_removed_count;
61} refcount_t;
62
63/* Note: refcount_t must be initialized with refcount_create[_untracked]() */
64
65void refcount_create(refcount_t *rc);
66void refcount_create_untracked(refcount_t *rc);
67void refcount_create_tracked(refcount_t *rc);
67void refcount_destroy(refcount_t *rc);
68void refcount_destroy_many(refcount_t *rc, uint64_t number);
69int refcount_is_zero(refcount_t *rc);
70int64_t refcount_count(refcount_t *rc);
71int64_t refcount_add(refcount_t *rc, void *holder_tag);
72int64_t refcount_remove(refcount_t *rc, void *holder_tag);
73int64_t refcount_add_many(refcount_t *rc, uint64_t number, void *holder_tag);
74int64_t refcount_remove_many(refcount_t *rc, uint64_t number, void *holder_tag);
75void refcount_transfer(refcount_t *dst, refcount_t *src);
76void refcount_transfer_ownership(refcount_t *, void *, void *);
68void refcount_destroy(refcount_t *rc);
69void refcount_destroy_many(refcount_t *rc, uint64_t number);
70int refcount_is_zero(refcount_t *rc);
71int64_t refcount_count(refcount_t *rc);
72int64_t refcount_add(refcount_t *rc, void *holder_tag);
73int64_t refcount_remove(refcount_t *rc, void *holder_tag);
74int64_t refcount_add_many(refcount_t *rc, uint64_t number, void *holder_tag);
75int64_t refcount_remove_many(refcount_t *rc, uint64_t number, void *holder_tag);
76void refcount_transfer(refcount_t *dst, refcount_t *src);
77void refcount_transfer_ownership(refcount_t *, void *, void *);
78boolean_t refcount_held(refcount_t *, void *);
79boolean_t refcount_not_held(refcount_t *, void *);
77
78void refcount_sysinit(void);
79void refcount_fini(void);
80
81#else /* ZFS_DEBUG */
82
83typedef struct refcount {
84 uint64_t rc_count;
85} refcount_t;
86
87#define refcount_create(rc) ((rc)->rc_count = 0)
88#define refcount_create_untracked(rc) ((rc)->rc_count = 0)
80
81void refcount_sysinit(void);
82void refcount_fini(void);
83
84#else /* ZFS_DEBUG */
85
86typedef struct refcount {
87 uint64_t rc_count;
88} refcount_t;
89
90#define refcount_create(rc) ((rc)->rc_count = 0)
91#define refcount_create_untracked(rc) ((rc)->rc_count = 0)
92#define refcount_create_tracked(rc) ((rc)->rc_count = 0)
89#define refcount_destroy(rc) ((rc)->rc_count = 0)
90#define refcount_destroy_many(rc, number) ((rc)->rc_count = 0)
91#define refcount_is_zero(rc) ((rc)->rc_count == 0)
92#define refcount_count(rc) ((rc)->rc_count)
93#define refcount_add(rc, holder) atomic_inc_64_nv(&(rc)->rc_count)
94#define refcount_remove(rc, holder) atomic_dec_64_nv(&(rc)->rc_count)
95#define refcount_add_many(rc, number, holder) \
96 atomic_add_64_nv(&(rc)->rc_count, number)
97#define refcount_remove_many(rc, number, holder) \
98 atomic_add_64_nv(&(rc)->rc_count, -number)
99#define refcount_transfer(dst, src) { \
100 uint64_t __tmp = (src)->rc_count; \
101 atomic_add_64(&(src)->rc_count, -__tmp); \
102 atomic_add_64(&(dst)->rc_count, __tmp); \
103}
104#define refcount_transfer_ownership(rc, current_holder, new_holder)
93#define refcount_destroy(rc) ((rc)->rc_count = 0)
94#define refcount_destroy_many(rc, number) ((rc)->rc_count = 0)
95#define refcount_is_zero(rc) ((rc)->rc_count == 0)
96#define refcount_count(rc) ((rc)->rc_count)
97#define refcount_add(rc, holder) atomic_inc_64_nv(&(rc)->rc_count)
98#define refcount_remove(rc, holder) atomic_dec_64_nv(&(rc)->rc_count)
99#define refcount_add_many(rc, number, holder) \
100 atomic_add_64_nv(&(rc)->rc_count, number)
101#define refcount_remove_many(rc, number, holder) \
102 atomic_add_64_nv(&(rc)->rc_count, -number)
103#define refcount_transfer(dst, src) { \
104 uint64_t __tmp = (src)->rc_count; \
105 atomic_add_64(&(src)->rc_count, -__tmp); \
106 atomic_add_64(&(dst)->rc_count, __tmp); \
107}
108#define refcount_transfer_ownership(rc, current_holder, new_holder)
109#define refcount_held(rc, holder) ((rc)->rc_count > 0)
110#define refcount_not_held(rc, holder) (B_TRUE)
105
106#define refcount_sysinit()
107#define refcount_fini()
108
109#endif /* ZFS_DEBUG */
110
111#ifdef __cplusplus
112}
113#endif
114
115#endif /* _SYS_REFCOUNT_H */
111
112#define refcount_sysinit()
113#define refcount_fini()
114
115#endif /* ZFS_DEBUG */
116
117#ifdef __cplusplus
118}
119#endif
120
121#endif /* _SYS_REFCOUNT_H */