1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/core/SkDynamicAnnotations.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,46 @@ 1.4 +/* 1.5 + * Copyright 2014 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef SkDynamicAnnotations_DEFINED 1.12 +#define SkDynamicAnnotations_DEFINED 1.13 + 1.14 +// This file contains macros used to send out-of-band signals to dynamic instrumentation systems, 1.15 +// namely thread sanitizer. This is a cut-down version of the full dynamic_annotations library with 1.16 +// only the features used by Skia. 1.17 + 1.18 +// We check the same define to know to enable the annotations, but prefix all our macros with SK_. 1.19 +#if DYNAMIC_ANNOTATIONS_ENABLED 1.20 + 1.21 +extern "C" { 1.22 +// TSAN provides these hooks. 1.23 +void AnnotateIgnoreReadsBegin(const char* file, int line); 1.24 +void AnnotateIgnoreReadsEnd(const char* file, int line); 1.25 +} // extern "C" 1.26 + 1.27 +// SK_ANNOTATE_UNPROTECTED_READ can wrap any variable read to tell TSAN to ignore that it appears to 1.28 +// be a racy read. This should be used only when we can make an external guarantee that though this 1.29 +// particular read is racy, it is being used as part of a mechanism which is thread safe. Examples: 1.30 +// - the first check in double-checked locking; 1.31 +// - checking if a ref count is equal to 1. 1.32 +// Note that in both these cases, we must still add terrifyingly subtle memory barriers to provide 1.33 +// that overall thread safety guarantee. Using this macro to shut TSAN up without providing such an 1.34 +// external guarantee is pretty much never correct. 1.35 +template <typename T> 1.36 +inline T SK_ANNOTATE_UNPROTECTED_READ(const volatile T& x) { 1.37 + AnnotateIgnoreReadsBegin(__FILE__, __LINE__); 1.38 + T read = x; 1.39 + AnnotateIgnoreReadsEnd(__FILE__, __LINE__); 1.40 + return read; 1.41 +} 1.42 + 1.43 +#else // !DYNAMIC_ANNOTATIONS_ENABLED 1.44 + 1.45 +#define SK_ANNOTATE_UNPROTECTED_READ(x) (x) 1.46 + 1.47 +#endif 1.48 + 1.49 +#endif//SkDynamicAnnotations_DEFINED