Hid inline assembly behind a macro

pull/35/head
Jeffrey Walton 2015-08-01 18:02:03 -04:00
parent ad352c64e0
commit 390d27b6cd
2 changed files with 14 additions and 5 deletions

11
misc.h
View File

@ -61,6 +61,17 @@
# pragma GCC diagnostic ignored "-Wunused-parameter" # pragma GCC diagnostic ignored "-Wunused-parameter"
#endif #endif
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
# pragma intrinsic(_ReadWriteBarrier)
# define MEMORY_BARRIER() _ReadWriteBarrier()
#elif defined(_INTEL_COMPILER)
# define MEMORY_BARRIER() __memory_barrier()
#elif defined(__GNUC__) || defined(__clang__)
# define MEMORY_BARRIER() __asm__ __volatile__ ("" ::: "memory")
#else
# define MEMORY_BARRIER()
#endif
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
// ************** compile-time assertion *************** // ************** compile-time assertion ***************

View File

@ -3,6 +3,7 @@
#include "config.h" #include "config.h"
#include "stdcpp.h" #include "stdcpp.h"
#include "misc.h"
#include "trap.h" #include "trap.h"
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
@ -51,11 +52,8 @@ template <class T> simple_ptr<T>::~simple_ptr()
delete m_p; delete m_p;
m_p = NULL; m_p = NULL;
#ifdef __GNUC__ // https://github.com/weidai11/cryptopp/issues/6
// From Andrew Haley (GCC Dev), to tame the optimizer so the assignment is always performed. MEMORY_BARRIER();
// See "Disable optimizations in one function" on the GCC mailing list.
asm volatile ("" : : : "memory");
#endif
} }
template <class T> class member_ptr template <class T> class member_ptr