20
20
*/
21
21
/*
22
22
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23
+ * Copyright (c) 2014 by Delphix. All rights reserved.
23
24
*/
24
25
25
26
/*
43
44
* A ZRL can be locked only while there are zero references, so ZRL_LOCKED is
44
45
* treated as zero references.
45
46
*/
46
- #define ZRL_LOCKED ((uint32_t)-1)
47
+ #define ZRL_LOCKED -1
47
48
#define ZRL_DESTROYED -2
48
49
49
50
void
@@ -61,7 +62,7 @@ zrl_init(zrlock_t *zrl)
61
62
void
62
63
zrl_destroy (zrlock_t * zrl )
63
64
{
64
- ASSERT (zrl -> zr_refcount == 0 );
65
+ ASSERT0 (zrl -> zr_refcount );
65
66
66
67
mutex_destroy (& zrl -> zr_mtx );
67
68
zrl -> zr_refcount = ZRL_DESTROYED ;
@@ -81,7 +82,7 @@ zrl_add(zrlock_t *zrl)
81
82
uint32_t cas = atomic_cas_32 (
82
83
(uint32_t * )& zrl -> zr_refcount , n , n + 1 );
83
84
if (cas == n ) {
84
- ASSERT ((int32_t )n >= 0 );
85
+ ASSERT3S ((int32_t )n , >=, 0 );
85
86
#ifdef ZFS_DEBUG
86
87
if (zrl -> zr_owner == curthread ) {
87
88
DTRACE_PROBE2 (zrlock__reentry ,
@@ -99,7 +100,7 @@ zrl_add(zrlock_t *zrl)
99
100
while (zrl -> zr_refcount == ZRL_LOCKED ) {
100
101
cv_wait (& zrl -> zr_cv , & zrl -> zr_mtx );
101
102
}
102
- ASSERT (zrl -> zr_refcount >= 0 );
103
+ ASSERT3S (zrl -> zr_refcount , >=, 0 );
103
104
zrl -> zr_refcount ++ ;
104
105
#ifdef ZFS_DEBUG
105
106
zrl -> zr_owner = curthread ;
@@ -113,14 +114,14 @@ zrl_remove(zrlock_t *zrl)
113
114
{
114
115
uint32_t n ;
115
116
116
- n = atomic_dec_32_nv ((uint32_t * )& zrl -> zr_refcount );
117
- ASSERT ((int32_t )n >= 0 );
118
117
#ifdef ZFS_DEBUG
119
118
if (zrl -> zr_owner == curthread ) {
120
119
zrl -> zr_owner = NULL ;
121
120
zrl -> zr_caller = NULL ;
122
121
}
123
122
#endif
123
+ n = atomic_dec_32_nv ((uint32_t * )& zrl -> zr_refcount );
124
+ ASSERT3S ((int32_t )n , >=, 0 );
124
125
}
125
126
126
127
int
@@ -133,26 +134,26 @@ zrl_tryenter(zrlock_t *zrl)
133
134
(uint32_t * )& zrl -> zr_refcount , 0 , ZRL_LOCKED );
134
135
if (cas == 0 ) {
135
136
#ifdef ZFS_DEBUG
136
- ASSERT (zrl -> zr_owner == NULL );
137
+ ASSERT3P (zrl -> zr_owner , = = , NULL );
137
138
zrl -> zr_owner = curthread ;
138
139
#endif
139
140
return (1 );
140
141
}
141
142
}
142
143
143
- ASSERT ((int32_t )n > ZRL_DESTROYED );
144
+ ASSERT3S ((int32_t )n , > , ZRL_DESTROYED );
144
145
145
146
return (0 );
146
147
}
147
148
148
149
void
149
150
zrl_exit (zrlock_t * zrl )
150
151
{
151
- ASSERT (zrl -> zr_refcount == ZRL_LOCKED );
152
+ ASSERT3S (zrl -> zr_refcount , = = , ZRL_LOCKED );
152
153
153
154
mutex_enter (& zrl -> zr_mtx );
154
155
#ifdef ZFS_DEBUG
155
- ASSERT (zrl -> zr_owner == curthread );
156
+ ASSERT3P (zrl -> zr_owner , = = , curthread );
156
157
zrl -> zr_owner = NULL ;
157
158
membar_producer (); /* make sure the owner store happens first */
158
159
#endif
@@ -166,7 +167,7 @@ zrl_refcount(zrlock_t *zrl)
166
167
{
167
168
int n ;
168
169
169
- ASSERT (zrl -> zr_refcount > ZRL_DESTROYED );
170
+ ASSERT3S (zrl -> zr_refcount , > , ZRL_DESTROYED );
170
171
171
172
n = (int )zrl -> zr_refcount ;
172
173
return (n <= 0 ? 0 : n );
@@ -175,15 +176,15 @@ zrl_refcount(zrlock_t *zrl)
175
176
int
176
177
zrl_is_zero (zrlock_t * zrl )
177
178
{
178
- ASSERT (zrl -> zr_refcount > ZRL_DESTROYED );
179
+ ASSERT3S (zrl -> zr_refcount , > , ZRL_DESTROYED );
179
180
180
181
return (zrl -> zr_refcount <= 0 );
181
182
}
182
183
183
184
int
184
185
zrl_is_locked (zrlock_t * zrl )
185
186
{
186
- ASSERT (zrl -> zr_refcount > ZRL_DESTROYED );
187
+ ASSERT3S (zrl -> zr_refcount , > , ZRL_DESTROYED );
187
188
188
189
return (zrl -> zr_refcount == ZRL_LOCKED );
189
190
}
0 commit comments