3
* $Id: cbdata.h,v 1.1 2006/08/21 00:50:41 robertc Exp $
6
* SQUID Web Proxy Cache http://www.squid-cache.org/
7
* ----------------------------------------------------------
9
* Squid is the result of efforts by numerous individuals from
10
* the Internet community; see the CONTRIBUTORS file for full
11
* details. Many organizations have provided support for Squid's
12
* development; see the SPONSORS file for full details. Squid is
13
* Copyrighted (C) 2001 by the Regents of the University of
14
* California; see the COPYRIGHT file for full details. Squid
15
* incorporates software developed and/or copyrighted by other
16
* sources; see the CREDITS file for full details.
18
* This program is free software; you can redistribute it and/or modify
19
* it under the terms of the GNU General Public License as published by
20
* the Free Software Foundation; either version 2 of the License, or
21
* (at your option) any later version.
23
* This program is distributed in the hope that it will be useful,
24
* but WITHOUT ANY WARRANTY; without even the implied warranty of
25
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
* GNU General Public License for more details.
28
* You should have received a copy of the GNU General Public License
29
* along with this program; if not, write to the Free Software
30
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32
* Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
35
#ifndef SQUID_CBDATA_H
36
#define SQUID_CBDATA_H
41
* cbdata types. similar to the MEM_* types above, but managed
42
* in cbdata.c. A big difference is that these types are dynamically
43
* allocated. This list is only a list of predefined types. Other types
50
extern void cbdataRegisterWithCacheManager(CacheManager & manager);
52
extern void *cbdataInternalAllocDbg(cbdata_type type, const char *, int);
53
extern void *cbdataInternalFreeDbg(void *p, const char *, int);
54
extern void cbdataInternalLockDbg(const void *p, const char *, int);
55
extern void cbdataInternalUnlockDbg(const void *p, const char *, int);
56
extern int cbdataInternalReferenceDoneValidDbg(void **p, void **tp, const char *, int);
58
extern void *cbdataInternalAlloc(cbdata_type type);
59
extern void *cbdataInternalFree(void *p);
60
extern void cbdataInternalLock(const void *p);
61
extern void cbdataInternalUnlock(const void *p);
62
extern int cbdataInternalReferenceDoneValid(void **p, void **tp);
64
extern int cbdataReferenceValid(const void *p);
65
extern cbdata_type cbdataInternalAddType(cbdata_type type, const char *label, int size, FREE * free_func);
70
#define cbdataAlloc(type) ((type *)cbdataInternalAllocDbg(CBDATA_##type,__FILE__,__LINE__))
71
#define cbdataFree(var) do {if (var) {cbdataInternalFreeDbg(var,__FILE__,__LINE__); var = NULL;}} while(0)
72
#define cbdataInternalLock(a) cbdataInternalLockDbg(a,__FILE__,__LINE__)
73
#define cbdataInternalUnlock(a) cbdataInternalUnlockDbg(a,__FILE__,__LINE__)
74
#define cbdataReferenceValidDone(var, ptr) cbdataInternalReferenceDoneValidDbg((void **)&(var), (ptr), __FILE__,__LINE__)
75
#define CBDATA_CLASS2(type) \
76
static cbdata_type CBDATA_##type; \
78
void *operator new(size_t size) { \
79
assert(size == sizeof(type)); \
80
(CBDATA_##type ? CBDATA_UNKNOWN : (CBDATA_##type = cbdataInternalAddType(CBDATA_##type, #type, sizeof(type), NULL))); \
81
return cbdataInternalAllocDbg(CBDATA_##type,__FILE__,__LINE__); \
83
void operator delete (void *address) { \
84
if (address) cbdataInternalFreeDbg(address,__FILE__,__LINE__); \
88
#define cbdataAlloc(type) ((type *)cbdataInternalAlloc(CBDATA_##type))
89
#define cbdataFree(var) do {if (var) {cbdataInternalFree(var); var = NULL;}} while(0)
90
#define cbdataReferenceValidDone(var, ptr) cbdataInternalReferenceDoneValid((void **)&(var), (ptr))
91
#define CBDATA_CLASS2(type) \
92
static cbdata_type CBDATA_##type; \
94
void *operator new(size_t size) { \
95
assert(size == sizeof(type)); \
96
(CBDATA_##type ? CBDATA_UNKNOWN : (CBDATA_##type = cbdataInternalAddType(CBDATA_##type, #type, sizeof(type), NULL))); \
97
return (type *)cbdataInternalAlloc(CBDATA_##type); \
99
void operator delete (void *address) { \
100
if (address) cbdataInternalFree(address);\
104
#define cbdataReference(var) (cbdataInternalLock(var), var)
105
#define cbdataReferenceDone(var) do {if (var) {cbdataInternalUnlock(var); var = NULL;}} while(0)
106
#define CBDATA_CLASS(type) static cbdata_type CBDATA_##type
107
#define CBDATA_CLASS_INIT(type) cbdata_type type::CBDATA_##type = CBDATA_UNKNOWN
108
#define CBDATA_TYPE(type) static cbdata_type CBDATA_##type = CBDATA_UNKNOWN
109
#define CBDATA_GLOBAL_TYPE(type) cbdata_type CBDATA_##type
110
#define CBDATA_INIT_TYPE(type) (CBDATA_##type ? CBDATA_UNKNOWN : (CBDATA_##type = cbdataInternalAddType(CBDATA_##type, #type, sizeof(type), NULL)))
111
#define CBDATA_INIT_TYPE_FREECB(type, free_func) (CBDATA_##type ? CBDATA_UNKNOWN : (CBDATA_##type = cbdataInternalAddType(CBDATA_##type, #type, sizeof(type), free_func)))
114
* use this when you need to pass callback data to a blocking
115
* operation, but you don't want to/cannot have that pointer be cbdata itself.
121
generic_cbdata(void * data) : data(data) {}
122
template<typename wrapped_type>void unwrap(wrapped_type **output)
124
*output = static_cast<wrapped_type *>(data);
127
/* the wrapped data - only public to allow the mild abuse of this facility
128
* done by store_swapout - it gives a wrapped StoreEntry to StoreIO as the
129
* object to be given to the callbacks. That needs to be fully cleaned up!
132
void *data; /* the wrapped data */
134
CBDATA_CLASS2(generic_cbdata);
139
#endif /* SQUID_CBDATA_H */