cbdata.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_SRC_CBDATA_H
10#define SQUID_SRC_CBDATA_H
11
195typedef int cbdata_type;
197
203
209void *cbdataInternalAlloc(cbdata_type type, const char *, int);
210
224void *cbdataInternalFree(void *p, const char *, int);
225
226#if USE_CBDATA_DEBUG
227void cbdataInternalLockDbg(const void *p, const char *, int);
228#define cbdataInternalLock(a) cbdataInternalLockDbg(a,__FILE__,__LINE__)
229
230void cbdataInternalUnlockDbg(const void *p, const char *, int);
231#define cbdataInternalUnlock(a) cbdataInternalUnlockDbg(a,__FILE__,__LINE__)
232
233int cbdataInternalReferenceDoneValidDbg(void **p, void **tp, const char *, int);
234#define cbdataReferenceValidDone(var, ptr) cbdataInternalReferenceDoneValidDbg((void **)&(var), (ptr), __FILE__,__LINE__)
235
236#else
237void cbdataInternalLock(const void *p);
238void cbdataInternalUnlock(const void *p);
239
255int cbdataInternalReferenceDoneValid(void **p, void **tp);
256#define cbdataReferenceValidDone(var, ptr) cbdataInternalReferenceDoneValid((void **)&(var), (ptr))
257
258#endif /* !CBDATA_DEBUG */
259
266int cbdataReferenceValid(const void *p);
267
273cbdata_type cbdataInternalAddType(cbdata_type type, const char *label, int size);
274
276#define CBDATA_DECL_(type, methodSpecifiers) \
277 public: \
278 void *operator new(size_t size) { \
279 assert(size == sizeof(type)); \
280 if (!CBDATA_##type) CBDATA_##type = cbdataInternalAddType(CBDATA_##type, #type, sizeof(type)); \
281 return (type *)cbdataInternalAlloc(CBDATA_##type,__FILE__,__LINE__); \
282 } \
283 void operator delete (void *address) { \
284 if (address) cbdataInternalFree(address,__FILE__,__LINE__); \
285 } \
286 void *toCbdata() methodSpecifiers { return this; } \
287 private: \
288 static cbdata_type CBDATA_##type;
289
293{
294public:
295 virtual ~CbdataParent() {}
296 virtual void *toCbdata() = 0;
297};
298
302#define CBDATA_CLASS(type) CBDATA_DECL_(type, noexcept)
303
307#define CBDATA_CHILD(type) CBDATA_DECL_(type, override final)
308
318#define CBDATA_CLASS_INIT(type) cbdata_type type::CBDATA_##type = CBDATA_UNKNOWN
319
326#define CBDATA_NAMESPACED_CLASS_INIT(namespace, type) cbdata_type namespace::type::CBDATA_##type = CBDATA_UNKNOWN
327
341#define cbdataReference(var) (cbdataInternalLock(var), var)
342
350#define cbdataReferenceDone(var) do {if (var) {cbdataInternalUnlock(var); var = nullptr;}} while(0)
351
359{
361
362public:
363 generic_cbdata(void *aData) : data(aData) {}
364
365 template<typename wrapped_type>void unwrap(wrapped_type **output) {
366 *output = static_cast<wrapped_type *>(data);
367 delete this;
368 }
369
370private:
371 void *data;
372};
373
374// Discouraged: Use CbcPointer<> and asynchronous calls instead if possible.
377{
378public:
379 CallbackData(): data_(nullptr) {}
380 CallbackData(void *data): data_(cbdataReference(data)) {}
382 CallbackData(CallbackData &&other): data_(other.data_) { other.data_ = nullptr; }
384
385 CallbackData &operator =(const CallbackData &other);
386 CallbackData &operator =(CallbackData &&other) { cbdataReferenceDone(data_); data_ = other.data_; other.data_ = nullptr; return *this; }
387
388 bool valid() const { return cbdataReferenceValid(data_); }
389 void *validDone() { void *result; return cbdataReferenceValidDone(data_, &result) ? result : nullptr; }
390
391private:
392 void *data_;
393};
394
395#endif /* SQUID_CBDATA_H */
396
int size
Definition: ModDevPoll.cc:75
void cbdataInternalUnlock(const void *p)
Definition: cbdata.cc:357
#define cbdataReferenceDone(var)
Definition: cbdata.h:350
#define cbdataReference(var)
Definition: cbdata.h:341
static const cbdata_type CBDATA_UNKNOWN
Definition: cbdata.h:196
int cbdataInternalReferenceDoneValid(void **p, void **tp)
Definition: cbdata.cc:418
#define cbdataReferenceValidDone(var, ptr)
Definition: cbdata.h:256
cbdata_type cbdataInternalAddType(cbdata_type type, const char *label, int size)
Definition: cbdata.cc:196
void cbdataRegisterWithCacheManager(void)
Definition: cbdata.cc:209
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:398
#define CBDATA_CLASS(type)
Definition: cbdata.h:302
void * cbdataInternalAlloc(cbdata_type type, const char *, int)
Definition: cbdata.cc:223
void cbdataInternalLock(const void *p)
Definition: cbdata.cc:331
int cbdata_type
Definition: cbdata.h:195
void * cbdataInternalFree(void *p, const char *, int)
Definition: cbdata.cc:301
an old-style void* callback parameter
Definition: cbdata.h:377
~CallbackData()
Definition: cbdata.h:383
void * validDone()
Definition: cbdata.h:389
bool valid() const
Definition: cbdata.h:388
CallbackData(CallbackData &&other)
Definition: cbdata.h:382
CallbackData()
Definition: cbdata.h:379
CallbackData(void *data)
Definition: cbdata.h:380
CallbackData & operator=(const CallbackData &other)
Definition: cbdata.cc:500
void * data_
raw callback data, maybe invalid
Definition: cbdata.h:392
CallbackData(const CallbackData &other)
Definition: cbdata.h:381
virtual void * toCbdata()=0
virtual ~CbdataParent()
Definition: cbdata.h:295
void * data
Definition: cbdata.h:371
void unwrap(wrapped_type **output)
Definition: cbdata.h:365
generic_cbdata(void *aData)
Definition: cbdata.h:363
int type
Definition: errorpage.cc:152

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors