2 * Copyright (c) 2005 Hewlett-Packard Development Company, L.P.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 /* Almost lock-free malloc implementation based on stack implementation. */
24 /* See doc/README_malloc.txt file for detailed usage rules. */
29 #include "atomic_ops_stack.h"
31 #include <stddef.h> /* for size_t */
33 #ifdef AO_STACK_IS_LOCK_FREE
34 # define AO_MALLOC_IS_LOCK_FREE
37 #ifndef AO_ATTR_MALLOC
38 # if AO_GNUC_PREREQ(3, 1)
39 # define AO_ATTR_MALLOC __attribute__((__malloc__))
40 # elif defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(__EDG__)
41 # define AO_ATTR_MALLOC \
42 __declspec(allocator) __declspec(noalias) __declspec(restrict)
43 # elif defined(_MSC_VER) && _MSC_VER >= 1400
44 # define AO_ATTR_MALLOC __declspec(noalias) __declspec(restrict)
46 # define AO_ATTR_MALLOC /* empty */
50 #ifndef AO_ATTR_ALLOC_SIZE
52 # if __has_attribute(__alloc_size__)
53 # define AO_ATTR_ALLOC_SIZE(argnum) \
54 __attribute__((__alloc_size__(argnum)))
56 # define AO_ATTR_ALLOC_SIZE(argnum) /* empty */
58 # elif AO_GNUC_PREREQ(4, 3) && !defined(__ICC)
59 # define AO_ATTR_ALLOC_SIZE(argnum) __attribute__((__alloc_size__(argnum)))
61 # define AO_ATTR_ALLOC_SIZE(argnum) /* empty */
67 AO_ATTR_MALLOC AO_ATTR_ALLOC_SIZE(1)
68 void * AO_malloc(size_t);
70 /* Allow use of mmap to grow the heap. No-op on some platforms. */
71 void AO_malloc_enable_mmap(void);
73 #endif /* !AO_MALLOC_H */