From: Christopher Dykes Date: Thu, 26 Oct 2017 19:15:55 +0000 (-0700) Subject: Just use a volatile static in Malloc.h X-Git-Tag: v2017.10.30.00~11 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a15fcb1e76444f7d464b263ad37bf3b5fbfdf33e;p=folly.git Just use a volatile static in Malloc.h Summary: As suggested late in the initial diff (D5840883), just mark it volatile, as it works under all supported platforms. Reviewed By: davidtgoldblatt, yfeldblum Differential Revision: D6155241 fbshipit-source-id: 00c07a11dc7fc2e33c2d1f9a45fd28006eeff6f9 --- diff --git a/folly/memory/Malloc.h b/folly/memory/Malloc.h index 2726c9d8..5bad7484 100644 --- a/folly/memory/Malloc.h +++ b/folly/memory/Malloc.h @@ -183,15 +183,12 @@ FOLLY_MALLOC_NOINLINE inline bool usingJEMalloc() noexcept { uint64_t origAllocated = *counter; - const void* ptr = malloc(1); + static const void* volatile ptr = malloc(1); if (!ptr) { // wtf, failing to allocate 1 byte return false; } - /* Avoid optimizing away the malloc. */ - asm volatile("" ::"m"(ptr) : "memory"); - return (origAllocated != *counter); }();