1 /* 2 * Copyright 2019, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef CLASSCACHE_H 6 #define CLASSCACHE_H 7 8 9 #include <slab/Slab.h> 10 11 12 #define CLASS_CACHE(CLASS) \ 13 static object_cache* s##CLASS##Cache = NULL; \ 14 \ 15 void* \ 16 CLASS::operator new(size_t size) \ 17 { \ 18 if (size != sizeof(CLASS)) \ 19 panic("unexpected size passed to operator new!"); \ 20 if (s##CLASS##Cache == NULL) { \ 21 s##CLASS##Cache = create_object_cache_etc("pkgfs " #CLASS "s", \ 22 sizeof(CLASS), 8, 0, 0, 0, CACHE_NO_DEPOT, NULL, NULL, NULL, NULL); \ 23 } \ 24 \ 25 return object_cache_alloc(s##CLASS##Cache, 0); \ 26 } \ 27 \ 28 void \ 29 CLASS::operator delete(void* block) \ 30 { \ 31 object_cache_free(s##CLASS##Cache, block, 0); \ 32 } 33 34 35 #endif // CLASSCACHE_H 36