diff options
author | dwhite <dwhite@FreeBSD.org> | 2005-03-03 02:41:37 +0000 |
---|---|---|
committer | dwhite <dwhite@FreeBSD.org> | 2005-03-03 02:41:37 +0000 |
commit | ac2dd8b794f18323edf3ffedbc2801a1c96ec278 (patch) | |
tree | 7d32629c23e471639588b4aaeb9f116a6e1e6b22 | |
parent | 3ec33a490c4e69e6bb5eb620245695e740311bb9 (diff) | |
download | FreeBSD-src-ac2dd8b794f18323edf3ffedbc2801a1c96ec278.zip FreeBSD-src-ac2dd8b794f18323edf3ffedbc2801a1c96ec278.tar.gz |
Insert volatile cast to discourage gcc from optimizing the read outside
of the while loop.
Suggested by: alc
MFC after: 1 day
-rw-r--r-- | sys/kern/uipc_mbuf.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index 4d832a8..1f6069e 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -234,9 +234,12 @@ mb_free_ext(struct mbuf *m) * This is tricky. We need to make sure to decrement the * refcount in a safe way but to also clean up if we're the * last reference. This method seems to do it without race. + * The volatile cast is required to emit the proper load + * instructions. Otherwise gcc will optimize the read outside + * of the while loop. */ while (dofree == 0) { - cnt = *(m->m_ext.ref_cnt); + cnt = *(volatile u_int *)(m->m_ext.ref_cnt); if (atomic_cmpset_int(m->m_ext.ref_cnt, cnt, cnt - 1)) { if (cnt == 1) dofree = 1; |