aboutsummaryrefslogtreecommitdiff
path: root/sys/ofed/include/linux
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2015-10-19 12:26:38 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2015-10-19 12:26:38 +0000
commitf556cede8a28b82b59b4f598d0fb3d04a2160934 (patch)
tree9085faf590b9c360afab9220d90c842a4c4d8147 /sys/ofed/include/linux
parent35d974cd0ca62319e4e7fc75f4df098a7a88aa4d (diff)
Notes
Diffstat (limited to 'sys/ofed/include/linux')
-rw-r--r--sys/ofed/include/linux/kref.h34
1 files changed, 29 insertions, 5 deletions
diff --git a/sys/ofed/include/linux/kref.h b/sys/ofed/include/linux/kref.h
index 883e1a1dceb4..ecf3c8a753a7 100644
--- a/sys/ofed/include/linux/kref.h
+++ b/sys/ofed/include/linux/kref.h
@@ -2,7 +2,8 @@
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2010 iX Systems, Inc.
* Copyright (c) 2010 Panasas, Inc.
- * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
+ * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
+ * Copyright (c) 2013 François Tigeot
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -32,33 +33,56 @@
#include <sys/types.h>
#include <sys/refcount.h>
+#include <asm/atomic.h>
+
struct kref {
- volatile u_int count;
+ atomic_t refcount;
};
static inline void
kref_init(struct kref *kref)
{
- refcount_init(&kref->count, 1);
+ refcount_init(&kref->refcount.counter, 1);
}
static inline void
kref_get(struct kref *kref)
{
- refcount_acquire(&kref->count);
+ refcount_acquire(&kref->refcount.counter);
}
static inline int
kref_put(struct kref *kref, void (*rel)(struct kref *kref))
{
- if (refcount_release(&kref->count)) {
+ if (refcount_release(&kref->refcount.counter)) {
rel(kref);
return 1;
}
return 0;
}
+static inline int
+kref_sub(struct kref *kref, unsigned int count,
+ void (*rel)(struct kref *kref))
+{
+
+ while (count--) {
+ if (refcount_release(&kref->refcount.counter)) {
+ rel(kref);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static inline int __must_check
+kref_get_unless_zero(struct kref *kref)
+{
+
+ return atomic_add_unless(&kref->refcount, 1, 0);
+}
+
#endif /* _LINUX_KREF_H_ */