From: Andrew Krieger Date: Tue, 29 Aug 2017 05:30:39 +0000 (-0700) Subject: Implement folly::launder for MSVC X-Git-Tag: v2017.09.04.00~16 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b3aabafd2d5306d85105bcdb55b2c2422628ecaa;p=folly.git Implement folly::launder for MSVC Summary: This implementation should suffice for MSVC. _ReadWriteBarrier() generates no instructions but instructs the compiler not to reorder accesses around it, and we have to rely on MSVC not currently having any other optimizations for const members to worry about. Reviewed By: yfeldblum Differential Revision: D5723782 fbshipit-source-id: a68caa4673a5c410b326c1d2e3c0752bd945f4a6 --- diff --git a/folly/Launder.h b/folly/Launder.h index 6a3b976d..fb0e5f7a 100644 --- a/folly/Launder.h +++ b/folly/Launder.h @@ -35,6 +35,11 @@ FOLLY_NODISCARD inline T* launder(T* in) noexcept { // so the compiler has to assume that it has been changed inside the block. __asm__("" : "+r"(in)); return in; +#elif defined(_WIN32) + // MSVC does not currently have optimizations around const members of structs. + // _ReadWriteBarrier() will prevent compiler reordering memory accesses. + _ReadWriteBarrier(); + return in; #else static_assert( false, "folly::launder is not implemented for this environment");