~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/cbdata.h

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2006-11-11 10:32:06 UTC
  • Revision ID: james.westby@ubuntu.com-20061111103206-f3p0r9g0vq44rp3r
Tags: upstream-3.0.PRE5
ImportĀ upstreamĀ versionĀ 3.0.PRE5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * $Id: cbdata.h,v 1.1 2006/08/21 00:50:41 robertc Exp $
 
4
 *
 
5
 *
 
6
 * SQUID Web Proxy Cache          http://www.squid-cache.org/
 
7
 * ----------------------------------------------------------
 
8
 *
 
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.
 
17
 *
 
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.
 
22
 *  
 
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.
 
27
 *  
 
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.
 
31
 *
 
32
 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
 
33
 */
 
34
 
 
35
#ifndef   SQUID_CBDATA_H
 
36
#define   SQUID_CBDATA_H
 
37
 
 
38
#include "squid.h"
 
39
 
 
40
/*
 
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
 
44
 * are added runtime
 
45
 */
 
46
typedef enum {
 
47
    CBDATA_UNKNOWN = 0,
 
48
} cbdata_type;
 
49
 
 
50
extern void cbdataRegisterWithCacheManager(CacheManager & manager);
 
51
#if CBDATA_DEBUG
 
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);
 
57
#else
 
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);
 
63
#endif
 
64
extern int cbdataReferenceValid(const void *p);
 
65
extern cbdata_type cbdataInternalAddType(cbdata_type type, const char *label, int size, FREE * free_func);
 
66
 
 
67
 
 
68
/* cbdata macros */
 
69
#if CBDATA_DEBUG
 
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; \
 
77
        public: \
 
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__); \
 
82
                } \
 
83
                void operator delete (void *address) { \
 
84
                  if (address) cbdataInternalFreeDbg(address,__FILE__,__LINE__); \
 
85
                } \
 
86
        private:
 
87
#else
 
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; \
 
93
        public: \
 
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); \
 
98
                } \
 
99
                void operator delete (void *address) { \
 
100
                  if (address) cbdataInternalFree(address);\
 
101
                } \
 
102
        private:
 
103
#endif
 
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)))
 
112
 
 
113
/*
 
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.
 
116
 */
 
117
 
 
118
class generic_cbdata
 
119
{
 
120
  public:
 
121
    generic_cbdata(void * data) : data(data) {}
 
122
    template<typename wrapped_type>void unwrap(wrapped_type **output) 
 
123
      {
 
124
        *output = static_cast<wrapped_type *>(data);
 
125
        delete this;
 
126
      }
 
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!
 
130
     * - RBC 20060820
 
131
     */
 
132
    void *data; /* the wrapped data */
 
133
  private:
 
134
    CBDATA_CLASS2(generic_cbdata);
 
135
};
 
136
 
 
137
 
 
138
 
 
139
#endif /* SQUID_CBDATA_H */