summaryrefslogtreecommitdiff
path: root/tirpc/rpc/auth.h
diff options
context:
space:
mode:
Diffstat (limited to 'tirpc/rpc/auth.h')
-rw-r--r--tirpc/rpc/auth.h35
1 files changed, 31 insertions, 4 deletions
diff --git a/tirpc/rpc/auth.h b/tirpc/rpc/auth.h
index f669ae4..5f66e67 100644
--- a/tirpc/rpc/auth.h
+++ b/tirpc/rpc/auth.h
@@ -203,8 +203,22 @@ typedef struct __auth {
} *ah_ops;
void *ah_private;
+ int ah_refcnt;
} AUTH;
+static __inline int
+auth_get(AUTH *auth)
+{
+ return __sync_add_and_fetch(&auth->ah_refcnt, 1);
+}
+
+static __inline int
+auth_put(AUTH *auth)
+{
+ return __sync_sub_and_fetch(&auth->ah_refcnt, 1);
+}
+
+
/*
* Authentication ops.
@@ -234,10 +248,23 @@ typedef struct __auth {
#define auth_refresh(auth, msg) \
((*((auth)->ah_ops->ah_refresh))(auth, msg))
-#define AUTH_DESTROY(auth) \
- ((*((auth)->ah_ops->ah_destroy))(auth))
-#define auth_destroy(auth) \
- ((*((auth)->ah_ops->ah_destroy))(auth))
+#define AUTH_DESTROY(auth) \
+ do { \
+ int refs; \
+ if ((refs = auth_put((auth))) == 0) \
+ ((*((auth)->ah_ops->ah_destroy))(auth));\
+ log_debug("%s: auth_put(), refs %d\n", \
+ __func__, refs); \
+ } while (0)
+
+#define auth_destroy(auth) \
+ do { \
+ int refs; \
+ if ((refs = auth_put((auth))) == 0) \
+ ((*((auth)->ah_ops->ah_destroy))(auth));\
+ log_debug("%s: auth_put(), refs %d\n", \
+ __func__, refs); \
+ } while (0)
#define AUTH_WRAP(auth, xdrs, xfunc, xwhere) \
((*((auth)->ah_ops->ah_wrap))(auth, xdrs, \