// // mp::zone // // Copyright (C) 2008 FURUHASHI Sadayuki // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #ifndef MP_ZONE_H__ #define MP_ZONE_H__ namespace mp { class zone { public: zone(); ~zone(); public: template T* allocate(); MP_ARGS_BEGIN template T* allocate(MP_ARGS_PARAMS); MP_ARGS_END void* malloc(size_t sz); void push_finalizer(void (*func)(void*), void* obj); void delegate_to(zone& guardian); void clear(); private: struct entry { entry(void (*func)(void*), void* obj): m_func(func), m_obj(obj) {} void finalize() { (*m_func)(m_obj); } private: void (*m_func)(void*); void* m_obj; }; typedef std::vector entries_t; entries_t m_entries; private: template T* push_object(T* x); static void finalize_free(void* p); template static void finalize_destruct_free(void* obj); private: zone(const zone&); }; } // namespace mp #include "mp/zone_impl.h" #endif /* mp/zone.h */