This patch is generated from the cbdata-20011010 branch of HEAD-20011010 in squid Tue Sep 9 11:56:52 2003 GMT See http://devel.squid-cache.org/ Index: squid/acconfig.h diff -u squid/acconfig.h:1.11 squid/acconfig.h:1.8.10.2 --- squid/acconfig.h:1.11 Thu Sep 27 00:49:37 2001 +++ squid/acconfig.h Fri Sep 28 00:49:19 2001 @@ -321,6 +321,11 @@ #undef LINUX_NETFILTER /* + * Enable for cbdata debug information + */ +#undef CBDATA_DEBUG + +/* * Known-size intgers */ Index: squid/configure.in diff -u squid/configure.in:1.29 squid/configure.in:1.20.10.3 --- squid/configure.in:1.29 Thu Sep 27 00:49:37 2001 +++ squid/configure.in Fri Sep 28 00:49:19 2001 @@ -72,6 +72,18 @@ AC_DEFINE_UNQUOTED(CONFIG_HOST_TYPE, "$host") +<<<<<<< configure.in +dnl Set default LDFLAGS +if test -z "$LDFLAGS"; then + LDFLAGS="-g" +fi + +PRESET_CFLAGS="$CFLAGS" +======= +>>>>>>> 1.29 + +dnl Check for GNU cc +AC_PROG_CC dnl Gerben Wierda case "$host" in @@ -212,6 +224,14 @@ AC_ARG_ENABLE(gnuregex, [ --enable-gnuregex Compile GNUregex], [USE_GNUREGEX=$enableval]) + +AC_ARG_ENABLE(debug-cbdata, +[ --enable-debug-cbdata Provide some debug information in cbdata], +[ if test "$enableval" = "yes" ; then + echo "cbdata debugging enabled" + AC_DEFINE(CBDATA_DEBUG) + fi +]) AC_ARG_ENABLE(xmalloc-debug, [ --enable-xmalloc-debug Do some simple malloc debugging], Index: squid/doc/Programming-Guide/prog-guide.sgml diff -u squid/doc/Programming-Guide/prog-guide.sgml:1.16 squid/doc/Programming-Guide/prog-guide.sgml:1.10.28.7 --- squid/doc/Programming-Guide/prog-guide.sgml:1.16 Fri Sep 7 16:55:49 2001 +++ squid/doc/Programming-Guide/prog-guide.sgml Wed Oct 10 14:17:30 2001 @@ -2483,7 +2483,151 @@

Squid's extensive use of callback functions makes it very - susceptible to memory access errors. For a blocking operation + susceptible to memory access errors. + +API + +CBDATA_TYPE + +

+ + CBDATA_TYPE(datatype); + + +

+ Macro that defines a new cbdata datatype. Similar to a variable + or struct definition. Scope is always local to the file/block + where it is defined and all allocations must be within this scope. + Allocated entries referenced or freed anywhere with no restrictions + on scope. + +CBDATA_GLOBAL_TYPE + +

+ + /* Module header file */ + external CBDATA_GLOBAL_TYPE(datatype); + + /* Module main C file */ + CBDATA_GLOBAL_TYPE(datatype); + + +

+ Defines a global cbdata type that can be referenced anywhere. + +CBDATA_INIT_TYPE + +

+ + CBDATA_INIT_TYPE(datatype); + /* or */ + CBDATA_INIT_TYPE_FREECB(datatype, FREE *freehandler); + + +

+ Initializes the cbdatatype. Must be called prior to the first use of + cbdataAlloc() for the type. + +

+ The freehandler is called when the last known reference to a + allocated entry goes away. + +cbdataAlloc + +

+ + pointer = cbdataAlloc(datatype); + + +

+ Allocates a new entry of a registered cbdata type. + +cbdataReference + +

+ + reference = cbdataReference(pointer); + + +

+ 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 cbdataValid(). + +

+ Note: The reference variable is a pointer to the entry, in all + aspects identical to the original pointer. But semantically it + is quite different. + +cbdataReferenceDone + +

+ + cbdataReferenceDone(reference); + + +

+ Removes a reference created by cbdataReference(). + +

+ Note: The reference variable will be automatically cleared to NULL. + +cbdataFree + +

+ + cbdataFree(pointer); + + +

+ Frees a entry allocated by cbdataAlloc(). + +

+ Note: If there are active references to the entry then the entry + will be freed with the last reference is removed. However, + cbdataValid() will return false for those references. + +cbdataValid + +

+ + if (cbdataValid(reference)) { + ... + } + + +

+ cbdataValid() returns false if a reference is stale (refers to a + entry freed by cbdataFree). + +cbdataReferenceDoneValid + +

+ + cbdata = cbdataReferenceDoneValid(reference); + + +

+ Removes a reference created by cbdataReference(), and returns a temporaty + voilatile referencce if still valid. + +

+ Meant to be used on the last dereference + + + void *cbdata; + ... + if ((cbdata = cbdataReferenceDoneValid(reference)) != NULL) + callback(..., cbdata); + + +

+ Note: The reference variable will be automatically cleared to NULL. + +Examples + +

+ For a blocking operation with callback functions, the normal sequence of events is as follows: @@ -2508,40 +2652,68 @@ operation executes elsewhere, and is freed when the operation completes. The normal sequence of events is: + /* initialization */ type_of_data callback_data; ... callback_data = cbdataAlloc(type_of_data); ... - cbdataLock(callback_data); - fooOperationStart(bar, callback_func, callback_data); + /* calling "foo" */ + fooOperationStart(..., callback_func, callback_data); ... - fooOperationComplete(...); - if (cbdataValid(callback_data)) { - callback_func(callback_data, ....); - cbdataUnlock(callback_data); + /* being destroyed */ cbdataFree(callback_data); + + /* foo */ + void + fooOperationStart(..., callback_func, void *callback_data) + { + void *local_pointer = cbdataReference(callback_data); + .... + } + void + fooOperationComplete(...) + { + ... + if (cbdataValid(local_pointer)) + callback_func(...., local_pointer); + cbdataDone(local_pointer); + } + + +

Or if you need to have it unreferenced prior to calling the + callback then fooOperationsComplete() can be written as + + + void + fooOperationComplete(...) + { + void *cbdata; + ... + if ((cbdata = cbdataReferenceDone(local_pointer)) != NULL) + callback_func(..., cbdata); + }

With this scheme, nothing bad happens if callback_data = cbdataAlloc(...); ... - cbdataLock(callback_data); fooOperationStart(bar, callback_func, callback_data); + local_pointer = cbdataReference(callback_data); ... cbdataFree(callback_data); ... fooOperationComplete(...); - if (cbdataValid(callback_data)) { - callback_func(callback_data, ....); - cbdataUnlock(callback_data); + if (cbdataValid(local_pointer)) + callback_func(local_pointer, ....); + cbdataDone(local_pointer); In this case, when access_list) != NULL) { /* * If the _acl_access is no longer valid (i.e. its been @@ -1741,7 +1744,7 @@ * access check. For now, return ACCESS_DENIED. */ if (!cbdataValid(A)) { - cbdataUnlock(A); + cbdataReferenceDone(checklist->access_list); break; } debug(28, 3) ("aclCheck: checking '%s'\n", A->cfgline); @@ -1798,8 +1801,7 @@ return; } else { debug(28, 1) ("aclCheck: Can't start ident lookup. No client connection\n"); - cbdataUnlock(checklist->conn); - checklist->conn = NULL; + cbdataReferenceDone(checklist->conn); allow = 0; match = -1; } @@ -1810,18 +1812,17 @@ * is allowed, denied, requires authentication, or we move on to * the next entry. */ - cbdataUnlock(A); if (match) { debug(28, 3) ("aclCheck: match found, returning %d\n", allow); + cbdataReferenceDone(checklist->access_list); /* A */ aclCheckCallback(checklist, allow); return; } - checklist->access_list = A->next; /* - * Lock the next _acl_access entry + * Reference the next _acl_access entry */ - if (A->next) - cbdataLock(A->next); + checklist->access_list = cbdataReference(A->next); + cbdataReferenceDone(A); } debug(28, 3) ("aclCheck: NO match found, returning %d\n", allow != ACCESS_DENIED ? ACCESS_DENIED : ACCESS_ALLOWED); aclCheckCallback(checklist, allow != ACCESS_DENIED ? ACCESS_DENIED : ACCESS_ALLOWED); @@ -1833,10 +1834,7 @@ if (checklist->request) requestUnlink(checklist->request); checklist->request = NULL; - if (checklist->conn) { - cbdataUnlock(checklist->conn); - checklist->conn = NULL; - } + cbdataReferenceDone(checklist->conn); cbdataFree(checklist); } @@ -1856,9 +1854,8 @@ } if (cbdataValid(checklist->callback_data)) checklist->callback(answer, checklist->callback_data); - cbdataUnlock(checklist->callback_data); checklist->callback = NULL; - checklist->callback_data = NULL; + cbdataReferenceDone(checklist->callback_data); aclChecklistFree(checklist); } @@ -1944,12 +1941,7 @@ int i; aclCheck_t *checklist; checklist = cbdataAlloc(aclCheck_t); - checklist->access_list = A; - /* - * aclCheck() makes sure checklist->access_list is a valid - * pointer, so lock it. - */ - cbdataLock(A); + checklist->access_list = cbdataReference(A); if (request != NULL) { checklist->request = requestLink(request); checklist->src_addr = request->client_addr; @@ -1970,8 +1962,7 @@ aclNBCheck(aclCheck_t * checklist, PF * callback, void *callback_data) { checklist->callback = callback; - checklist->callback_data = callback_data; - cbdataLock(callback_data); + checklist->callback_data = cbdataReference(callback_data); aclCheck(checklist); } Index: squid/src/cache_cf.c diff -u squid/src/cache_cf.c:1.33 squid/src/cache_cf.c:1.22.4.5 --- squid/src/cache_cf.c:1.33 Thu Aug 23 22:54:05 2001 +++ squid/src/cache_cf.c Wed Oct 10 14:17:31 2001 @@ -1376,8 +1376,10 @@ #endif #if USE_CACHE_DIGESTS if (!p->options.no_digest) { - p->digest = peerDigestCreate(p); - cbdataLock(p->digest); /* so we know when/if digest disappears */ + /* XXX This looks odd.. who has the original pointer + * then? + */ + p->digest = cbdataReference(peerDigestCreate(p)); } #endif while (*head != NULL) @@ -1394,9 +1396,7 @@ while ((p = *P) != NULL) { *P = p->next; #if USE_CACHE_DIGESTS - if (p->digest) - cbdataUnlock(p->digest); - p->digest = NULL; + cbdataReferenceDone(p->digest); #endif cbdataFree(p); } Index: squid/src/cbdata.c diff -u squid/src/cbdata.c:1.13 squid/src/cbdata.c:1.13.12.7 --- squid/src/cbdata.c:1.13 Tue Apr 10 06:20:52 2001 +++ squid/src/cbdata.c Wed Oct 10 14:25:11 2001 @@ -42,37 +42,21 @@ * pointers, lock them just before registering the callback function, * validate them before issuing the callback, and then free them * when finished. - * - * In terms of time, the sequence goes something like this: - * - * foo = cbdataAlloc(sizeof(foo),NULL); - * ... - * some_blocking_operation(..., callback_func, foo); - * cbdataLock(foo); - * ... - * some_blocking_operation_completes() - * if (cbdataValid(foo)) - * callback_func(..., foo) - * cbdataUnlock(foo); - * ... - * cbdataFree(foo); - * - * The nice thing is that, we do not need to require that Unlock - * occurs before Free. If the Free happens first, then the - * callback data is marked invalid and the callback will never - * be made. When we Unlock and the lock count reaches zero, - * we free the memory if it is marked invalid. */ #include "squid.h" static int cbdataCount = 0; +#if CBDATA_DEBUG +dlink_list cbdataEntries; +#endif typedef struct _cbdata { int valid; int locks; int type; #if CBDATA_DEBUG + dlink_node link; const char *file; int line; #endif @@ -132,6 +116,9 @@ cbdataDump, 0, 1); #define CREATE_CBDATA(type) cbdataInitType(CBDATA_##type, #type, sizeof(type), NULL) #define CREATE_CBDATA_FREE(type, free_func) cbdataInitType(CBDATA_##type, #type, sizeof(type), free_func) + /* XXX + * most of these should be moved out to their respective module. + */ CREATE_CBDATA(acl_access); CREATE_CBDATA(aclCheck_t); CREATE_CBDATA(clientHttpRequest); @@ -172,15 +159,26 @@ p->y = p; cbdataCount++; +#if CBDATA_DEBUG + dlinkAdd(p, &p->link, &cbdataEntries); +#endif return (void *) &p->data; } void * +#if CBDATA_DEBUG +cbdataInternalFreeDbg(void *p, const char *file, int line) +#else cbdataInternalFree(void *p) +#endif { cbdata *c; FREE *free_func; +#if CBDATA_DEBUG + debug(45, 3) ("cbdataFree: %p %s:%d\n", p, file, line); +#else debug(45, 3) ("cbdataFree: %p\n", p); +#endif c = (cbdata *) (((char *) p) - OFFSET_OF(cbdata, data)); assert(c->y == c); c->valid = 0; @@ -191,6 +189,9 @@ } cbdataCount--; debug(45, 3) ("cbdataFree: Freeing %p\n", p); +#if CBDATA_DEBUG + dlinkDelete(&c->link, &cbdataEntries); +#endif free_func = cbdata_index[c->type].free_func; if (free_func) free_func((void *) p); @@ -198,23 +199,11 @@ return NULL; } -int -cbdataLocked(const void *p) -{ - cbdata *c; - assert(p); - c = (cbdata *) (((char *) p) - OFFSET_OF(cbdata, data)); - assert(c->y == c); - debug(45, 3) ("cbdataLocked: %p = %d\n", p, c->locks); - assert(c != NULL); - return c->locks; -} - void #if CBDATA_DEBUG -cbdataLockDbg(const void *p, const char *file, int line) +cbdataInternalLockDbg(const void *p, const char *file, int line) #else -cbdataLock(const void *p) +cbdataInternalLock(const void *p) #endif { cbdata *c; @@ -222,20 +211,20 @@ return; c = (cbdata *) (((char *) p) - OFFSET_OF(cbdata, data)); assert(c->y == c); +#if CBDATA_DEBUG + debug(45, 3) ("cbdataLock: %p %s:%d\n", p, file, line); +#else debug(45, 3) ("cbdataLock: %p\n", p); +#endif assert(c != NULL); c->locks++; -#if CBDATA_DEBUG - c->file = file; - c->line = line; -#endif } void #if CBDATA_DEBUG -cbdataUnlockDbg(const void *p, const char *file, int line) +cbdataInternalUnlockDbg(const void *p, const char *file, int line) #else -cbdataUnlock(const void *p) +cbdataInternalUnlock(const void *p) #endif { cbdata *c; @@ -244,18 +233,21 @@ return; c = (cbdata *) (((char *) p) - OFFSET_OF(cbdata, data)); assert(c->y == c); +#if CBDATA_DEBUG + debug(45, 3) ("cbdataUnlock: %p %s:%d\n", p, file, line); +#else debug(45, 3) ("cbdataUnlock: %p\n", p); +#endif assert(c != NULL); assert(c->locks > 0); c->locks--; -#if CBDATA_DEBUG - c->file = file; - c->line = line; -#endif if (c->valid || c->locks) return; cbdataCount--; debug(45, 3) ("cbdataUnlock: Freeing %p\n", p); +#if CBDATA_DEBUG + dlinkDelete(&c->link, &cbdataEntries); +#endif free_func = cbdata_index[c->type].free_func; if (free_func) free_func((void *) p); @@ -275,9 +267,54 @@ return c->valid; } +int +void +#if CBDATA_DEBUG +cbdataInternalReferenceDoneValidDgb(const void **pp, const char *file, int line) +#else +cbdataInternalReferenceDoneValid(const void **pp) +#endif +{ + void *p = *pp; + int valid = cbdataValid(p); +#if CBDATA_DEBUG + cbdataInternalUnlockDbg(p, file, line); +#else + cbdataInternalUnlock(p); +#endif + if (valid) + return p; + else + return NULL; +} + + static void cbdataDump(StoreEntry * sentry) { +#if CBDATA_DEBUG + dlink_node *n; + cbdata *p; + int i; +#endif storeAppendPrintf(sentry, "%d cbdata entries\n", cbdataCount); - storeAppendPrintf(sentry, "see also memory pools section\n"); +#if CBDATA_DEBUG + storeAppendPrintf(sentry, "Pointer\tType\tLocks\tAllocated by\n"); + for (n = cbdataEntries.head; n; n = n->next) { + p = n->data; + storeAppendPrintf(sentry, "%c%p\t%d\t%d\t%20s:%-5d\n", p->valid ? ' ' : '!', &p->data, p->type, p->locks, p->file, p->line); + } + storeAppendPrintf(sentry, "\n"); + storeAppendPrintf(sentry, "types\tsize\tallocated\ttotal\n"); + for (i=1; i < cbdata_types; i++) { + MemPool *pool = cbdata_index[i].pool; + if (pool) { + int obj_size = pool->obj_size - OFFSET_OF(cbdata, data); + storeAppendPrintf(sentry, "%s\t%d\t%d\t%d\n", pool->label + 7, obj_size, pool->meter.inuse.level, obj_size * pool->meter.inuse.level); + } + } +#else + storeAppendPrintf(sentry, "detailed allocation information only available when compiled with CBDATA_DEBUG\n"); +#endif + storeAppendPrintf(sentry, "\nsee also \"Memory utilization\" for detailed per type statistics\n"); } Index: squid/src/client_side.c diff -u squid/src/client_side.c:1.37 squid/src/client_side.c:1.27.6.3 --- squid/src/client_side.c:1.37 Mon Sep 24 00:07:28 2001 +++ squid/src/client_side.c Fri Sep 28 00:49:20 2001 @@ -158,8 +158,7 @@ * place to store the ident result on persistent connections... */ /* connection oriented auth also needs these two lines for it's operation. */ - ch->conn = conn; - cbdataLock(ch->conn); + ch->conn = cbdataReference(conn); /* unreferenced in acl.c */ return ch; } @@ -2820,13 +2819,6 @@ for (H = &conn->chr; *H; H = &(*H)->next); *H = http; conn->nrequests++; - /* - * I wanted to lock 'http' here since its callback data for - * clientLifetimeTimeout(), but there's no logical place to - * cbdataUnlock if the timeout never happens. Maybe its safe - * enough to assume that if the FD is open, and the timeout - * triggers, that 'http' is valid. - */ commSetTimeout(fd, Config.Timeout.lifetime, clientLifetimeTimeout, http); if (parser_return_code < 0) { debug(33, 1) ("clientReadRequest: FD %d Invalid Request\n", fd); Index: squid/src/comm.c diff -u squid/src/comm.c:1.14 squid/src/comm.c:1.12.10.4 --- squid/src/comm.c:1.14 Sun Aug 26 15:24:05 2001 +++ squid/src/comm.c Wed Oct 10 14:17:31 2001 @@ -98,7 +98,7 @@ CommWriteState->handler = NULL; if (callback && cbdataValid(data)) callback(fd, CommWriteState->buf, CommWriteState->offset, code, data); - cbdataUnlock(data); + cbdataReferenceDone(data); memPoolFree(comm_write_pool, CommWriteState); } @@ -240,8 +240,7 @@ cs->host = xstrdup(host); cs->port = port; cs->callback = callback; - cs->data = data; - cbdataLock(cs->data); + cs->data = cbdataReference(data); comm_add_close_handler(fd, commConnectFree, cs); cs->locks++; ipcache_nbgethostbyname(host, commConnectDnsHandle, cs); @@ -284,7 +283,7 @@ commConnectFree(fd, cs); if (cbdataValid(data)) callback(fd, status, data); - cbdataUnlock(data); + cbdataReferenceDone(data); } static void @@ -292,8 +291,7 @@ { ConnectStateData *cs = data; debug(5, 3) ("commConnectFree: FD %d\n", fd); - if (cs->data) - cbdataUnlock(cs->data); + cbdataReferenceDone(cs->data); safe_free(cs->host); cbdataFree(cs); } @@ -404,13 +402,13 @@ assert(F->flags.open); if (timeout < 0) { F->timeout_handler = NULL; - F->timeout_data = NULL; + cbdataReferenceDone(F->timeout_data); return F->timeout = 0; } assert(handler || F->timeout_handler); if (handler || data) { F->timeout_handler = handler; - F->timeout_data = data; + F->timeout_data = cbdataReference(data); } return F->timeout = squid_curtime + (time_t) timeout; } @@ -529,7 +527,7 @@ debug(5, 5) ("commCallCloseHandlers: ch->handler=%p\n", ch->handler); if (cbdataValid(ch->data)) ch->handler(fd, ch->data); - cbdataUnlock(ch->data); + cbdataReferenceDone(ch->data); memPoolFree(conn_close_pool, ch); /* AAA */ } } @@ -673,10 +671,9 @@ for (c = fd_table[fd].close_handler; c; c = c->next) assert(c->handler != handler || c->data != data); new->handler = handler; - new->data = data; + new->data = cbdataReference(data); new->next = fd_table[fd].close_handler; fd_table[fd].close_handler = new; - cbdataLock(data); } void @@ -696,9 +693,8 @@ last->next = p->next; else fd_table[fd].close_handler = p->next; - cbdataUnlock(p->data); - memPoolFree(conn_close_pool, p); /* AAA */ - + cbdataReferenceDone(p->data); + memPoolFree(conn_close_pool, p); } static void @@ -892,9 +888,8 @@ state->size = size; state->offset = 0; state->handler = handler; - state->handler_data = handler_data; + state->handler_data = cbdataReference(handler_data); state->free_func = free_func; - cbdataLock(handler_data); commSetSelect(fd, COMM_SELECT_WRITE, commHandleWrite, state, 0); } @@ -936,6 +931,7 @@ int fd; fde *F = NULL; PF *callback; + void *cbdata; for (fd = 0; fd <= Biggest_FD; fd++) { F = &fd_table[fd]; if (!F->flags.open) @@ -948,8 +944,12 @@ debug(5, 5) ("commCloseAllSockets: FD %d: Calling timeout handler\n", fd); callback = F->timeout_handler; + cbdata = F->timeout_data; F->timeout_handler = NULL; - callback(fd, F->timeout_data); + F->timeout_data = NULL; + if (cbdataValid(F->timeout_data)) + callback(fd, cbdata); + cbdataReferenceDone(cbdata); } else { debug(5, 5) ("commCloseAllSockets: FD %d: calling comm_close()\n", fd); comm_close(fd); Index: squid/src/defines.h diff -u squid/src/defines.h:1.13 squid/src/defines.h:1.11.4.9 --- squid/src/defines.h:1.13 Thu Aug 16 00:39:03 2001 +++ squid/src/defines.h Wed Oct 10 14:25:11 2001 @@ -279,8 +279,19 @@ #endif /* cbdata macros */ +#if CBDATA_DEBUG +#define cbdataAlloc(type) ((type *)cbdataInternalAllocDbg(CBDATA_##type,__FILE__,__LINE__)) +#define cbdataFree(var) do {if (var) {cbdataInternalFreeDbg(var,__FILE__,__LINE__); var = NULL;}} while(0) +#define cbdataInternalLock(a) cbdataInternalLockDbg(a,__FILE__,__LINE__) +#define cbdataInternalUnlock(a) cbdataInternalUnlockDbg(a,__FILE__,__LINE__) +#define cbdataReferenceDone(var) cbdataInternalReferenceDoneDbg(&(var),__FILE__,__LINE__) +#else #define cbdataAlloc(type) ((type *)cbdataInternalAlloc(CBDATA_##type)) -#define cbdataFree(var) (var = (var != NULL ? cbdataInternalFree(var): NULL)) +#define cbdataFree(var) do {if (var) {cbdataInternalFree(var); var = NULL;}} while(0) +#define cbdataReferenceDone(var) cbdataInternalReferenceDone(&(var)) +#endif +#define cbdataReference(var) (cbdataInternalLock(var), var) +#define cbdataReferenceDone(var) do {if (var) {cbdataInternalUnlock(var); var = NULL;}} while(0) #define CBDATA_TYPE(type) static cbdata_type CBDATA_##type = 0 #define CBDATA_GLOBAL_TYPE(type) cbdata_type CBDATA_##type #define CBDATA_INIT_TYPE(type) (CBDATA_##type ? 0 : (CBDATA_##type = cbdataAddType(CBDATA_##type, #type, sizeof(type), NULL))) Index: squid/src/disk.c diff -u squid/src/disk.c:1.8 squid/src/disk.c:1.6.10.5 --- squid/src/disk.c:1.8 Thu Aug 16 00:39:03 2001 +++ squid/src/disk.c Wed Oct 10 14:25:11 2001 @@ -259,7 +259,7 @@ } else { /* another block is queued */ diskCombineWrites(fdd); - cbdataLock(fdd->wrt_handle_data); + cbdataInternalLock(fdd->wrt_handle_data); /* ??? */ commSetSelect(fd, COMM_SELECT_WRITE, diskHandleWrite, NULL, 0); F->flags.write_daemon = 1; } @@ -272,7 +272,7 @@ else do_callback = 0; if (fdd->wrt_handle_data != NULL) - cbdataUnlock(fdd->wrt_handle_data); + cbdataInternalUnlock(fdd->wrt_handle_data); /* ??? */ if (do_callback) { fdd->wrt_handle(fd, status, len, fdd->wrt_handle_data); /* @@ -322,7 +322,7 @@ F->disk.write_q_tail = wq; } if (!F->flags.write_daemon) { - cbdataLock(F->disk.wrt_handle_data); + cbdataInternalLock(F->disk.wrt_handle_data); /* ??? */ diskHandleWrite(fd, NULL); } } @@ -379,7 +379,7 @@ } if (cbdataValid(ctrl_dat->client_data)) ctrl_dat->handler(fd, ctrl_dat->buf, len, rc, ctrl_dat->client_data); - cbdataUnlock(ctrl_dat->client_data); + cbdataReferenceDone(ctrl_dat->client_data); memFree(ctrl_dat, MEM_DREAD_CTRL); } @@ -400,7 +400,6 @@ ctrl_dat->buf = buf; ctrl_dat->end_of_file = 0; ctrl_dat->handler = handler; - ctrl_dat->client_data = client_data; - cbdataLock(client_data); + ctrl_dat->client_data = cbdataReference(client_data); diskHandleRead(fd, ctrl_dat); } Index: squid/src/dns_internal.c diff -u squid/src/dns_internal.c:1.11 squid/src/dns_internal.c:1.8.26.6 --- squid/src/dns_internal.c:1.11 Thu Aug 16 00:39:03 2001 +++ squid/src/dns_internal.c Wed Oct 10 14:17:31 2001 @@ -439,7 +439,6 @@ idnsGrokReply(const char *buf, size_t sz) { int n; - int valid; rfc1035_rr *answers = NULL; unsigned short rid = 0xFFFF; idns_query *q; @@ -476,10 +475,9 @@ return; } } - valid = cbdataValid(q->callback_data); - cbdataUnlock(q->callback_data); - if (valid) + if (cbdataValid(q->callback_data)) q->callback(q->callback_data, answers, n); + cbdataReferenceDone(q->callback_data); rfc1035RRDestroy(answers, n); memFree(q, MEM_IDNS_QUERY); } @@ -578,13 +576,12 @@ if (tvSubDsec(q->start_t, current_time) < Config.Timeout.idns_query) { idnsSendQuery(q); } else { - int v = cbdataValid(q->callback_data); debug(78, 1) ("idnsCheckQueue: ID %x: giving up after %d tries and %5.1f seconds\n", (int) q->id, q->nsends, tvSubDsec(q->start_t, current_time)); - cbdataUnlock(q->callback_data); - if (v) + if (cbdataValid(q->callback_data)) q->callback(q->callback_data, NULL, 0); + cbdataReferenceDone(q->callback_data); memFree(q, MEM_IDNS_QUERY); } } @@ -676,8 +673,7 @@ debug(78, 3) ("idnsALookup: buf is %d bytes for %s, id = %#hx\n", (int) q->sz, name, q->id); q->callback = callback; - q->callback_data = data; - cbdataLock(q->callback_data); + q->callback_data = cbdataReference(data); q->start_t = current_time; idnsSendQuery(q); } @@ -691,8 +687,7 @@ debug(78, 3) ("idnsPTRLookup: buf is %d bytes for %s, id = %#hx\n", (int) q->sz, inet_ntoa(addr), q->id); q->callback = callback; - q->callback_data = data; - cbdataLock(q->callback_data); + q->callback_data = cbdataReference(data); q->start_t = current_time; idnsSendQuery(q); } Index: squid/src/event.c diff -u squid/src/event.c:1.4 squid/src/event.c:1.4.40.4 --- squid/src/event.c:1.4 Fri Jan 12 00:20:32 2001 +++ squid/src/event.c Wed Oct 10 14:17:31 2001 @@ -57,13 +57,11 @@ struct ev_entry *event = memAllocate(MEM_EVENT); struct ev_entry **E; event->func = func; - event->arg = arg; + event->arg = cbdataReference(arg); event->name = name; event->when = current_dtime + when; event->weight = weight; event->id = run_id; - if (NULL != arg) - cbdataLock(arg); debug(41, 7) ("eventAdd: Adding '%s', in %f seconds\n", name, when); /* Insert after the last event with the same or earlier time */ for (E = &tasks; *E; E = &(*E)->next) { @@ -100,8 +98,7 @@ if (event->arg != arg) continue; *E = event->next; - if (NULL != event->arg) - cbdataUnlock(event->arg); + cbdataReferenceDone(event->arg); memFree(event, MEM_EVENT); return; } @@ -112,8 +109,6 @@ eventRun(void) { struct ev_entry *event = NULL; - EVH *func; - void *arg; int weight = 0; if (NULL == tasks) return; @@ -122,30 +117,22 @@ run_id++; debug(41, 5) ("eventRun: RUN ID %d\n", run_id); while ((event = tasks)) { - int valid = 1; if (event->when > current_dtime) break; if (event->id == run_id) /* was added during this run */ break; if (weight) break; - func = event->func; - arg = event->arg; - event->func = NULL; - event->arg = NULL; tasks = event->next; - if (NULL != arg) { - valid = cbdataValid(arg); - cbdataUnlock(arg); - } - if (valid) { + if (cbdataValid(event->arg)) { weight += event->weight; /* XXX assumes ->name is static memory! */ last_event_ran = event->name; debug(41, 5) ("eventRun: Running '%s', id %d\n", event->name, event->id); - func(arg); + event->func(event->arg); } + cbdataReferenceDone(event->arg); memFree(event, MEM_EVENT); } } @@ -192,8 +179,7 @@ struct ev_entry *event; while ((event = tasks)) { tasks = event->next; - if (NULL != event->arg) - cbdataUnlock(event->arg); + cbdataReferenceDone(event->arg); memFree(event, MEM_EVENT); } tasks = NULL; Index: squid/src/forward.c diff -u squid/src/forward.c:1.12 squid/src/forward.c:1.12.22.3 --- squid/src/forward.c:1.12 Fri Mar 30 14:29:38 2001 +++ squid/src/forward.c Wed Oct 10 14:17:31 2001 @@ -72,8 +72,7 @@ static void fwdServerFree(FwdServer * fs) { - if (fs->peer) - cbdataUnlock(fs->peer); + cbdataReferenceDone(fs->peer); memFree(fs, MEM_FWD_SERVER); } Index: squid/src/fqdncache.c diff -u squid/src/fqdncache.c:1.14 squid/src/fqdncache.c:1.14.28.3 --- squid/src/fqdncache.c:1.14 Sat Mar 3 02:44:32 2001 +++ squid/src/fqdncache.c Wed Oct 10 14:17:31 2001 @@ -216,7 +216,7 @@ dns_error_message = f->error_message; handler(f->flags.negcached ? NULL : f->names[0], handlerData); } - cbdataUnlock(handlerData); + cbdataReferenceDone(handlerData); fqdncacheUnlockEntry(f); } @@ -374,8 +374,7 @@ else FqdncacheStats.hits++; f->handler = handler; - f->handlerData = handlerData; - cbdataLock(handlerData); + f->handlerData = cbdataReference(handlerData); fqdncacheCallback(f); return; } @@ -384,8 +383,7 @@ FqdncacheStats.misses++; f = fqdncacheCreateEntry(name); f->handler = handler; - f->handlerData = handlerData; - cbdataLock(handlerData); + f->handlerData = cbdataReference(handlerData); f->request_time = current_time; c = cbdataAlloc(generic_cbdata); c->data = f; Index: squid/src/helper.c diff -u squid/src/helper.c:1.13 squid/src/helper.c:1.10.10.5 --- squid/src/helper.c:1.13 Thu Aug 30 09:24:13 2001 +++ squid/src/helper.c Wed Oct 10 14:17:31 2001 @@ -111,8 +111,7 @@ srv->buf = memAllocate(MEM_8K_BUF); srv->buf_sz = 8192; srv->offset = 0; - srv->parent = hlp; - cbdataLock(hlp); /* lock because of the parent backlink */ + srv->parent = cbdataReference(hlp); dlinkAddTail(srv, &srv->link, &hlp->servers); if (rfd == wfd) { snprintf(fd_note_buf, FD_DESC_SZ, "%s #%d", shortname, k + 1); @@ -194,10 +193,9 @@ srv->buf = memAllocate(MEM_8K_BUF); srv->buf_sz = 8192; srv->offset = 0; - srv->parent = hlp; + srv->parent = cbdataReference(hlp); if (hlp->datapool != NULL) srv->data = memPoolAlloc(hlp->datapool); - cbdataLock(hlp); /* lock because of the parent backlink */ dlinkAddTail(srv, &srv->link, &hlp->servers); if (rfd == wfd) { snprintf(fd_note_buf, FD_DESC_SZ, "%s #%d", shortname, k + 1); @@ -230,9 +228,8 @@ return; } r->callback = callback; - r->data = data; + r->data = cbdataReference(data); r->buf = xstrdup(buf); - cbdataLock(r->data); if ((srv = GetFirstAvailable(hlp))) helperDispatch(srv, r); else @@ -254,15 +251,14 @@ return; } r->callback = callback; - r->data = data; - if (buf != NULL) { + r->data = cbdataReference(data); + if (buf != NULL) r->buf = xstrdup(buf); r->placeholder = 0; } else { r->buf = NULL; r->placeholder = 1; } - cbdataLock(r->data); if ((buf != NULL) && lastserver) { debug(29, 5) ("StatefulSubmit with lastserver %d\n", lastserver); /* the queue doesn't count for this assert because queued requests @@ -649,7 +645,7 @@ if (hlp->n_running < hlp->n_to_start / 2) fatalf("Too few %s processes are running", hlp->id_name); } - cbdataUnlock(srv->parent); + cbdataReferenceDone(srv->parent); cbdataFree(srv); } @@ -683,7 +679,7 @@ } if (srv->data != NULL) memPoolFree(hlp->datapool, srv->data); - cbdataUnlock(srv->parent); + cbdataReferenceDone(srv->parent); cbdataFree(srv); } @@ -1102,7 +1098,7 @@ static void helperRequestFree(helper_request * r) { - cbdataUnlock(r->data); + cbdataReferenceDone(r->data); xfree(r->buf); memFree(r, MEM_HELPER_REQUEST); } @@ -1110,7 +1106,7 @@ static void helperStatefulRequestFree(helper_stateful_request * r) { - cbdataUnlock(r->data); + cbdataReferenceDone(r->data); xfree(r->buf); memFree(r, MEM_HELPER_STATEFUL_REQUEST); } Index: squid/src/ident.c diff -u squid/src/ident.c:1.8 squid/src/ident.c:1.8.10.3 --- squid/src/ident.c:1.8 Fri Apr 13 17:31:02 2001 +++ squid/src/ident.c Wed Oct 10 14:17:31 2001 @@ -73,7 +73,7 @@ state->clients = client->next; if (cbdataValid(client->callback_data)) client->callback(result, client->callback_data); - cbdataUnlock(client->callback_data); + cbdataReferenceDone(client->callback_data); xfree(client); } } @@ -172,8 +172,7 @@ IdentClient *c = xcalloc(1, sizeof(*c)); IdentClient **C; c->callback = callback; - c->callback_data = callback_data; - cbdataLock(callback_data); + c->callback_data = cbdataReference(callback_data); for (C = &state->clients; *C; C = &(*C)->next); *C = c; } Index: squid/src/ipcache.c diff -u squid/src/ipcache.c:1.15 squid/src/ipcache.c:1.15.28.3 --- squid/src/ipcache.c:1.15 Sat Mar 3 02:44:32 2001 +++ squid/src/ipcache.c Wed Oct 10 14:17:31 2001 @@ -226,7 +226,7 @@ dns_error_message = i->error_message; handler(i->flags.negcached ? NULL : &i->addrs, handlerData); } - cbdataUnlock(handlerData); + cbdataReferenceDone(handlerData); ipcacheUnlockEntry(i); } @@ -420,8 +420,7 @@ else IpcacheStats.hits++; i->handler = handler; - i->handlerData = handlerData; - cbdataLock(handlerData); + i->handlerData = cbdataReference(handlerData); ipcacheCallback(i); return; } @@ -429,8 +428,7 @@ IpcacheStats.misses++; i = ipcacheCreateEntry(name); i->handler = handler; - i->handlerData = handlerData; - cbdataLock(handlerData); + i->handlerData = cbdataReference(handlerData); i->request_time = current_time; c = cbdataAlloc(generic_cbdata); c->data = i; Index: squid/src/neighbors.c diff -u squid/src/neighbors.c:1.12 squid/src/neighbors.c:1.11.10.4 --- squid/src/neighbors.c:1.12 Tue Jun 26 23:49:54 2001 +++ squid/src/neighbors.c Wed Oct 10 14:17:31 2001 @@ -955,11 +955,7 @@ } safe_free(p->host); #if USE_CACHE_DIGESTS - if (p->digest) { - PeerDigest *pd = p->digest; - p->digest = NULL; - cbdataUnlock(pd); - } + cbdataReferenceDone(p->digest); #endif } @@ -967,11 +963,7 @@ peerNoteDigestGone(peer * p) { #if USE_CACHE_DIGESTS - if (p->digest) { - PeerDigest *pd = p->digest; - p->digest = NULL; - cbdataUnlock(pd); - } + cbdataReferenceDone(p->digest); #endif } Index: squid/src/net_db.c diff -u squid/src/net_db.c:1.11 squid/src/net_db.c:1.10.28.4 --- squid/src/net_db.c:1.11 Wed Jun 13 00:20:56 2001 +++ squid/src/net_db.c Wed Oct 10 14:17:31 2001 @@ -648,7 +648,7 @@ requestUnlink(ex->r); storeUnregister(ex->sc, ex->e, ex); storeUnlockObject(ex->e); - cbdataUnlock(ex->p); + cbdataReferenceDone(ex->p); cbdataFree(ex); } @@ -994,8 +994,7 @@ netdbExchangeState *ex; CBDATA_INIT_TYPE(netdbExchangeState); ex = cbdataAlloc(netdbExchangeState); - cbdataLock(p); - ex->p = p; + ex->p = cbdataReference(p); uri = internalRemoteUri(p->host, p->http_port, "/squid-internal-dynamic/", "netdb"); debug(38, 3) ("netdbExchangeStart: Requesting '%s'\n", uri); assert(NULL != uri); Index: squid/src/peer_digest.c diff -u squid/src/peer_digest.c:1.9 squid/src/peer_digest.c:1.9.10.3 --- squid/src/peer_digest.c:1.9 Fri Apr 13 17:31:02 2001 +++ squid/src/peer_digest.c Wed Oct 10 14:17:31 2001 @@ -109,9 +109,9 @@ CBDATA_INIT_TYPE(PeerDigest); pd = cbdataAlloc(PeerDigest); peerDigestInit(pd, p); - cbdataLock(pd->peer); /* we will use the peer */ - return pd; + /* XXX This does not look right, and the same thing again in the caller */ + return cbdataReference(pd); } /* call Clean and free/unlock everything */ @@ -126,7 +126,7 @@ /* inform peer (if any) that we are gone */ if (cbdataValid(p)) peerNoteDigestGone(p); - cbdataUnlock(p); /* must unlock, valid or not */ + cbdataReferenceDone(p); peerDigestClean(pd); cbdataFree(pd); @@ -300,7 +300,7 @@ CBDATA_INIT_TYPE(DigestFetchState); fetch = cbdataAlloc(DigestFetchState); fetch->request = requestLink(req); - fetch->pd = pd; + fetch->pd = cbdataReference(pd); fetch->offset = 0; /* update timestamps */ @@ -328,8 +328,6 @@ /* push towards peer cache */ debug(72, 3) ("peerDigestRequest: forwarding to fwdStart...\n"); fwdStart(-1, e, req); - cbdataLock(fetch); - cbdataLock(fetch->pd); storeClientCopy(fetch->sc, e, 0, 0, 4096, memAllocate(MEM_4K_BUF), peerDigestFetchReply, fetch); } @@ -675,8 +673,7 @@ else debug(72, 2) ("received valid digest from %s\n", host); } - fetch->pd = NULL; - cbdataUnlock(pd); + cbdataReferenceDone(fetch->pd); } /* free fetch state structures @@ -706,7 +703,6 @@ fetch->entry = NULL; fetch->request = NULL; assert(fetch->pd == NULL); - cbdataUnlock(fetch); cbdataFree(fetch); } Index: squid/src/peer_select.c diff -u squid/src/peer_select.c:1.9 squid/src/peer_select.c:1.9.10.3 --- squid/src/peer_select.c:1.9 Fri Apr 13 17:31:02 2001 +++ squid/src/peer_select.c Wed Oct 10 14:17:31 2001 @@ -143,14 +143,13 @@ psstate->request = requestLink(request); psstate->entry = entry; psstate->callback = callback; - psstate->callback_data = callback_data; + psstate->callback_data = cbdataReference(callback_data); psstate->direct = DIRECT_UNKNOWN; #if USE_CACHE_DIGESTS request->hier.peer_select_start = current_time; #endif if (psstate->entry) storeLockObject(psstate->entry); - cbdataLock(callback_data); peerSelectFoo(psstate); } @@ -180,6 +179,7 @@ StoreEntry *entry = psstate->entry; FwdServer *fs = psstate->servers; void *data = psstate->callback_data; + psstate->callback_data = NULL; if (entry) { debug(44, 3) ("peerSelectCallback: %s\n", storeUrl(entry)); if (entry->ping_status == PING_WAITING) @@ -198,7 +198,7 @@ psstate->servers = NULL; psstate->callback(fs, data); } - cbdataUnlock(data); + cbdataReferenceDone(data); peerSelectStateFree(psstate); } @@ -495,7 +495,7 @@ if (!cbdataValid(psstate->callback_data)) { /* request aborted */ entry->ping_status = PING_DONE; - cbdataUnlock(psstate->callback_data); + cbdataReferenceDone(psstate->callback_data); peerSelectStateFree(psstate); return; } @@ -649,9 +649,8 @@ debug(44, 5) ("peerAddFwdServer: adding %s %s\n", p ? p->host : "DIRECT", hier_strings[code]); - fs->peer = p; + fs->peer = cbdataReference(p); fs->code = code; - cbdataLock(fs->peer); while (*FS) FS = &(*FS)->next; *FS = fs; Index: squid/src/protos.h diff -u squid/src/protos.h:1.34 squid/src/protos.h:1.24.6.9 --- squid/src/protos.h:1.34 Sun Sep 9 13:02:46 2001 +++ squid/src/protos.h Wed Oct 10 14:25:11 2001 @@ -102,20 +102,21 @@ */ extern void cbdataInit(void); #if CBDATA_DEBUG -extern void *cbdataInternalAllocDbg(cbdata_type type, int, const char *); -extern void cbdataLockDbg(const void *p, const char *, int); -extern void cbdataUnlockDbg(const void *p, const char *, int); +extern void *cbdataInternalAllocDbg(cbdata_type type, const char *, int); +extern void *cbdataInternalFreeDbg(void *p, const char *, int); +extern void cbdataInternalLockDbg(const void *p, const char *, int); +extern void cbdataInternalUnlockDbg(const void *p, const char *, int); +extern void *cbdataInternalReferenceDoneDbg(const void *p, const char *, int); #else extern void *cbdataInternalAlloc(cbdata_type type); -extern void cbdataLock(const void *p); -extern void cbdataUnlock(const void *p); -#endif -/* Note: Allocations is done using the cbdataAlloc macro */ extern void *cbdataInternalFree(void *p); +extern void cbdataInternalLock(const void *p); +extern void cbdataInternalUnlock(const void *p); +extern void *cbdataInternalReferenceDone(const void *p); +#endif extern int cbdataValid(const void *p); extern void cbdataInitType(cbdata_type type, char *label, int size, FREE * free_func); extern cbdata_type cbdataAddType(cbdata_type type, char *label, int size, FREE * free_func); -extern int cbdataLocked(const void *p); extern void clientdbInit(void); extern void clientdbUpdate(struct in_addr, log_type, protocol_t, size_t); Index: squid/src/redirect.c diff -u squid/src/redirect.c:1.7 squid/src/redirect.c:1.7.28.4 --- squid/src/redirect.c:1.7 Sat Mar 3 02:44:32 2001 +++ squid/src/redirect.c Wed Oct 10 14:17:31 2001 @@ -55,7 +55,6 @@ redirectHandleReply(void *data, char *reply) { redirectStateData *r = data; - int valid; char *t; debug(29, 5) ("redirectHandleRead: {%s}\n", reply ? reply : ""); if (reply) { @@ -64,10 +63,9 @@ if (*reply == '\0') reply = NULL; } - valid = cbdataValid(r->data); - cbdataUnlock(r->data); - if (valid) + if (cbdataValid(r->data)) r->handler(r->data, reply); + cbdataReferenceDone(r->data); redirectStateFree(r); } @@ -135,8 +133,7 @@ } r->method_s = RequestMethodStr[http->request->method]; r->handler = handler; - r->data = data; - cbdataLock(r->data); + r->data = cbdataReference(data); if ((fqdn = fqdncache_gethostbyaddr(r->client_addr, 0)) == NULL) fqdn = dash_str; snprintf(buf, 8192, "%s %s/%s %s %s\n", Index: squid/src/squid.h diff -u squid/src/squid.h:1.12 squid/src/squid.h:1.12.10.1 --- squid/src/squid.h:1.12 Fri Apr 13 17:31:02 2001 +++ squid/src/squid.h Sat Apr 21 02:10:45 2001 @@ -341,12 +341,6 @@ #define LOCAL_ARRAY(type,name,size) static type name[size] #endif -#if CBDATA_DEBUG -#define cbdataAlloc(a,b) cbdataAllocDbg(a,b,__FILE__,__LINE__) -#define cbdataLock(a) cbdataLockDbg(a,__FILE__,__LINE__) -#define cbdataUnlock(a) cbdataUnlockDbg(a,__FILE__,__LINE__) -#endif - #if USE_LEAKFINDER #define leakAdd(p) leakAddFL(p,__FILE__,__LINE__) #define leakTouch(p) leakTouchFL(p,__FILE__,__LINE__) Index: squid/src/ssl.c diff -u squid/src/ssl.c:1.9 squid/src/ssl.c:1.8.10.3 --- squid/src/ssl.c:1.9 Tue Jul 17 03:37:01 2001 +++ squid/src/ssl.c Wed Oct 10 14:25:11 2001 @@ -211,7 +211,7 @@ kb_incr(&statCounter.server.other.kbytes_in, len); sslState->server.len += len; } - cbdataLock(sslState); + cbdataInternalLock(sslState); /* ??? should be locked by the caller... */ if (len < 0) { debug(50, ignoreErrno(errno) ? 3 : 1) ("sslReadServer: FD %d: read failure: %s\n", fd, xstrerror()); @@ -222,7 +222,7 @@ } if (cbdataValid(sslState)) sslSetSelect(sslState); - cbdataUnlock(sslState); + cbdataInternalUnlock(sslState); /* ??? */ } /* Read from client side and queue it for writing to the server */ @@ -245,7 +245,7 @@ kb_incr(&statCounter.client_http.kbytes_in, len); sslState->client.len += len; } - cbdataLock(sslState); + cbdataInternalLock(sslState); /* ??? should be locked by the caller... */ if (len < 0) { int level = 1; #ifdef ECONNRESET @@ -263,7 +263,7 @@ } if (cbdataValid(sslState)) sslSetSelect(sslState); - cbdataUnlock(sslState); + cbdataInternalUnlock(sslState); /* ??? */ } /* Writes data from the client buffer to the server side */ @@ -293,7 +293,7 @@ sslState->client.len); } } - cbdataLock(sslState); + cbdataInternalLock(sslState); /* ??? should be locked by the caller... */ if (len < 0) { debug(50, ignoreErrno(errno) ? 3 : 1) ("sslWriteServer: FD %d: write failure: %s.\n", fd, xstrerror()); @@ -302,7 +302,7 @@ } if (cbdataValid(sslState)) sslSetSelect(sslState); - cbdataUnlock(sslState); + cbdataInternalUnlock(sslState); /* ??? */ } /* Writes data from the server buffer to the client side */ @@ -334,7 +334,7 @@ sslState->server.len); } } - cbdataLock(sslState); + cbdataInternalLock(sslState); /* ??? should be locked by the caller... */ if (len < 0) { debug(50, ignoreErrno(errno) ? 3 : 1) ("sslWriteClient: FD %d: write failure: %s.\n", fd, xstrerror()); @@ -343,7 +343,7 @@ } if (cbdataValid(sslState)) sslSetSelect(sslState); - cbdataUnlock(sslState); + cbdataInternalUnlock(sslState); /* ??? */ } static void Index: squid/src/store_client.c diff -u squid/src/store_client.c:1.8 squid/src/store_client.c:1.8.10.4 --- squid/src/store_client.c:1.8 Fri Apr 13 17:31:02 2001 +++ squid/src/store_client.c Wed Oct 10 14:25:11 2001 @@ -134,8 +134,7 @@ e->refcount++; mem->nclients++; sc = cbdataAlloc(store_client); - cbdataLock(data); /* locked while we point to it */ - sc->callback_data = data; + sc->callback_data = cbdataReference(data); sc->seen_offset = 0; sc->copy_offset = 0; sc->flags.disk_io_pending = 0; @@ -246,7 +245,7 @@ eventAdd("storeClientCopyEvent", storeClientCopyEvent, sc, 0.0, 0); return; } - cbdataLock(sc); /* ick, prevent sc from getting freed */ + cbdataInternalLock(sc); /* ick, prevent sc from getting freed */ sc->flags.store_copying = 1; debug(20, 3) ("storeClientCopy2: %s\n", storeKeyText(e->hash.key)); assert(sc->callback != NULL); @@ -259,7 +258,7 @@ */ storeClientCopy3(e, sc); sc->flags.store_copying = 0; - cbdataUnlock(sc); /* ick, allow sc to be freed */ + cbdataInternalUnlock(sc); /* ick, allow sc to be freed */ } static void @@ -525,8 +524,7 @@ storeSwapOut(e); if (sc->swapin_sio) { storeClose(sc->swapin_sio); - cbdataUnlock(sc->swapin_sio); - sc->swapin_sio = NULL; + cbdataReferenceDone(sc->swapin_sio); statCounter.swap.ins++; } if (NULL != sc->callback) { @@ -538,8 +536,7 @@ #if DELAY_POOLS delayUnregisterDelayIdPtr(&sc->delay_id); #endif - cbdataUnlock(sc->callback_data); /* we're done with it now */ - /*assert(!sc->flags.disk_io_pending); */ + cbdataReferenceDone(sc->callback_data); cbdataFree(sc); assert(e->lock_count > 0); if (mem->nclients == 0) Index: squid/src/store_swapin.c diff -u squid/src/store_swapin.c:1.5 squid/src/store_swapin.c:1.5.40.3 --- squid/src/store_swapin.c:1.5 Fri Jan 12 00:20:33 2001 +++ squid/src/store_swapin.c Wed Oct 10 14:17:31 2001 @@ -61,9 +61,8 @@ assert(e->mem_obj != NULL); debug(20, 3) ("storeSwapInStart: Opening fileno %08X\n", e->swap_filen); - sc->swapin_sio = storeOpen(e, storeSwapInFileNotify, storeSwapInFileClosed, - sc); - cbdataLock(sc->swapin_sio); + sc->swapin_sio = cbdataReference(storeOpen(e, storeSwapInFileNotify, storeSwapInFileClosed, + sc)); } static void @@ -73,8 +72,7 @@ STCB *callback; debug(20, 3) ("storeSwapInFileClosed: sio=%p, errflag=%d\n", sio, errflag); - cbdataUnlock(sio); - sc->swapin_sio = NULL; + cbdataReferenceDone(sc->swapin_sio); if ((callback = sc->callback)) { assert(errflag <= 0); sc->callback = NULL; Index: squid/src/store_swapout.c diff -u squid/src/store_swapout.c:1.8 squid/src/store_swapout.c:1.7.28.4 --- squid/src/store_swapout.c:1.8 Tue Jun 26 23:49:54 2001 +++ squid/src/store_swapout.c Wed Oct 10 14:17:31 2001 @@ -63,7 +63,7 @@ /* Create the swap file */ c = cbdataAlloc(generic_cbdata); c->data = e; - mem->swapout.sio = storeCreate(e, storeSwapOutFileNotify, storeSwapOutFileClosed, c); + mem->swapout.sio = cbdataReference(storeCreate(e, storeSwapOutFileNotify, storeSwapOutFileClosed, c)); if (NULL == mem->swapout.sio) { e->swap_status = SWAPOUT_NONE; cbdataFree(c); @@ -77,7 +77,6 @@ e->swap_filen = mem->swapout.sio->swap_filen; e->swap_dirn = mem->swapout.sio->swap_dirn; /* write out the swap metadata */ - cbdataLock(mem->swapout.sio); storeWrite(mem->swapout.sio, buf, mem->swap_hdr_sz, 0, xfree); } @@ -316,8 +315,7 @@ statCounter.swap.outs++; } debug(20, 3) ("storeSwapOutFileClosed: %s:%d\n", __FILE__, __LINE__); - mem->swapout.sio = NULL; - cbdataUnlock(sio); + cbdataReferenceDone(mem->swapout.sio); storeUnlockObject(e); } Index: squid/src/auth/basic/auth_basic.c diff -u squid/src/auth/basic/auth_basic.c:1.14 squid/src/auth/basic/auth_basic.c:1.11.28.5 --- squid/src/auth/basic/auth_basic.c:1.14 Mon Sep 3 14:15:37 2001 +++ squid/src/auth/basic/auth_basic.c Wed Oct 10 14:17:31 2001 @@ -261,7 +261,6 @@ auth_user_t *auth_user; basic_data *basic_auth; auth_basic_queue_node *tmpnode; - int valid; char *t = NULL; debug(29, 9) ("authenticateBasicHandleReply: {%s}\n", reply ? reply : ""); if (reply) { @@ -279,16 +278,14 @@ else basic_auth->flags.credentials_ok = 3; basic_auth->credentials_checkedtime = squid_curtime; - valid = cbdataValid(r->data); - if (valid) + if (cbdataValid(r->data)) r->handler(r->data, NULL); - cbdataUnlock(r->data); + cbdataReferenceDone(r->data); while (basic_auth->auth_queue) { tmpnode = basic_auth->auth_queue->next; - valid = cbdataValid(basic_auth->auth_queue->data); - if (valid) + if (cbdataValid(basic_auth->auth_queue->data)) basic_auth->auth_queue->handler(basic_auth->auth_queue->data, NULL); - cbdataUnlock(basic_auth->auth_queue->data); + cbdataReferenceDone(basic_auth->auth_queue->data); xfree(basic_auth->auth_queue); basic_auth->auth_queue = tmpnode; } @@ -584,14 +581,12 @@ basic_auth->auth_queue = node; node->auth_user_request = auth_user_request; node->handler = handler; - node->data = data; - cbdataLock(data); + node->data = cbdataReference(data); return; } else { r = cbdataAlloc(authenticateStateData); r->handler = handler; - cbdataLock(data); - r->data = data; + r->data = cbdataReference(data); r->auth_user_request = auth_user_request; /* mark the user as haveing verification in progress */ basic_auth->flags.credentials_ok = 2; Index: squid/src/auth/digest/auth_digest.c diff -u squid/src/auth/digest/auth_digest.c:1.8 squid/src/auth/digest/auth_digest.c:1.5.32.5 --- squid/src/auth/digest/auth_digest.c:1.8 Tue Sep 18 23:43:34 2001 +++ squid/src/auth/digest/auth_digest.c Wed Oct 10 14:17:31 2001 @@ -827,7 +827,6 @@ auth_user_request_t *auth_user_request; digest_request_h *digest_request; digest_user_h *digest_user; - int valid; char *t = NULL; debug(29, 9) ("authenticateDigestHandleReply: {%s}\n", reply ? reply : ""); if (reply) { @@ -847,10 +846,9 @@ CvtBin(reply, digest_user->HA1); digest_user->HA1created = 1; } - valid = cbdataValid(r->data); - if (valid) + if (cbdataValid(r->data)) r->handler(r->data, NULL); - cbdataUnlock(r->data); + cbdataReferenceDone(r->data); authenticateStateFree(r); } @@ -1333,8 +1331,7 @@ } r = cbdataAlloc(authenticateStateData); r->handler = handler; - cbdataLock(data); - r->data = data; + r->data = cbdataReference(data); r->auth_user_request = auth_user_request; snprintf(buf, 8192, "\"%s\":\"%s\"\n", digest_user->username, digest_request->realm); helperSubmit(digestauthenticators, buf, authenticateDigestHandleReply, r); Index: squid/src/auth/ntlm/auth_ntlm.c diff -u squid/src/auth/ntlm/auth_ntlm.c:1.13 squid/src/auth/ntlm/auth_ntlm.c:1.9.30.5 --- squid/src/auth/ntlm/auth_ntlm.c:1.13 Mon Sep 3 14:15:38 2001 +++ squid/src/auth/ntlm/auth_ntlm.c Wed Oct 10 14:17:31 2001 @@ -413,7 +413,7 @@ /* call authenticateNTLMStart to retry this request */ debug(29, 9) ("authenticateNTLMHandleplaceholder: calling authenticateNTLMStart\n"); authenticateNTLMStart(r->auth_user_request, r->handler, r->data); - cbdataUnlock(r->data); + cbdataReferenceDone(r->data); authenticateStateFree(r); return result; } @@ -434,7 +434,7 @@ valid = cbdataValid(r->data); if (!valid) { debug(29, 1) ("AuthenticateNTLMHandleReply: invalid callback data. Releasing helper '%d'.\n", lastserver); - cbdataUnlock(r->data); + cbdataReferenceDone(r->data); authenticateStateFree(r); debug(29, 9) ("NTLM HandleReply, telling stateful helper : %d\n", S_HELPER_RELEASE); return S_HELPER_RELEASE; @@ -572,7 +572,7 @@ * a different one. */ authenticateNTLMStart(auth_user_request, r->handler, r->data); /* don't call the callback */ - cbdataUnlock(r->data); + cbdataReferenceDone(r->data); authenticateStateFree(r); debug(29, 9) ("NTLM HandleReply, telling stateful helper : %d\n", result); return result; @@ -605,7 +605,7 @@ ntlm_request->authserver = NULL; } r->handler(r->data, NULL); - cbdataUnlock(r->data); + cbdataReferenceDone(r->data); authenticateStateFree(r); debug(29, 9) ("NTLM HandleReply, telling stateful helper : %d\n", result); return result; @@ -733,8 +733,7 @@ /* No server, or server with invalid challenge */ r = cbdataAlloc(authenticateStateData); r->handler = handler; - cbdataLock(data); - r->data = data; + r->data = cbdataReference(data); r->auth_user_request = auth_user_request; if (server == NULL) { helperStatefulSubmit(ntlmauthenticators, NULL, authenticateNTLMHandleplaceholder, r, NULL); @@ -761,8 +760,7 @@ case AUTHENTICATE_STATE_RESPONSE: r = cbdataAlloc(authenticateStateData); r->handler = handler; - cbdataLock(data); - r->data = data; + r->data = cbdataReference(data); r->auth_user_request = auth_user_request; snprintf(buf, 8192, "KK %s\n", sent_string); /* getting rid of deferred request status */ Index: squid/src/fs/aufs/async_io.c diff -u squid/src/fs/aufs/async_io.c:1.6 squid/src/fs/aufs/async_io.c:1.5.40.4 --- squid/src/fs/aufs/async_io.c:1.6 Wed Aug 22 14:15:46 2001 +++ squid/src/fs/aufs/async_io.c Wed Oct 10 14:17:31 2001 @@ -116,9 +116,8 @@ ctrlp = memPoolAlloc(squidaio_ctrl_pool); ctrlp->fd = -2; ctrlp->done_handler = callback; - ctrlp->done_handler_data = callback_data; + ctrlp->done_handler_data = cbdataReference(callback_data); ctrlp->operation = _AIO_OPEN; - cbdataLock(callback_data); ctrlp->result.data = ctrlp; squidaio_open(path, oflag, mode, &ctrlp->result); dlinkAdd(ctrlp, &ctrlp->node, &used_list); @@ -173,7 +172,7 @@ debug(0, 0) ("this be aioCancel\n"); if (cbdataValid(their_data)) done_handler(fd, their_data, -2, -2); - cbdataUnlock(their_data); + cbdataReferenceDone(their_data); } next = m->next; dlinkDelete(m, &used_list); @@ -193,7 +192,7 @@ ctrlp = memPoolAlloc(squidaio_ctrl_pool); ctrlp->fd = fd; ctrlp->done_handler = callback; - ctrlp->done_handler_data = callback_data; + ctrlp->done_handler_data = cbdataReference(callback_data); ctrlp->operation = _AIO_WRITE; ctrlp->bufp = bufp; ctrlp->free_func = free_func; @@ -203,7 +202,6 @@ seekmode = SEEK_END; offset = 0; } - cbdataLock(callback_data); ctrlp->result.data = ctrlp; squidaio_write(fd, bufp, len, offset, seekmode, &ctrlp->result); dlinkAdd(ctrlp, &ctrlp->node, &used_list); @@ -221,7 +219,7 @@ ctrlp = memPoolAlloc(squidaio_ctrl_pool); ctrlp->fd = fd; ctrlp->done_handler = callback; - ctrlp->done_handler_data = callback_data; + ctrlp->done_handler_data = cbdataReference(callback_data); ctrlp->operation = _AIO_READ; if (offset >= 0) seekmode = SEEK_SET; @@ -229,7 +227,6 @@ seekmode = SEEK_CUR; offset = 0; } - cbdataLock(callback_data); ctrlp->result.data = ctrlp; squidaio_read(fd, bufp, len, offset, seekmode, &ctrlp->result); dlinkAdd(ctrlp, &ctrlp->node, &used_list); @@ -246,9 +243,8 @@ ctrlp = memPoolAlloc(squidaio_ctrl_pool); ctrlp->fd = -2; ctrlp->done_handler = callback; - ctrlp->done_handler_data = callback_data; + ctrlp->done_handler_data = cbdataReference(callback_data); ctrlp->operation = _AIO_STAT; - cbdataLock(callback_data); ctrlp->result.data = ctrlp; squidaio_stat(path, sb, &ctrlp->result); dlinkAdd(ctrlp, &ctrlp->node, &used_list); @@ -264,9 +260,8 @@ ctrlp = memPoolAlloc(squidaio_ctrl_pool); ctrlp->fd = -2; ctrlp->done_handler = callback; - ctrlp->done_handler_data = callback_data; + ctrlp->done_handler_data = cbdataReference(callback_data); ctrlp->operation = _AIO_UNLINK; - cbdataLock(callback_data); ctrlp->result.data = ctrlp; squidaio_unlink(path, &ctrlp->result); dlinkAdd(ctrlp, &ctrlp->node, &used_list); @@ -281,9 +276,8 @@ ctrlp = memPoolAlloc(squidaio_ctrl_pool); ctrlp->fd = -2; ctrlp->done_handler = callback; - ctrlp->done_handler_data = callback_data; + ctrlp->done_handler_data = cbdataReference(callback_data); ctrlp->operation = _AIO_TRUNCATE; - cbdataLock(callback_data); ctrlp->result.data = ctrlp; squidaio_truncate(path, length, &ctrlp->result); dlinkAdd(ctrlp, &ctrlp->node, &used_list); @@ -317,7 +311,7 @@ done_handler(ctrlp->fd, their_data, ctrlp->result.aio_return, ctrlp->result.aio_errno); } - cbdataUnlock(their_data); + cbdataReferenceDone(their_data); } /* free data if requested to aioWrite() */ if (ctrlp->free_func) Index: squid/src/fs/aufs/store_io_aufs.c diff -u squid/src/fs/aufs/store_io_aufs.c:1.10 squid/src/fs/aufs/store_io_aufs.c:1.8.28.4 --- squid/src/fs/aufs/store_io_aufs.c:1.10 Fri Sep 7 16:55:50 2001 +++ squid/src/fs/aufs/store_io_aufs.c Wed Oct 10 14:17:31 2001 @@ -62,9 +62,8 @@ sio->swap_dirn = SD->index; sio->mode = O_RDONLY; sio->callback = callback; - sio->callback_data = callback_data; + sio->callback_data = cbdataReference(callback_data); sio->e = e; - cbdataLock(callback_data); Opening_FD++; #if ASYNC_OPEN aioOpen(path, O_RDONLY | O_BINARY, 0644, storeAufsOpenDone, sio); @@ -117,9 +116,8 @@ sio->swap_dirn = dirn; sio->mode = O_WRONLY | O_BINARY; sio->callback = callback; - sio->callback_data = callback_data; + sio->callback_data = cbdataReference(callback_data); sio->e = (StoreEntry *) e; - cbdataLock(callback_data); Opening_FD++; #if ASYNC_CREATE aioOpen(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644, storeAufsOpenDone, sio); @@ -174,9 +172,8 @@ return; } sio->read.callback = callback; - sio->read.callback_data = callback_data; + sio->read.callback_data = cbdataReference(callback_data); aiostate->read_buf = buf; - cbdataLock(callback_data); debug(78, 3) ("storeAufsRead: dirno %d, fileno %08X, FD %d\n", sio->swap_dirn, sio->swap_filen, aiostate->fd); sio->offset = offset; @@ -337,7 +334,7 @@ sio->read.callback_data = NULL; if (cbdataValid(their_data)) callback(their_data, aiostate->read_buf, rlen); - cbdataUnlock(their_data); + cbdataReferenceDone(their_data); aiostate->flags.inreaddone = 0; if (aiostate->flags.close_request) storeAufsIOCallback(sio, errflag); @@ -406,7 +403,7 @@ if (NULL == their_data || cbdataValid(their_data)) callback(their_data, errflag, sio); debug(78, 3) ("%s:%d\n", __FILE__, __LINE__); - cbdataUnlock(their_data); + cbdataReferenceDone(their_data); aiostate->fd = -1; cbdataFree(sio); if (fd < 0) Index: squid/src/fs/coss/async_io.c diff -u squid/src/fs/coss/async_io.c:1.3 squid/src/fs/coss/async_io.c:1.3.20.2 --- squid/src/fs/coss/async_io.c:1.3 Fri Aug 24 08:43:58 2001 +++ squid/src/fs/coss/async_io.c Wed Oct 10 14:17:31 2001 @@ -75,7 +75,7 @@ qe = &q->aq_queue[slot]; qe->aq_e_state = AQ_ENTRY_USED; qe->aq_e_callback.read = callback; - qe->aq_e_callback_data = data; + qe->aq_e_callback_data = cbdataReference(data); qe->aq_e_type = AQ_ENTRY_READ; qe->aq_e_free = NULL; qe->aq_e_buf = buf; @@ -89,9 +89,6 @@ /* Account */ q->aq_numpending++; - /* Lock */ - cbdataLock(data); - /* Initiate aio */ if (aio_read(&qe->aq_e_aiocb) < 0) { debug(1, 1) ("Aiee! aio_read() returned error (%d)!\n", errno); @@ -122,7 +119,7 @@ qe = &q->aq_queue[slot]; qe->aq_e_state = AQ_ENTRY_USED; qe->aq_e_callback.write = callback; - qe->aq_e_callback_data = data; + qe->aq_e_callback_data = cbdataReference(data); qe->aq_e_type = AQ_ENTRY_WRITE; qe->aq_e_free = freefunc; qe->aq_e_buf = buf; @@ -136,9 +133,6 @@ /* Account */ q->aq_numpending++; - /* Lock */ - cbdataLock(data); - /* Initiate aio */ if (aio_write(&qe->aq_e_aiocb) < 0) { debug(1, 1) ("Aiee! aio_read() returned error (%d)!\n", errno); @@ -206,7 +200,7 @@ if (type == AQ_ENTRY_WRITE) wc(fd, reterr, retval, callback_data); } - cbdataUnlock(callback_data); + cbdataReferenceDone(callback_data); if (type == AQ_ENTRY_WRITE && freefunc) freefunc(buf); } Index: squid/src/fs/coss/store_io_coss.c diff -u squid/src/fs/coss/store_io_coss.c:1.8 squid/src/fs/coss/store_io_coss.c:1.7.2.4 --- squid/src/fs/coss/store_io_coss.c:1.8 Sun Aug 12 08:20:29 2001 +++ squid/src/fs/coss/store_io_coss.c Wed Oct 10 14:17:32 2001 @@ -163,8 +163,7 @@ sio->callback = callback; sio->file_callback = file_callback; - sio->callback_data = callback_data; - cbdataLock(callback_data); + sio->callback_data = cbdataReference(callback_data); sio->e = (StoreEntry *) e; cstate->flags.writing = 0; @@ -202,8 +201,7 @@ sio->mode = O_RDONLY; sio->callback = callback; sio->file_callback = file_callback; - sio->callback_data = callback_data; - cbdataLock(callback_data); + sio->callback_data = cbdataReference(callback_data); sio->st_size = e->swap_file_sz; sio->e = e; @@ -281,7 +279,7 @@ assert(sio->read.callback == NULL); assert(sio->read.callback_data == NULL); sio->read.callback = callback; - sio->read.callback_data = callback_data; + sio->read.callback_data = cbdataReference(callback_data); debug(81, 3) ("storeCossRead: offset %d\n", offset); sio->offset = offset; cstate->flags.reading = 1; @@ -370,6 +368,7 @@ sio->read.callback_data = NULL; if (cbdataValid(their_data)) callback(their_data, cstate->requestbuf, rlen); + cbdataReferenceDone(their_data); } static void @@ -380,7 +379,7 @@ xfree(cstate->readbuffer); if (cbdataValid(sio->callback_data)) sio->callback(sio->callback_data, errflag, sio); - cbdataUnlock(sio->callback_data); + cbdataReferenceDone(sio->callback_data); sio->callback_data = NULL; cbdataFree(sio); } Index: squid/src/fs/diskd/store_io_diskd.c diff -u squid/src/fs/diskd/store_io_diskd.c:1.8 squid/src/fs/diskd/store_io_diskd.c:1.7.28.5 --- squid/src/fs/diskd/store_io_diskd.c:1.8 Thu May 31 01:39:42 2001 +++ squid/src/fs/diskd/store_io_diskd.c Wed Oct 10 14:17:32 2001 @@ -78,9 +78,8 @@ sio->swap_dirn = SD->index; sio->mode = O_RDONLY; sio->callback = callback; - sio->callback_data = callback_data; + sio->callback_data = cbdataReference(callback_data); sio->e = e; - cbdataLock(callback_data); diskdstate->flags.writing = 0; diskdstate->flags.reading = 0; @@ -99,7 +98,7 @@ if (x < 0) { debug(50, 1) ("storeDiskdSend OPEN: %s\n", xstrerror()); storeDiskdShmPut(SD, shm_offset); - cbdataUnlock(sio->callback_data); + cbdataReferenceDone(sio->callback_data); cbdataFree(sio); return NULL; } @@ -137,9 +136,8 @@ sio->swap_dirn = SD->index; sio->mode = O_WRONLY | O_CREAT | O_TRUNC; sio->callback = callback; - sio->callback_data = callback_data; + sio->callback_data = cbdataReference(callback_data); sio->e = e; - cbdataLock(callback_data); diskdstate->flags.writing = 0; diskdstate->flags.reading = 0; @@ -158,7 +156,7 @@ if (x < 0) { debug(50, 1) ("storeDiskdSend OPEN: %s\n", xstrerror()); storeDiskdShmPut(SD, shm_offset); - cbdataUnlock(sio->callback_data); + cbdataReferenceDone(sio->callback_data); cbdataFree(sio); return NULL; } @@ -208,9 +206,8 @@ assert(sio->read.callback == NULL); assert(sio->read.callback_data == NULL); sio->read.callback = callback; - sio->read.callback_data = callback_data; + sio->read.callback_data = cbdataReference(callback_data); diskdstate->read_buf = buf; /* the one passed from above */ - cbdataLock(sio->read.callback_data); sio->offset = offset; diskdstate->flags.reading = 1; rbuf = storeDiskdShmGet(SD, &shm_offset); @@ -348,8 +345,6 @@ int valid; statCounter.syscalls.disk.reads++; diskdstate->flags.reading = 0; - valid = cbdataValid(sio->read.callback_data); - cbdataUnlock(sio->read.callback_data); debug(81, 3) ("storeDiskdReadDone: dirno %d, fileno %08x status %d\n", sio->swap_dirn, sio->swap_filen, M->status); if (M->status < 0) { @@ -362,7 +357,7 @@ len = M->status; sio->offset += len; assert(callback); - assert(their_data); + valid = cbdataValid(sio->read.callback_data); sio->read.callback = NULL; sio->read.callback_data = NULL; if (valid) { @@ -376,6 +371,7 @@ xmemcpy(their_buf, sbuf, len); /* yucky copy */ callback(their_data, their_buf, len); } + cbdataReferenceDone(their_data); } static void @@ -411,10 +407,28 @@ void storeDiskdHandle(diomsg * M) { - int valid = M->callback_data ? cbdataValid(M->callback_data) : 1; - if (M->callback_data) - cbdataUnlock(M->callback_data); - if (!valid) { + if (cbdataValid(M->callback_data)) { + switch (M->mtype) { + case _MQD_OPEN: + storeDiskdOpenDone(M); + break; + case _MQD_CLOSE: + storeDiskdCloseDone(M); + break; + case _MQD_READ: + storeDiskdReadDone(M); + break; + case _MQD_WRITE: + storeDiskdWriteDone(M); + break; + case _MQD_UNLINK: + storeDiskdUnlinkDone(M); + break; + default: + assert(0); + break; + } + } else { debug(81, 3) ("storeDiskdHandle: Invalid callback_data %p\n", M->callback_data); /* @@ -423,41 +437,26 @@ * callback_data gets unlocked! */ if (_MQD_READ == M->mtype) { + /* XXX This cannot be the correct approach. This + * is most likely the wrong place for this. It should + * be done before the sio becomes invalid, not here. + */ storeIOState *sio = M->callback_data; - cbdataUnlock(sio->read.callback_data); + cbdataReferenceDone(sio->read.callback_data); } - return; - } - switch (M->mtype) { - case _MQD_OPEN: - storeDiskdOpenDone(M); - break; - case _MQD_CLOSE: - storeDiskdCloseDone(M); - break; - case _MQD_READ: - storeDiskdReadDone(M); - break; - case _MQD_WRITE: - storeDiskdWriteDone(M); - break; - case _MQD_UNLINK: - storeDiskdUnlinkDone(M); - break; - default: - assert(0); - break; } + cbdataReferenceDone(M->callback_data); } static void storeDiskdIOCallback(storeIOState * sio, int errflag) { - int valid = cbdataValid(sio->callback_data); + void *callback_data = sio->callback_data; debug(81, 3) ("storeUfsIOCallback: errflag=%d\n", errflag); - cbdataUnlock(sio->callback_data); - if (valid) - sio->callback(sio->callback_data, errflag, sio); + sio->callback_data = NULL; /* saved in callback_data */ + if (cbdataValid(callback_data)) + sio->callback(callback_data, errflag, sio); + cbdataReferenceDone(callback_data); cbdataFree(sio); } @@ -471,15 +470,13 @@ static int seq_no = 0; diskdinfo_t *diskdinfo = sd->fsdata; M.mtype = mtype; - M.callback_data = sio; + M.callback_data = cbdataReference(sio); M.size = size; M.offset = offset; M.status = -1; M.shm_offset = (int) shm_offset; M.id = id; M.seq_no = ++seq_no; - if (M.callback_data) - cbdataLock(M.callback_data); if (M.seq_no < last_seq_no) debug(81, 1) ("WARNING: sequencing out of order\n"); x = msgsnd(diskdinfo->smsgid, &M, msg_snd_rcv_sz, IPC_NOWAIT); @@ -489,8 +486,7 @@ diskdinfo->away++; } else { debug(50, 1) ("storeDiskdSend: msgsnd: %s\n", xstrerror()); - if (M.callback_data) - cbdataUnlock(M.callback_data); + cbdataReferenceDone(M.callback_data); assert(++send_errors < 100); } /* Index: squid/src/fs/ufs/store_io_ufs.c diff -u squid/src/fs/ufs/store_io_ufs.c:1.6 squid/src/fs/ufs/store_io_ufs.c:1.6.28.3 --- squid/src/fs/ufs/store_io_ufs.c:1.6 Sat Mar 3 02:44:34 2001 +++ squid/src/fs/ufs/store_io_ufs.c Wed Oct 10 14:17:32 2001 @@ -70,8 +70,7 @@ sio->swap_dirn = SD->index; sio->mode = O_RDONLY; sio->callback = callback; - sio->callback_data = callback_data; - cbdataLock(callback_data); + sio->callback_data = cbdataReference(callback_data); sio->e = e; ((ufsstate_t *) (sio->fsstate))->fd = fd; ((ufsstate_t *) (sio->fsstate))->flags.writing = 0; @@ -118,8 +117,7 @@ sio->swap_dirn = dirn; sio->mode = mode; sio->callback = callback; - sio->callback_data = callback_data; - cbdataLock(callback_data); + sio->callback_data = cbdataReference(callback_data); sio->e = (StoreEntry *) e; ((ufsstate_t *) (sio->fsstate))->fd = fd; ((ufsstate_t *) (sio->fsstate))->flags.writing = 0; @@ -154,8 +152,7 @@ assert(sio->read.callback == NULL); assert(sio->read.callback_data == NULL); sio->read.callback = callback; - sio->read.callback_data = callback_data; - cbdataLock(callback_data); + sio->read.callback_data = cbdataReference(callback_data); debug(79, 3) ("storeUfsRead: dirno %d, fileno %08X, FD %d\n", sio->swap_dirn, sio->swap_filen, ufsstate->fd); sio->offset = offset; @@ -219,7 +216,7 @@ sio->read.callback_data = NULL; if (cbdataValid(their_data)) callback(their_data, buf, (size_t) rlen); - cbdataUnlock(their_data); + cbdataReferenceDone(their_data); } static void @@ -251,8 +248,7 @@ } if (cbdataValid(sio->callback_data)) sio->callback(sio->callback_data, errflag, sio); - cbdataUnlock(sio->callback_data); - sio->callback_data = NULL; + cbdataReferenceDone(sio->callback_data); sio->callback = NULL; cbdataFree(sio); } squid-cbdata-20011010-HEAD-20011010.new squid-cbdata-20011010-HEAD-20011010 differ: char 83, line 2