Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178095684
D62140.1795946661.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
D62140.1795946661.diff
View Options
diff --git a/sys/kern/subr_epoch.c b/sys/kern/subr_epoch.c
--- a/sys/kern/subr_epoch.c
+++ b/sys/kern/subr_epoch.c
@@ -38,6 +38,7 @@
#include <sys/mutex.h>
#include <sys/pcpu.h>
#include <sys/proc.h>
+#include <sys/refcount.h>
#include <sys/sched.h>
#include <sys/sx.h>
#include <sys/smp.h>
@@ -86,7 +87,7 @@
int e_flags;
struct sx e_drain_sx;
struct mtx e_drain_mtx;
- volatile int e_drain_count;
+ volatile u_int e_drain_count;
const char *e_name;
};
@@ -958,11 +959,18 @@
struct epoch *epoch =
__containerof(ctx, struct epoch_record, er_drain_ctx)->er_parent;
- if (atomic_fetchadd_int(&epoch->e_drain_count, -1) == 1) {
- mtx_lock(&epoch->e_drain_mtx);
+ /*
+ * Each CPU's callback drops the count once, so the one that finds it
+ * at one is the last. The drainer reads the count only with the
+ * drain mutex held and may free the epoch as soon as it sees zero,
+ * so the last callback drops it with the mutex held.
+ */
+ if (refcount_release_if_not_last(&epoch->e_drain_count))
+ return;
+ mtx_lock(&epoch->e_drain_mtx);
+ if (refcount_release(&epoch->e_drain_count))
wakeup(epoch);
- mtx_unlock(&epoch->e_drain_mtx);
- }
+ mtx_unlock(&epoch->e_drain_mtx);
}
void
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 29, 10:04 AM (5 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42067341
Default Alt Text
D62140.1795946661.diff (1 KB)
Attached To
Mode
D62140: epoch: Zero the drain count under the drain mutex
Attached
Detach File
Event Timeline