Fix VS 2015 warning by adding an additional cast

The OwningThread member of CRITICAL_SECTION is declared as having type
HANDLE but it is actually the thread's Thread ID which is a DWORD. When
doing 64-bit builds of Chromium with VS 2015 this triggers a warning
because of the suspicious conversion from 32-bit integer to 64-bit
pointer.

This change adds a cast (and some comments) to make the conversion
explicit and avoid the warning.

R=henrikg@webrtc.org
BUG=440500

Review URL: https://codereview.webrtc.org/1386183002

Cr-Commit-Position: refs/heads/master@{#10190}
This commit is contained in:
brucedawson
2015-10-06 13:34:30 -07:00
committed by Commit bot
parent 4139c0f1c5
commit a10492ff33

View File

@ -88,7 +88,12 @@ void CriticalSection::Leave() UNLOCK_FUNCTION() {
bool CriticalSection::CurrentThreadIsOwner() const {
#if defined(WEBRTC_WIN)
return crit_.OwningThread == reinterpret_cast<HANDLE>(GetCurrentThreadId());
// OwningThread has type HANDLE but actually contains the Thread ID:
// http://stackoverflow.com/questions/12675301/why-is-the-owningthread-member-of-critical-section-of-type-handle-when-it-is-de
// Converting through size_t avoids the VS 2015 warning C4312: conversion from
// 'type1' to 'type2' of greater size
return crit_.OwningThread ==
reinterpret_cast<HANDLE>(static_cast<size_t>(GetCurrentThreadId()));
#else
#if CS_DEBUG_CHECKS
return pthread_equal(thread_, pthread_self());