summaryrefslogtreecommitdiffstats
path: root/sys/ofed
diff options
context:
space:
mode:
authorhselasky <hselasky@FreeBSD.org>2015-10-19 12:26:38 +0000
committerhselasky <hselasky@FreeBSD.org>2015-10-19 12:26:38 +0000
commitfd834c513a221af10224dd38154b74cde2b57c62 (patch)
tree9085faf590b9c360afab9220d90c842a4c4d8147 /sys/ofed
parentc2a6426cb9ffa31713523a61187c8876c801ed54 (diff)
downloadFreeBSD-src-fd834c513a221af10224dd38154b74cde2b57c62.zip
FreeBSD-src-fd834c513a221af10224dd38154b74cde2b57c62.tar.gz
Merge LinuxKPI changes from DragonflyBSD:
- Define the kref structure identical to the one found in Linux. - Update clients referring inside the kref structure. - Implement kref_sub() for FreeBSD. Reviewed by: np @ Sponsored by: Mellanox Technologies
Diffstat (limited to 'sys/ofed')
-rw-r--r--sys/ofed/drivers/infiniband/core/uverbs_main.c2
-rw-r--r--sys/ofed/include/linux/kref.h34
2 files changed, 30 insertions, 6 deletions
diff --git a/sys/ofed/drivers/infiniband/core/uverbs_main.c b/sys/ofed/drivers/infiniband/core/uverbs_main.c
index 12bc0d3..5a6b605 100644
--- a/sys/ofed/drivers/infiniband/core/uverbs_main.c
+++ b/sys/ofed/drivers/infiniband/core/uverbs_main.c
@@ -1168,7 +1168,7 @@ static ssize_t show_dev_ref_cnt(struct device *device,
if (!dev)
return -ENODEV;
- return sprintf(buf, "%d\n", dev->ref.count);
+ return sprintf(buf, "%d\n", atomic_read(&dev->ref.refcount));
}
static DEVICE_ATTR(ref_cnt, S_IRUGO, show_dev_ref_cnt, NULL);
diff --git a/sys/ofed/include/linux/kref.h b/sys/ofed/include/linux/kref.h
index 883e1a1..ecf3c8a 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_ */
OpenPOWER on IntegriCloud