Reference count async queue transactions
so we can put them of task message queues
This commit is contained in:
53
asyncqueue.c
53
asyncqueue.c
@@ -89,27 +89,36 @@ static const char *state_name(AsyncState the_state)
|
||||
return "<unknown>";
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the transaction and buffers
|
||||
*/
|
||||
static void free_transaction(pAsyncTxn myTxn)
|
||||
{
|
||||
if (myTxn) {
|
||||
if (--myTxn->ref_counter > 0)
|
||||
return;
|
||||
/*
|
||||
* Allow kill_private to clean it all if it wants
|
||||
*/
|
||||
if (myTxn->kill_private)
|
||||
myTxn->kill_private(myTxn);
|
||||
if (myTxn->out_buf)
|
||||
free(myTxn->out_buf);
|
||||
if (myTxn->inp_buf)
|
||||
free(myTxn->inp_buf);
|
||||
if (myTxn->proto_private)
|
||||
free(myTxn->proto_private);
|
||||
free(myTxn);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the command and transaction structures and their contents
|
||||
*/
|
||||
static void free_command(pAQ_Cmd myCmd)
|
||||
{
|
||||
if (myCmd) {
|
||||
pAsyncTxn myTxn = myCmd->tran;
|
||||
if (myTxn) {
|
||||
/*
|
||||
* Allow kill_private to clean it all if it wants
|
||||
*/
|
||||
if (myTxn->kill_private)
|
||||
myTxn->kill_private(myTxn);
|
||||
if (myTxn->out_buf)
|
||||
free(myTxn->out_buf);
|
||||
if (myTxn->inp_buf)
|
||||
free(myTxn->inp_buf);
|
||||
if (myTxn->proto_private)
|
||||
free(myTxn->proto_private);
|
||||
free(myTxn);
|
||||
}
|
||||
free_transaction(myCmd->tran);
|
||||
free(myCmd);
|
||||
}
|
||||
}
|
||||
@@ -735,9 +744,23 @@ pAsyncTxn AsyncUnitPrepareTxn(pAsyncUnit unit,
|
||||
myTxn->unit = unit;
|
||||
myTxn->handleResponse = callback;
|
||||
myTxn->cntx = context;
|
||||
myTxn->ref_counter = 1;
|
||||
return myTxn;
|
||||
}
|
||||
|
||||
pAsyncTxn AsyncUnitHoldTxn(pAsyncTxn txn)
|
||||
{
|
||||
if (txn)
|
||||
txn->ref_counter++;
|
||||
return txn;
|
||||
}
|
||||
|
||||
void AsyncUnitFreeTxn(pAsyncTxn txn)
|
||||
{
|
||||
if (txn)
|
||||
free_transaction(txn);
|
||||
}
|
||||
|
||||
int AsyncUnitSendTxn(pAsyncUnit unit,
|
||||
const char *command, int cmd_len,
|
||||
AsyncTxnHandler callback, void *context, int rsp_len)
|
||||
|
||||
Reference in New Issue
Block a user