Skip to content

Commit

Permalink
Replace MEM_DREAD_CTRL pool with MEMPROXY class pool (#1924)
Browse files Browse the repository at this point in the history
Replacing memory allocate and destruct with C++ new/delete
and in-class initialization.
  • Loading branch information
yadij authored and squid-anubis committed Nov 21, 2024
1 parent 010f2d2 commit c92e1ad
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
14 changes: 3 additions & 11 deletions src/fs_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ diskHandleRead(int fd, void *data)
*/

if (fd < 0) {
memFree(ctrl_dat, MEM_DREAD_CTRL);
delete ctrl_dat;
return;
}

Expand Down Expand Up @@ -414,7 +414,7 @@ diskHandleRead(int fd, void *data)

cbdataReferenceDone(ctrl_dat->client_data);

memFree(ctrl_dat, MEM_DREAD_CTRL);
delete ctrl_dat;
}

/* start read operation */
Expand All @@ -424,16 +424,8 @@ diskHandleRead(int fd, void *data)
void
file_read(int fd, char *buf, int req_len, off_t offset, DRCB * handler, void *client_data)
{
dread_ctrl *ctrl_dat;
assert(fd >= 0);
ctrl_dat = (dread_ctrl *)memAllocate(MEM_DREAD_CTRL);
ctrl_dat->fd = fd;
ctrl_dat->offset = offset;
ctrl_dat->req_len = req_len;
ctrl_dat->buf = buf;
ctrl_dat->end_of_file = 0;
ctrl_dat->handler = handler;
ctrl_dat->client_data = cbdataReference(client_data);
const auto ctrl_dat = new dread_ctrl(fd, offset, buf, req_len, handler, cbdataReference(client_data));
diskHandleRead(fd, ctrl_dat);
}

Expand Down
27 changes: 19 additions & 8 deletions src/fs_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,28 @@

class MemBuf;

// POD
class dread_ctrl
{
MEMPROXY_CLASS(dread_ctrl);
public:
int fd;
off_t offset;
int req_len;
char *buf;
int end_of_file;
DRCB *handler;
void *client_data;
dread_ctrl(int aFd, off_t aOffset, char *aBuf, int aLen, DRCB *aHandler, void *aData) :
fd(aFd),
offset(aOffset),
req_len(aLen),
buf(aBuf),
handler(aHandler),
client_data(aData)
{}
dread_ctrl(dread_ctrl &&) = delete; // no copying or moving of any kind
~dread_ctrl() = default;

int fd = -1;
off_t offset = 0;
int req_len = 0;
char *buf = nullptr;
int end_of_file = 0;
DRCB *handler = nullptr;
void *client_data = nullptr;
};

class dwrite_q
Expand Down
1 change: 0 additions & 1 deletion src/mem/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ typedef enum {
MEM_16K_BUF,
MEM_32K_BUF,
MEM_64K_BUF,
MEM_DREAD_CTRL,
MEM_MD5_DIGEST,
MEM_MAX
} mem_type;
Expand Down
1 change: 0 additions & 1 deletion src/mem/old_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ Mem::Init(void)
memDataInit(MEM_32K_BUF, "32K Buffer", 32768, 10, false);
memDataInit(MEM_64K_BUF, "64K Buffer", 65536, 10, false);
// TODO: Carefully stop zeroing these objects memory and drop the doZero parameter
memDataInit(MEM_DREAD_CTRL, "dread_ctrl", sizeof(dread_ctrl), 0, true);
memDataInit(MEM_MD5_DIGEST, "MD5 digest", SQUID_MD5_DIGEST_LENGTH, 0, true);
GetPool(MEM_MD5_DIGEST)->setChunkSize(512 * 1024);

Expand Down

0 comments on commit c92e1ad

Please sign in to comment.