X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/5963ec5bc27cc5ce1ff3e6a60d0776de87c4f250..511f56b025a791a6f62910bdd2fe01caaaf917c2:/Pooling.hpp diff --git a/Pooling.hpp b/Pooling.hpp index 24c7cc2..0e5456f 100644 --- a/Pooling.hpp +++ b/Pooling.hpp @@ -1,21 +1,21 @@ /* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2013 Jay Freeman (saurik) + * Copyright (C) 2009-2014 Jay Freeman (saurik) */ -/* GNU General Public License, Version 3 {{{ */ +/* GNU Affero General Public License, Version 3 {{{ */ /* - * Cycript is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * Cycript is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Cycript. If not, see . + * GNU Affero General Public License for more details. + + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . **/ /* }}} */ @@ -62,6 +62,11 @@ class CYPool { return (size + 7) & ~0x3; } + template + static void delete_(void *data) { + reinterpret_cast(data)->~Type_(); + } + CYPool(const CYPool &); public: @@ -182,6 +187,13 @@ class CYPool { } void atexit(void (*code)(void *), void *data = NULL); + + template + Type_ &object() { + Type_ *value(new(*this) Type_()); + atexit(&delete_, value); + return *value; + } }; _finline void *operator new(size_t size, CYPool &pool) { @@ -300,4 +312,7 @@ class CYLocalPool : #define $pool \ (*CYLocal::Get()) +template <> +::pthread_key_t CYLocal::key_; + #endif/*CYCRIPT_POOLING_HPP*/