brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.2 KiB · a18f079 Raw
114 lines · c
1//===-------------------------- rpnew.h -----------------*- C -*-=============//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// This library provides a cross-platform lock free thread caching malloc10// implementation in C11.11//12//===----------------------------------------------------------------------===//13 14#ifdef __cplusplus15 16#include <new>17#include <rpmalloc.h>18 19#ifndef __CRTDECL20#define __CRTDECL21#endif22 23extern void __CRTDECL operator delete(void *p) noexcept { rpfree(p); }24 25extern void __CRTDECL operator delete[](void *p) noexcept { rpfree(p); }26 27extern void *__CRTDECL operator new(std::size_t size) noexcept(false) {28  return rpmalloc(size);29}30 31extern void *__CRTDECL operator new[](std::size_t size) noexcept(false) {32  return rpmalloc(size);33}34 35extern void *__CRTDECL operator new(std::size_t size,36                                    const std::nothrow_t &tag) noexcept {37  (void)sizeof(tag);38  return rpmalloc(size);39}40 41extern void *__CRTDECL operator new[](std::size_t size,42                                      const std::nothrow_t &tag) noexcept {43  (void)sizeof(tag);44  return rpmalloc(size);45}46 47#if (__cplusplus >= 201402L || _MSC_VER >= 1916)48 49extern void __CRTDECL operator delete(void *p, std::size_t size) noexcept {50  (void)sizeof(size);51  rpfree(p);52}53 54extern void __CRTDECL operator delete[](void *p, std::size_t size) noexcept {55  (void)sizeof(size);56  rpfree(p);57}58 59#endif60 61#if (__cplusplus > 201402L || defined(__cpp_aligned_new))62 63extern void __CRTDECL operator delete(void *p,64                                      std::align_val_t align) noexcept {65  (void)sizeof(align);66  rpfree(p);67}68 69extern void __CRTDECL operator delete[](void *p,70                                        std::align_val_t align) noexcept {71  (void)sizeof(align);72  rpfree(p);73}74 75extern void __CRTDECL operator delete(void *p, std::size_t size,76                                      std::align_val_t align) noexcept {77  (void)sizeof(size);78  (void)sizeof(align);79  rpfree(p);80}81 82extern void __CRTDECL operator delete[](void *p, std::size_t size,83                                        std::align_val_t align) noexcept {84  (void)sizeof(size);85  (void)sizeof(align);86  rpfree(p);87}88 89extern void *__CRTDECL operator new(std::size_t size,90                                    std::align_val_t align) noexcept(false) {91  return rpaligned_alloc(static_cast<size_t>(align), size);92}93 94extern void *__CRTDECL operator new[](std::size_t size,95                                      std::align_val_t align) noexcept(false) {96  return rpaligned_alloc(static_cast<size_t>(align), size);97}98 99extern void *__CRTDECL operator new(std::size_t size, std::align_val_t align,100                                    const std::nothrow_t &tag) noexcept {101  (void)sizeof(tag);102  return rpaligned_alloc(static_cast<size_t>(align), size);103}104 105extern void *__CRTDECL operator new[](std::size_t size, std::align_val_t align,106                                      const std::nothrow_t &tag) noexcept {107  (void)sizeof(tag);108  return rpaligned_alloc(static_cast<size_t>(align), size);109}110 111#endif112 113#endif114