1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 2005 Apple Computer, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #ifndef KHTMLMAINTTHREADMALLOC_H
24 #define KHTMLMAINTTHREADMALLOC_H
26 // This is a copy of dlmalloc, a fast single-threaded malloc implementation.
27 // JavaScriptCore is multi-threaded, but certain actions can only take place under
28 // the global collector lock. Therefore, these functions should only be used
29 // while holding the collector lock (this is true whenenever the interpreter is
30 // executing or GC is taking place).
36 inline void *main_thread_malloc(size_t n) { return malloc(n); }
37 inline void *main_thread_calloc(size_t n_elements, size_t element_size) { return calloc(n_elements, element_size); }
38 inline void main_thread_free(void* p) { free(p); }
39 inline void *main_thread_realloc(void* p, size_t n) { return realloc(p, n); }
41 #define MAIN_THREAD_ALLOCATED
45 void *main_thread_malloc(size_t n);
46 void *main_thread_calloc(size_t n_elements, size_t element_size);
47 void main_thread_free(void* p);
48 void *main_thread_realloc(void* p, size_t n);
50 #define MAIN_THREAD_ALLOCATED \
51 void* operator new(size_t s) { return khtml::main_thread_malloc(s); } \
52 void operator delete(void* p) { khtml::main_thread_free(p); }
58 #endif /* KHTMLMAINTTHREADMALLOC_H */