• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef WEBRTC_BASE_BASICTYPES_H_
12 #define WEBRTC_BASE_BASICTYPES_H_
13 
14 #include <stddef.h>  // for NULL, size_t
15 #include <stdint.h>  // for uintptr_t and (u)int_t types.
16 
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"  // NOLINT
19 #endif
20 
21 // Detect compiler is for x86 or x64.
22 #if defined(__x86_64__) || defined(_M_X64) || \
23     defined(__i386__) || defined(_M_IX86)
24 #define CPU_X86 1
25 #endif
26 
27 // Detect compiler is for arm.
28 #if defined(__arm__) || defined(_M_ARM)
29 #define CPU_ARM 1
30 #endif
31 
32 #if defined(CPU_X86) && defined(CPU_ARM)
33 #error CPU_X86 and CPU_ARM both defined.
34 #endif
35 
36 #if !defined(RTC_ARCH_CPU_BIG_ENDIAN) && !defined(RTC_ARCH_CPU_LITTLE_ENDIAN)
37 // x86, arm or GCC provided __BYTE_ORDER__ macros
38 #if CPU_X86 || CPU_ARM ||  \
39   (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
40 #define RTC_ARCH_CPU_LITTLE_ENDIAN
41 #elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
42 #define RTC_ARCH_CPU_BIG_ENDIAN
43 #else
44 #error RTC_ARCH_CPU_BIG_ENDIAN or RTC_ARCH_CPU_LITTLE_ENDIAN should be defined.
45 #endif
46 #endif
47 
48 #if defined(RTC_ARCH_CPU_BIG_ENDIAN) && defined(RTC_ARCH_CPU_LITTLE_ENDIAN)
49 #error RTC_ARCH_CPU_BIG_ENDIAN and RTC_ARCH_CPU_LITTLE_ENDIAN both defined.
50 #endif
51 
52 #if defined(WEBRTC_WIN)
53 typedef int socklen_t;
54 #endif
55 
56 // The following only works for C++
57 #ifdef __cplusplus
58 
59 #ifndef ALIGNP
60 #define ALIGNP(p, t)                                             \
61   (reinterpret_cast<uint8_t*>(((reinterpret_cast<uintptr_t>(p) + \
62   ((t) - 1)) & ~((t) - 1))))
63 #endif
64 
65 #define RTC_IS_ALIGNED(p, a) (!((uintptr_t)(p) & ((a) - 1)))
66 
67 // Use these to declare and define a static local variable that gets leaked so
68 // that its destructors are not called at exit.
69 #define RTC_DEFINE_STATIC_LOCAL(type, name, arguments) \
70   static type& name = *new type arguments
71 
72 #endif  // __cplusplus
73 
74 #endif  // WEBRTC_BASE_BASICTYPES_H_
75