cbdata.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 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 
195 typedef int cbdata_type;
196 static const cbdata_type CBDATA_UNKNOWN = 0;
197 
203 
209 void *cbdataInternalAlloc(cbdata_type type, const char *, int);
210 
224 void *cbdataInternalFree(void *p, const char *, int);
225 
226 #if USE_CBDATA_DEBUG
227 void cbdataInternalLockDbg(const void *p, const char *, int);
228 #define cbdataInternalLock(a) cbdataInternalLockDbg(a,__FILE__,__LINE__)
229 
230 void cbdataInternalUnlockDbg(const void *p, const char *, int);
231 #define cbdataInternalUnlock(a) cbdataInternalUnlockDbg(a,__FILE__,__LINE__)
232 
233 int cbdataInternalReferenceDoneValidDbg(void **p, void **tp, const char *, int);
234 #define cbdataReferenceValidDone(var, ptr) cbdataInternalReferenceDoneValidDbg((void **)&(var), (ptr), __FILE__,__LINE__)
235 
236 #else
237 void cbdataInternalLock(const void *p);
238 void cbdataInternalUnlock(const void *p);
239 
255 int cbdataInternalReferenceDoneValid(void **p, void **tp);
256 #define cbdataReferenceValidDone(var, ptr) cbdataInternalReferenceDoneValid((void **)&(var), (ptr))
257 
258 #endif /* !CBDATA_DEBUG */
259 
266 int cbdataReferenceValid(const void *p);
267 
273 cbdata_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 {
294 public:
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 = NULL;}} while(0)
351 
359 {
361 
362 public:
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 
370 private:
371  void *data;
372 };
373 
374 // Discouraged: Use CbcPointer<> and asynchronous calls instead if possible.
377 {
378 public:
379  CallbackData(): data_(nullptr) {}
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 
391 private:
392  void *data_;
393 };
394 
395 #endif /* SQUID_CBDATA_H */
396 
#define cbdataReferenceValidDone(var, ptr)
Definition: cbdata.h:256
#define cbdataReferenceDone(var)
Definition: cbdata.h:350
void * cbdataInternalFree(void *p, const char *file, int line)
Definition: cbdata.cc:298
int type
Definition: errorpage.cc:78
int cbdata_type
Definition: cbdata.h:195
virtual ~CbdataParent()
Definition: cbdata.h:295
CallbackData & operator=(const CallbackData &other)
Definition: cbdata.cc:520
void unwrap(wrapped_type **output)
Definition: cbdata.h:365
char * p
Definition: membanger.c:43
CallbackData(CallbackData &&other)
Definition: cbdata.h:382
bool valid() const
Definition: cbdata.h:388
cbdata_type cbdataInternalAddType(cbdata_type type, const char *name, int size)
Definition: cbdata.cc:197
void const char HLPCB void * data
Definition: stub_helper.cc:16
void cbdataInternalUnlock(const void *p)
Definition: cbdata.cc:365
CallbackData(void *data)
Definition: cbdata.h:380
#define cbdataReference(var)
Definition: cbdata.h:341
virtual void * toCbdata()=0
~CallbackData()
Definition: cbdata.h:383
int cbdataInternalReferenceDoneValid(void **pp, void **tp)
Definition: cbdata.cc:438
#define CBDATA_CLASS(type)
Definition: cbdata.h:302
an old-style void* callback parameter
Definition: cbdata.h:376
CallbackData()
Definition: cbdata.h:379
void * cbdataInternalAlloc(cbdata_type type, const char *file, int line)
Definition: cbdata.cc:224
void * validDone()
Definition: cbdata.h:389
generic_cbdata(void *aData)
Definition: cbdata.h:363
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:412
void cbdataInternalLock(const void *p)
Definition: cbdata.cc:333
void * data_
raw callback data, maybe invalid
Definition: cbdata.h:392
CallbackData(const CallbackData &other)
Definition: cbdata.h:381
void cbdataRegisterWithCacheManager(void)
Definition: cbdata.cc:210
void * data
Definition: cbdata.h:371
static const cbdata_type CBDATA_UNKNOWN
Definition: cbdata.h:196
int size
Definition: ModDevPoll.cc:77

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors