1 | /* |
---|
2 | * |
---|
3 | * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand. |
---|
4 | * All rights reserved. |
---|
5 | * |
---|
6 | * This file is part of libtrace. |
---|
7 | * |
---|
8 | * This code has been developed by the University of Waikato WAND |
---|
9 | * research group. For further information please see http://www.wand.net.nz/ |
---|
10 | * |
---|
11 | * libtrace is free software; you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU Lesser General Public License as published by |
---|
13 | * the Free Software Foundation; either version 3 of the License, or |
---|
14 | * (at your option) any later version. |
---|
15 | * |
---|
16 | * libtrace is distributed in the hope that it will be useful, |
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | * GNU Lesser General Public License for more details. |
---|
20 | * |
---|
21 | * You should have received a copy of the GNU Lesser General Public License |
---|
22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | * |
---|
24 | * |
---|
25 | */ |
---|
26 | #ifndef LIBTRACE_OBJECT_CACHE_H |
---|
27 | #define LIBTRACE_OBJECT_CACHE_H |
---|
28 | |
---|
29 | #include "ring_buffer.h" |
---|
30 | #include "vector.h" |
---|
31 | |
---|
32 | |
---|
33 | struct local_cache; |
---|
34 | typedef struct libtrace_ocache { |
---|
35 | libtrace_ringbuffer_t rb; |
---|
36 | void *(*alloc)(void); |
---|
37 | void (*free)(void *); |
---|
38 | size_t thread_cache_size; |
---|
39 | size_t max_allocations; |
---|
40 | size_t current_allocations; |
---|
41 | pthread_spinlock_t spin; |
---|
42 | size_t nb_thread_list; |
---|
43 | size_t max_nb_thread_list; |
---|
44 | struct local_cache **thread_list; |
---|
45 | } libtrace_ocache_t; |
---|
46 | |
---|
47 | DLLEXPORT int libtrace_ocache_init(libtrace_ocache_t *oc, void *(*alloc)(void), void (*free)(void*), |
---|
48 | size_t thread_cache_size, size_t buffer_size, bool limit_size); |
---|
49 | DLLEXPORT int libtrace_ocache_destroy(libtrace_ocache_t *oc); |
---|
50 | DLLEXPORT size_t libtrace_ocache_alloc(libtrace_ocache_t *oc, void *values[], size_t nb_buffers, size_t min_nb_buffers); |
---|
51 | DLLEXPORT size_t libtrace_ocache_free(libtrace_ocache_t *oc, void *values[], size_t nb_buffers, size_t min_nb_buffers); |
---|
52 | DLLEXPORT void libtrace_zero_ocache(libtrace_ocache_t *oc); |
---|
53 | DLLEXPORT void libtrace_ocache_unregister_thread(libtrace_ocache_t *oc); |
---|
54 | #endif // LIBTRACE_OBJECT_CACHE_H |
---|