Welcome! Log In Create A New Profile

Advanced

condition variable in conn_queue seams not need

Posted by ilnarb 
ilnarb
condition variable in conn_queue seams not need
August 13, 2010 11:50AM
I found in thread.c:109
pthread_cond_signal(&cq->cond);
without any waiting for that condition variable.
I don't know, will it helpful if you eliminate using it.
Peter Portante
Re: condition variable in conn_queue seams not need
August 13, 2010 01:30PM
Seems we could shrink the structure by removing the condition variable
itself, and eliminate the signal call since it does appear to be unused.
cq_pop() does not have a mode where it waits for a cq_push().

And while we are at it, you can also optimize cq_pop() on the no connection
case to avoid taking the lock (you only have to lock if something is there
and you are going to modify the memory:

static CQ_ITEM *cq_pop(CQ *cq) {
CQ_ITEM *item;

if (NULL == cq->head)
return NULL;
pthread_mutex_lock(&cq->lock);
item = cq->head;
if (NULL != item) {
cq->head = item->next;
if (NULL == cq->head)
cq->tail = NULL;
}
pthread_mutex_unlock(&cq->lock);

return item;
}

-peter

On 8/13/10 4:08 AM, "ilnarb" <[email protected]> wrote:

> I found in thread.c:109
> pthread_cond_signal(&cq->cond);
> without any waiting for that condition variable.
> I don't know, will it helpful if you eliminate using it.
Sorry, only registered users may post in this forum.

Click here to login