2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/base/surprise-flags.h"
19 #include <type_traits>
23 // NoHandleSurpriseScope is only implemented in DEBUG mode.
27 __thread
int64_t tl_noSurpriseDepth
[sizeof(SurpriseFlag
)] = {0,};
28 // Cache of flags with depth > 0.
29 __thread SurpriseFlag tl_noSurpriseMask
= static_cast<SurpriseFlag
>(0);
31 void addNoSurpriseDepth(SurpriseFlag flags
, int increment
) {
32 typename
std::underlying_type
<SurpriseFlag
>::type mask
= 0;
33 for (size_t i
= 0; i
< sizeof(flags
); ++i
) {
34 if (flags
& (1ull << i
)) tl_noSurpriseDepth
[i
] += increment
;
35 if (tl_noSurpriseDepth
[i
] > 0) mask
|= (1ull << i
);
37 tl_noSurpriseMask
= static_cast<SurpriseFlag
>(mask
);
42 void NoHandleSurpriseScope::AssertNone(SurpriseFlag flags
) {
43 assertx((flags
& tl_noSurpriseMask
) == 0);
46 NoHandleSurpriseScope::NoHandleSurpriseScope(SurpriseFlag flags
) {
48 addNoSurpriseDepth(m_flags
, 1);
51 NoHandleSurpriseScope::~NoHandleSurpriseScope() {
52 addNoSurpriseDepth(m_flags
, -1);