diff options
author | Abseil Team <absl-team@google.com> | 2022-11-16 11:05:21 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-11-16 11:06:21 -0800 |
commit | 4b48854949f8bf9afb871c293a9022331a0b77c7 (patch) | |
tree | 768ae9ca20e921fbce962adce0cad17bf409eea6 /absl/synchronization/mutex.h | |
parent | 76fa844139fb04958a9682f34e3b3d0e4943ae5f (diff) | |
download | abseil-4b48854949f8bf9afb871c293a9022331a0b77c7.tar.gz abseil-4b48854949f8bf9afb871c293a9022331a0b77c7.tar.bz2 abseil-4b48854949f8bf9afb871c293a9022331a0b77c7.zip |
Update Condition to allocate 24 bytes for MSVC platform pointers to methods.
PiperOrigin-RevId: 488986942
Change-Id: I2babb7ea30d60c544f55ca9ed02d9aed23051a12
Diffstat (limited to 'absl/synchronization/mutex.h')
-rw-r--r-- | absl/synchronization/mutex.h | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/absl/synchronization/mutex.h b/absl/synchronization/mutex.h index 54ee703a..779aafa0 100644 --- a/absl/synchronization/mutex.h +++ b/absl/synchronization/mutex.h @@ -751,21 +751,19 @@ class Condition { // multiple inheritance are bigger than those of classes with single // inheritance. Other variations also exist. - // A good way to allocate enough space for *any* pointer in these ABIs is to - // employ a class declaration with no definition. Because the inheritance - // structure is not available for this declaration, the compiler must - // assume, conservatively, that its method pointers have the largest possible - // size. - class OpaqueClass; - using ConservativeMethodPointer = bool (OpaqueClass::*)(); - static_assert(sizeof(bool(OpaqueClass::*)()) >= sizeof(bool (*)(void *)), - "Unsupported platform."); - +#ifndef _MSC_VER // Allocation for a function pointer or method pointer. // The {0} initializer ensures that all unused bytes of this buffer are // always zeroed out. This is necessary, because GuaranteedEqual() compares // all of the bytes, unaware of which bytes are relevant to a given `eval_`. - char callback_[sizeof(ConservativeMethodPointer)] = {0}; + using MethodPtr = bool (Condition::*)(); + char callback_[sizeof(MethodPtr)] = {0}; +#else + // It is well known that the larget MSVC pointer-to-member is 24 bytes. This + // may be the largest known pointer-to-member of any platform. For this + // reason we will allocate 24 bytes for MSVC platform toolchains. + char callback_[24] = {0}; +#endif // Function with which to evaluate callbacks and/or arguments. bool (*eval_)(const Condition*); |