1a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org/*
2a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org *
4a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org *  Use of this source code is governed by a BSD-style license
5a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org *  that can be found in the LICENSE file in the root of the source
6a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org *  tree. An additional intellectual property rights grant can be found
7a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org *  in the file PATENTS.  All contributing project authors may
8a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
9a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org */
10b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
11b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org// Various inline functions and macros to fix compilation of 32 bit target
12b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org// on MSVC with /Wp64 flag enabled.
13b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
14b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org// The original code can be found here:
15b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org// http://src.chromium.org/svn/trunk/src/base/fix_wp64.h
16b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
17b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_FIX_INTERLOCKED_EXCHANGE_POINTER_WINDOWS_H_
18b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_FIX_INTERLOCKED_EXCHANGE_POINTER_WINDOWS_H_
19b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
20b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org#include <windows.h>
21b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
22b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org// Platform SDK fixes when building with /Wp64 for a 32 bits target.
23b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org#if !defined(_WIN64) && defined(_Wp64)
24b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
25b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org#ifdef InterlockedExchangePointer
26b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org#undef InterlockedExchangePointer
27b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org// The problem is that the macro provided for InterlockedExchangePointer() is
28b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org// doing a (LONG) C-style cast that triggers invariably the warning C4312 when
29b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org// building on 32 bits.
30b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.orginline void* InterlockedExchangePointer(void* volatile* target, void* value) {
31b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org  return reinterpret_cast<void*>(static_cast<LONG_PTR>(InterlockedExchange(
32b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org      reinterpret_cast<volatile LONG*>(target),
33b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org      static_cast<LONG>(reinterpret_cast<LONG_PTR>(value)))));
34b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org}
35b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org#endif  // #ifdef InterlockedExchangePointer
36b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
37b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org#endif // #if !defined(_WIN64) && defined(_Wp64)
38b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
39b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_FIX_INTERLOCKED_EXCHANGE_POINTER_WINDOWS_H_
40