2 * Original code from jemalloc with this license:
4 * Copyright (C) 2002-2013 Jason Evans <jasone@canonware.com>.
6 * Copyright (C) 2007-2012 Mozilla Foundation. All rights reserved.
7 * Copyright (C) 2009-2013 Facebook, Inc. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the above copyright notice(s),
12 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice(s),
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20 * EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * ***** BEGIN GPL LICENSE BLOCK *****
30 * This program is free software; you can redistribute it and/or
31 * modify it under the terms of the GNU General Public License
32 * as published by the Free Software Foundation; either version 2
33 * of the License, or (at your option) any later version.
35 * This program is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 * GNU General Public License for more details.
40 * You should have received a copy of the GNU General Public License
41 * along with this program; if not, write to the Free Software Foundation,
42 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
44 * The Original Code is Copyright (C) 2016 Blender Foundation.
45 * All rights reserved.
47 * The Original Code is: adapted from jemalloc.
49 * ***** END GPL LICENSE BLOCK *****
52 #ifndef __ATOMIC_OPS_UTILS_H__
53 #define __ATOMIC_OPS_UTILS_H__
55 /* needed for int types */
56 #include "../../../source/blender/blenlib/BLI_sys_types.h"
62 /* little macro so inline keyword works */
64 # define ATOMIC_INLINE static __forceinline
66 # if (defined(__APPLE__) && defined(__ppc__))
67 /* static inline __attribute__ here breaks osx ppc gcc42 build */
68 # define ATOMIC_INLINE static __attribute__((always_inline))
70 # define ATOMIC_INLINE static inline __attribute__((always_inline))
76 # define LIKELY(x) __builtin_expect(!!(x), 1)
77 # define UNLIKELY(x) __builtin_expect(!!(x), 0)
79 # define LIKELY(x) (x)
80 # define UNLIKELY(x) (x)
84 #if defined(__SIZEOF_POINTER__)
85 # define LG_SIZEOF_PTR __SIZEOF_POINTER__
86 #elif defined(UINTPTR_MAX)
87 # if (UINTPTR_MAX == 0xFFFFFFFF)
88 # define LG_SIZEOF_PTR 4
89 # elif (UINTPTR_MAX == 0xFFFFFFFFFFFFFFFF)
90 # define LG_SIZEOF_PTR 8
92 #elif defined(__WORDSIZE) /* Fallback for older glibc and cpp */
93 # if (__WORDSIZE == 32)
94 # define LG_SIZEOF_PTR 4
95 # elif (__WORDSIZE == 64)
96 # define LG_SIZEOF_PTR 8
100 #ifndef LG_SIZEOF_PTR
101 # error "Cannot find pointer size"
104 #if (UINT_MAX == 0xFFFFFFFF)
105 # define LG_SIZEOF_INT 4
106 #elif (UINT_MAX == 0xFFFFFFFFFFFFFFFF)
107 # define LG_SIZEOF_INT 8
109 # error "Cannot find int size"
112 #endif /* __ATOMIC_OPS_UTILS_H__ */