cbdata.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CbdataParent
 
class  generic_cbdata
 
class  CallbackData
 an old-style void* callback parameter More...
 

Macros

#define cbdataReferenceValidDone(var, ptr)   cbdataInternalReferenceDoneValid((void **)&(var), (ptr))
 
#define CBDATA_DECL_(type, methodSpecifiers)
 declaration-generator used internally by CBDATA_CLASS() and CBDATA_CHILD() More...
 
#define CBDATA_CLASS(type)   CBDATA_DECL_(type, noexcept)
 
#define CBDATA_CHILD(type)
 
#define CBDATA_INTERMEDIATE()
 
#define CBDATA_CLASS_INIT(type)   cbdata_type type::CBDATA_##type = CBDATA_UNKNOWN
 
#define CBDATA_NAMESPACED_CLASS_INIT(namespace, type)   cbdata_type namespace::type::CBDATA_##type = CBDATA_UNKNOWN
 
#define cbdataReference(var)   (cbdataInternalLock(var), var)
 
#define cbdataReferenceDone(var)   do {if (var) {cbdataInternalUnlock(var); var = nullptr;}} while(0)
 

Typedefs

typedef int cbdata_type
 

Functions

void * cbdataInternalAlloc (cbdata_type type)
 
void * cbdataInternalFree (void *p)
 
void cbdataInternalLock (const void *p)
 
void cbdataInternalUnlock (const void *p)
 
int cbdataInternalReferenceDoneValid (void **p, void **tp)
 
int cbdataReferenceValid (const void *p)
 
cbdata_type cbdataInternalAddType (cbdata_type type, const char *label, int size)
 

Variables

static const cbdata_type CBDATA_UNKNOWN = 0
 

Macro Definition Documentation

◆ CBDATA_CHILD

#define CBDATA_CHILD (   type)
Value:
CBDATA_DECL_(type, final) \
void finalizedInCbdataChild() final {}
#define CBDATA_DECL_(type, methodSpecifiers)
declaration-generator used internally by CBDATA_CLASS() and CBDATA_CHILD()
Definition: cbdata.h:257

cbdata-enables a final CbdataParent-derived class in a hierarchy sets the class declaration section to "private" use this at the start of your class declaration for consistency sake

Definition at line 294 of file cbdata.h.

◆ CBDATA_CLASS

#define CBDATA_CLASS (   type)    CBDATA_DECL_(type, noexcept)

cbdata-enables a stand-alone class that is not a CbdataParent child sets the class declaration section to "private" use this at the start of your class declaration for consistency sake

Definition at line 289 of file cbdata.h.

◆ CBDATA_CLASS_INIT

#define CBDATA_CLASS_INIT (   type)    cbdata_type type::CBDATA_##type = CBDATA_UNKNOWN

Creates a global instance pointer for the CBDATA memory allocator to allocate and free objects for the matching CBDATA_CLASS().

Place this in the appropriate .cc file for the class being registered.

May be placed inside an explicit namespace scope declaration, or CBDATA_NAMESPACED_CLASS_INIT() used instead.

Definition at line 320 of file cbdata.h.

◆ CBDATA_DECL_

#define CBDATA_DECL_ (   type,
  methodSpecifiers 
)
Value:
public: \
void *operator new(size_t size) { \
assert(size == sizeof(type)); \
if (!CBDATA_##type) CBDATA_##type = cbdataInternalAddType(CBDATA_##type, #type, sizeof(type)); \
return (type *)cbdataInternalAlloc(CBDATA_##type); \
} \
void operator delete (void *address) { \
if (address) cbdataInternalFree(address); \
} \
void *toCbdata() methodSpecifiers { return this; } \
private: \
static cbdata_type CBDATA_##type;
int size
Definition: ModDevPoll.cc:75
void * cbdataInternalFree(void *p)
Definition: cbdata.cc:203
cbdata_type cbdataInternalAddType(cbdata_type type, const char *label, int size)
Definition: cbdata.cc:117
void * cbdataInternalAlloc(cbdata_type type)
Definition: cbdata.cc:145
int cbdata_type
Definition: cbdata.h:195

Definition at line 257 of file cbdata.h.

◆ CBDATA_INTERMEDIATE

#define CBDATA_INTERMEDIATE ( )
Value:
public: \
void *toCbdata() override { return this; } \
private:

cbdata-enables a non-final CbdataParent-derived class T in a hierarchy. Using this macro is required to be able to create cbdata pointers in T constructors, when the current vtable is still pointing to T::toCbdata() that would have been pure without this macro, leading to FATAL runtime OnTerminate() calls. However, assuming that the final cbdata pointer will still point to T::this is risky – multiple inheritance changes "this"!

sets the class declaration section to "private" use this at the start of your class declaration for consistency sake

Definition at line 306 of file cbdata.h.

◆ CBDATA_NAMESPACED_CLASS_INIT

#define CBDATA_NAMESPACED_CLASS_INIT (   namespace,
  type 
)    cbdata_type namespace::type::CBDATA_##type = CBDATA_UNKNOWN

Creates a global instance pointer for the CBDATA memory allocator to allocate and free objects for the matching CBDATA_CLASS().

Place this in the appropriate .cc file for the class being registered.

Definition at line 328 of file cbdata.h.

◆ cbdataReference

#define cbdataReference (   var)    (cbdataInternalLock(var), var)

Creates a new reference to a cbdata entry. Used when you need to store a reference in another structure. The reference can later be verified for validity by cbdataReferenceValid().

Deprecated:
Prefer the use of CbcPointer<> smart pointer.
Parameters
varThe reference variable is a pointer to the entry, in all aspects identical to the original pointer. But semantically it is quite different. It is best if the reference is thought of and handled as a "void *".

Definition at line 343 of file cbdata.h.

◆ cbdataReferenceDone

#define cbdataReferenceDone (   var)    do {if (var) {cbdataInternalUnlock(var); var = nullptr;}} while(0)

Removes a reference created by cbdataReference().

Deprecated:
Prefer the use of CbcPointer<> smart pointer.
Parameters
varThe reference variable. Will be automatically cleared to nullptr

Definition at line 352 of file cbdata.h.

◆ cbdataReferenceValidDone

#define cbdataReferenceValidDone (   var,
  ptr 
)    cbdataInternalReferenceDoneValid((void **)&(var), (ptr))

Definition at line 239 of file cbdata.h.

Typedef Documentation

◆ cbdata_type

typedef int cbdata_type

cbdata types. Similar to the MEM_* types, but managed in cbdata.cc A big difference is that cbdata types are dynamically allocated.

Initially only UNKNOWN type is predefined. Other types are added at runtime by CBDATA_CLASS().

Definition at line 195 of file cbdata.h.

Function Documentation

◆ cbdataInternalAddType()

cbdata_type cbdataInternalAddType ( cbdata_type  type,
const char *  label,
int  size 
)

Create a run-time registration for the class type with cbdata memory allocator.

Note
For internal CBDATA use only.

Definition at line 117 of file cbdata.cc.

References assert, cbdata_index, cbdata_types, memPoolCreate, CBDataIndex::pool, size, xmalloc, and xrealloc().

◆ cbdataInternalAlloc()

void * cbdataInternalAlloc ( cbdata_type  type)

Allocates a new entry of a registered CBDATA type.

Note
For internal CBDATA use only.

Definition at line 145 of file cbdata.cc.

References Mem::Allocator::alloc(), assert, cbdata_htable, cbdata_index, cbdata_types, cbdataCount, cbdata::cookie, cbdata::Cookie, cbdata::data, debugs, cbdata::locks, CBDataIndex::pool, cbdata::type, and cbdata::valid.

◆ cbdataInternalFree()

void * cbdataInternalFree ( void *  p)

Frees a entry allocated by cbdataInternalAlloc().

Once this has been called cbdataReferenceValid() and cbdataReferenceValidDone() will return false regardless of whether there are remaining cbdata references.

cbdataReferenceDone() must still be called for any active references to the cbdata entry. The cbdata entry will be freed only when the last reference is removed.

Note
For internal CBDATA use only.

Definition at line 203 of file cbdata.cc.

References assert, cbdataRealFree(), debugs, and cbdata::FromUserData().

◆ cbdataInternalLock()

void cbdataInternalLock ( const void *  p)

Definition at line 221 of file cbdata.cc.

References assert, debugs, cbdata::FromUserData(), and INT_MAX.

Referenced by logfile_mod_daemon_open().

◆ cbdataInternalReferenceDoneValid()

int cbdataInternalReferenceDoneValid ( void **  p,
void **  tp 
)

Removes a reference created by cbdataReference() and checks it for validity. Meant to be used on the last dereference, usually to make a callback.

void *cbdata;
...
if (cbdataReferenceValidDone(reference, &cbdata)))
callback(..., cbdata);
#define cbdataReferenceValidDone(var, ptr)
Definition: cbdata.h:239
Definition: cbdata.cc:38
Parameters
varThe reference variable. Will be automatically cleared to nullptr
ptrA temporary pointer to the referenced data (if valid).

Definition at line 282 of file cbdata.cc.

References cbdataInternalUnlock(), and cbdataReferenceValid().

◆ cbdataInternalUnlock()

void cbdataInternalUnlock ( const void *  p)

◆ cbdataReferenceValid()

int cbdataReferenceValid ( const void *  p)
Parameters
pA cbdata entry reference pointer.
Return values
0A reference is stale. The pointer refers to a entry already freed.
trueThe reference is valid and active.

Definition at line 265 of file cbdata.cc.

References assert, debugs, and cbdata::FromUserData().

Referenced by CbcPointer< Cbc >::CbcPointer(), ConnStateData::borrowPinnedConnection(), ACLChecklist::calcImplicitAnswer(), ACLChecklist::callerGone(), AsyncJob::callException(), AsyncJob::callStart(), StoreIOStateCb::canDial(), EventDialer::canDial(), CommCbFunPtrCallT< Dialer >::canFire(), cbdataInternalReferenceDoneValid(), EventScheduler::checkEvents(), Helper::Session::checkForTimedOutRequests(), clientGetMoreData(), clientSocketDetach(), clientSocketRecipient(), clientStreamDetach(), ACLFilledChecklist::conn(), diskHandleRead(), downloaderRecipient(), EventScheduler::dump(), esiBufferRecipient(), esiProcessStream(), esiStreamDetach(), esiStreamRead(), esiStreamStatus(), externalAclHandleReply(), ACLChecklist::fastCheck(), ftpSendReply(), CbcPointer< Cbc >::get(), ClientHttpRequest::getConn(), Comm::Connection::getPeer(), DiskdIOStrategy::handle(), helperDispatch(), helperHandleRead(), helperReturnBuffer(), helperStatefulDispatch(), helperStatefulHandleRead(), ClientRequestContext::httpStateIsValid(), idnsCallbackOneWithAnswer(), ConnStateData::isOpen(), TunnelStateData::keepGoingAfterRead(), ClientHttpRequest::noteAdaptationAnswer(), CbcPointer< Cbc >::operator=(), peerCountMcastPeersAbort(), peerDigestFetchedEnough(), peerDigestHandleReply(), ACLChecklist::prepNonBlocking(), TunnelStateData::ReadClient(), TunnelStateData::ReadServer(), clientReplyContext::sendMoreData(), SslBumpEstablish(), tunnelStartShoveling(), CallbackData::valid(), PeerPoolMgr::validPeer(), TunnelStateData::writeClientDone(), TunnelStateData::WriteClientDone(), TunnelStateData::writeServerDone(), and TunnelStateData::WriteServerDone().

Variable Documentation

◆ CBDATA_UNKNOWN

const cbdata_type CBDATA_UNKNOWN = 0
static

Definition at line 196 of file cbdata.h.

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors