Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: third_party/tcmalloc/chromium/src/base/basictypes.h

Issue 9667026: Revert 126020 - Experiment for updating the tcmalloc chromium branch to r144 (gperftools 2.0). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2005, Google Inc. 1 // Copyright (c) 2005, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 #ifndef _BASICTYPES_H_ 30 #ifndef _BASICTYPES_H_
31 #define _BASICTYPES_H_ 31 #define _BASICTYPES_H_
32 32
33 #include <config.h> 33 #include <config.h>
34 #include <string.h> // for memcpy()
35 #ifdef HAVE_INTTYPES_H 34 #ifdef HAVE_INTTYPES_H
36 #include <inttypes.h> // gets us PRId64, etc 35 #include <inttypes.h> // gets us PRId64, etc
37 #endif 36 #endif
38 37
39 // To use this in an autoconf setting, make sure you run the following 38 // To use this in an autoconf setting, make sure you run the following
40 // autoconf macros: 39 // autoconf macros:
41 // AC_HEADER_STDC /* for stdint_h and inttypes_h */ 40 // AC_HEADER_STDC /* for stdint_h and inttypes_h */
42 // AC_CHECK_TYPES([__int64]) /* defined in some windows platforms */ 41 // AC_CHECK_TYPES([__int64]) /* defined in some windows platforms */
43 42
44 #ifdef HAVE_INTTYPES_H 43 #ifdef HAVE_INTTYPES_H
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 186
188 #define COMPILE_ASSERT(expr, msg) \ 187 #define COMPILE_ASSERT(expr, msg) \
189 typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] 188 typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
190 189
191 #define arraysize(a) (sizeof(a) / sizeof(*(a))) 190 #define arraysize(a) (sizeof(a) / sizeof(*(a)))
192 191
193 #define OFFSETOF_MEMBER(strct, field) \ 192 #define OFFSETOF_MEMBER(strct, field) \
194 (reinterpret_cast<char*>(&reinterpret_cast<strct*>(16)->field) - \ 193 (reinterpret_cast<char*>(&reinterpret_cast<strct*>(16)->field) - \
195 reinterpret_cast<char*>(16)) 194 reinterpret_cast<char*>(16))
196 195
197 // bit_cast<Dest,Source> implements the equivalent of
198 // "*reinterpret_cast<Dest*>(&source)".
199 //
200 // The reinterpret_cast method would produce undefined behavior
201 // according to ISO C++ specification section 3.10 -15 -.
202 // bit_cast<> calls memcpy() which is blessed by the standard,
203 // especially by the example in section 3.9.
204 //
205 // Fortunately memcpy() is very fast. In optimized mode, with a
206 // constant size, gcc 2.95.3, gcc 4.0.1, and msvc 7.1 produce inline
207 // code with the minimal amount of data movement. On a 32-bit system,
208 // memcpy(d,s,4) compiles to one load and one store, and memcpy(d,s,8)
209 // compiles to two loads and two stores.
210
211 template <class Dest, class Source>
212 inline Dest bit_cast(const Source& source) {
213 COMPILE_ASSERT(sizeof(Dest) == sizeof(Source), bitcasting_unequal_sizes);
214 Dest dest;
215 memcpy(&dest, &source, sizeof(dest));
216 return dest;
217 }
218
219 #ifdef HAVE___ATTRIBUTE__ 196 #ifdef HAVE___ATTRIBUTE__
220 # define ATTRIBUTE_WEAK __attribute__((weak)) 197 # define ATTRIBUTE_WEAK __attribute__((weak))
221 # define ATTRIBUTE_NOINLINE __attribute__((noinline)) 198 # define ATTRIBUTE_NOINLINE __attribute__((noinline))
222 #else 199 #else
223 # define ATTRIBUTE_WEAK 200 # define ATTRIBUTE_WEAK
224 # define ATTRIBUTE_NOINLINE 201 # define ATTRIBUTE_NOINLINE
225 #endif 202 #endif
226 203
227 // Section attributes are supported for both ELF and Mach-O, but in 204 // Section attributes are supported for both ELF and Mach-O, but in
228 // very different ways. Here's the API we provide: 205 // very different ways. Here's the API we provide:
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 # define ATTRIBUTE_SECTION(name) 302 # define ATTRIBUTE_SECTION(name)
326 # define DECLARE_ATTRIBUTE_SECTION_VARS(name) 303 # define DECLARE_ATTRIBUTE_SECTION_VARS(name)
327 # define INIT_ATTRIBUTE_SECTION_VARS(name) 304 # define INIT_ATTRIBUTE_SECTION_VARS(name)
328 # define DEFINE_ATTRIBUTE_SECTION_VARS(name) 305 # define DEFINE_ATTRIBUTE_SECTION_VARS(name)
329 # define ATTRIBUTE_SECTION_START(name) (reinterpret_cast<void*>(0)) 306 # define ATTRIBUTE_SECTION_START(name) (reinterpret_cast<void*>(0))
330 # define ATTRIBUTE_SECTION_STOP(name) (reinterpret_cast<void*>(0)) 307 # define ATTRIBUTE_SECTION_STOP(name) (reinterpret_cast<void*>(0))
331 308
332 #endif // HAVE___ATTRIBUTE__ and __ELF__ or __MACH__ 309 #endif // HAVE___ATTRIBUTE__ and __ELF__ or __MACH__
333 310
334 #if defined(HAVE___ATTRIBUTE__) && (defined(__i386__) || defined(__x86_64__)) 311 #if defined(HAVE___ATTRIBUTE__) && (defined(__i386__) || defined(__x86_64__))
335 # define CACHELINE_ALIGNED __attribute__((aligned(64))) 312 # define CACHELINE_SIZE 64
313 # define CACHELINE_ALIGNED __attribute__((aligned(CACHELINE_SIZE)))
336 #else 314 #else
337 # define CACHELINE_ALIGNED 315 # define CACHELINE_ALIGNED
338 #endif // defined(HAVE___ATTRIBUTE__) && (__i386__ || __x86_64__) 316 #endif // defined(HAVE___ATTRIBUTE__) && (__i386__ || __x86_64__)
339 317
340 318
341 // The following enum should be used only as a constructor argument to indicate 319 // The following enum should be used only as a constructor argument to indicate
342 // that the variable has static storage class, and that the constructor should 320 // that the variable has static storage class, and that the constructor should
343 // do nothing to its state. It indicates to the reader that it is legal to 321 // do nothing to its state. It indicates to the reader that it is legal to
344 // declare a static nistance of the class, provided the constructor is given 322 // declare a static nistance of the class, provided the constructor is given
345 // the base::LINKER_INITIALIZED argument. Normally, it is unsafe to declare a 323 // the base::LINKER_INITIALIZED argument. Normally, it is unsafe to declare a
346 // static variable that has a constructor or a destructor because invocation 324 // static variable that has a constructor or a destructor because invocation
347 // order is undefined. However, IF the type can be initialized by filling with 325 // order is undefined. However, IF the type can be initialized by filling with
348 // zeroes (which the loader does for static variables), AND the destructor also 326 // zeroes (which the loader does for static variables), AND the destructor also
349 // does nothing to the storage, then a constructor declared as 327 // does nothing to the storage, then a constructor declared as
350 // explicit MyClass(base::LinkerInitialized x) {} 328 // explicit MyClass(base::LinkerInitialized x) {}
351 // and invoked as 329 // and invoked as
352 // static MyClass my_variable_name(base::LINKER_INITIALIZED); 330 // static MyClass my_variable_name(base::LINKER_INITIALIZED);
353 namespace base { 331 namespace base {
354 enum LinkerInitialized { LINKER_INITIALIZED }; 332 enum LinkerInitialized { LINKER_INITIALIZED };
355 } 333 }
356 334
357 #endif // _BASICTYPES_H_ 335 #endif // _BASICTYPES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698