/*
- * $Id: mem_node.cc,v 1.6 2004/08/30 05:12:31 robertc Exp $
+ * $Id: mem_node.cc,v 1.7 2005/09/14 18:23:21 wessels Exp $
*
* DEBUG: section 19 Store Memory Primitives
* AUTHOR: Robert Collins
#include "squid.h"
#include "mem_node.h"
+static int makeMemNodeDataOffset();
+
unsigned long mem_node::store_mem_size;
+static int _mem_node_data_offset = makeMemNodeDataOffset();
+
+/*
+ * Calculate the offset between the start of a mem_node and
+ * its 'data' member
+ */
+static int
+makeMemNodeDataOffset()
+{
+ mem_node *p = 0L;
+ return int(&p->data);
+}
+
+/*
+ * This is the callback when storeIOWrite() is done. We need to
+ * clear the write_pending flag for the mem_node. First we have
+ * to calculate the start of the mem_node based on the character
+ * buffer that we wrote. ick.
+ */
+void
+memNodeWriteComplete(void* d)
+{
+ mem_node* n = (mem_node*)((char*)d - _mem_node_data_offset);
+ assert(n->write_pending);
+ n->write_pending = 0;
+}
mem_node::mem_node(off_t offset):nodeBuffer(0,offset,data)
{}
/*
- * $Id: mem_node.h,v 1.8 2005/04/01 21:11:28 serassio Exp $
+ * $Id: mem_node.h,v 1.9 2005/09/14 18:23:21 wessels Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
StoreIOBuffer nodeBuffer;
/* Private */
char data[SM_PAGE_SIZE];
- int uses;
+
+unsigned int write_pending:
+ 1;
};
MEMPROXY_CLASS_INLINE(mem_node)
return os;
}
+void memNodeWriteComplete(void *);
+
#endif /* SQUID_MEM_NODE_H */
/*
- * $Id: stmem.cc,v 1.88 2005/04/01 21:11:28 serassio Exp $
+ * $Id: stmem.cc,v 1.89 2005/09/14 18:23:21 wessels Exp $
*
* DEBUG: section 19 Store Memory Primitives
* AUTHOR: Harvest Derived
#include "MemObject.h"
#include "Generic.h"
+/*
+ * NodeGet() is called to get the data buffer to pass to storeIOWrite().
+ * By setting the write_pending flag here we are assuming that there
+ * will be no other users of NodeGet(). The storeIOWrite() callback
+ * is memNodeWriteComplete(), which, for whatever reason, lives in
+ * mem_node.cc.
+ */
char *
mem_hdr::NodeGet(mem_node * aNode)
{
- aNode->uses++;
+ assert(!aNode->write_pending);
+ aNode->write_pending = 1;
return aNode->data;
}
inmem_hi = 0;
}
-void
+bool
mem_hdr::unlink(mem_node *aNode)
{
- nodes.remove (aNode, NodeCompare);
-
- if (!aNode->uses)
- delete aNode;
- else
- aNode->uses--;
+ if (aNode->write_pending) {
+ debug(0,0)("cannot unlink mem_node %p while write_pending\n", aNode);
+ return false;
+ }
+ nodes.remove (aNode, NodeCompare);
+ delete aNode;
+ return true;
}
int
SplayNode<mem_node*> const * theStart = nodes.start();
- while (theStart && theStart != nodes.finish() &&
- theStart->data->end() <= (size_t) target_offset ) {
- unlink(theStart->data);
- theStart = nodes.start();
+ while ((theStart = nodes.start())) {
+ if (theStart == nodes.finish())
+ break;
+
+ if (theStart->data->end() > (size_t) target_offset )
+ break;
+
+ if (!unlink(theStart->data))
+ break;
}
assert (lowestOffset () <= target_offset);
/*
- * $Id: stmem.h,v 1.8 2005/04/01 21:11:28 serassio Exp $
+ * $Id: stmem.h,v 1.9 2005/09/14 18:23:21 wessels Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
private:
void debugDump() const;
- void unlink(mem_node *aNode);
+ bool unlink(mem_node *aNode);
void makeAppendSpace();
int appendToNode(mem_node *aNode, const char *data, int maxLength);
void appendNode (mem_node *aNode);
/*
- * $Id: store_swapout.cc,v 1.100 2005/04/01 21:11:28 serassio Exp $
+ * $Id: store_swapout.cc,v 1.101 2005/09/14 18:23:21 wessels Exp $
*
* DEBUG: section 20 Storage Manager Swapout Functions
* AUTHOR: Duane Wessels
mem->swapout.queue_offset += swap_buf_len;
- storeIOWrite(mem->swapout.sio, mem->data_hdr.NodeGet(mem->swapout.memnode), swap_buf_len, -1, NULL);
+ storeIOWrite(mem->swapout.sio, mem->data_hdr.NodeGet(mem->swapout.memnode), swap_buf_len, -1, memNodeWriteComplete);
/* the storeWrite() call might generate an error */
if (anEntry->swap_status != SWAPOUT_WRITING)