From 0b6baeca64827c2dfaa86b43bbb9ab86c6421e7c Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Sun, 25 Nov 2012 23:08:13 +0100 Subject: [PATCH] Simplify CBUFF tail/consumer attachment. Consumer does receives only messages which are allocated later than tail is attached. CBUFF requires at least one consumer/tail reader before buffer is filled. The previous attempt to allow special handling of zero readers situation was nor used nor tested and was not correct. Code removed. Signed-off-by: Pavel Pisa --- ulut/ul_cbuff.h | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/ulut/ul_cbuff.h b/ulut/ul_cbuff.h index bc54c0c..29d662f 100644 --- a/ulut/ul_cbuff.h +++ b/ulut/ul_cbuff.h @@ -183,7 +183,12 @@ ul_cbuff_head_alloc(ul_cbuff_t *buff, ul_cbuff_put_info_t *put_info, unsigned in ((ul_cbuff_msg_head_t *)(buff->buff_start+state->head))->flags=0; + flags&=~(UL_CBUFF_MSG_READY|UL_CBUFF_MSG_READERS); + put_info->msg_head->flags|=flags; + if(buff->state->readers>0) + put_info->msg_head->flags+=buff->state->readers; + put_info->msg_head->length=length; return 0; @@ -192,8 +197,6 @@ ul_cbuff_head_alloc(ul_cbuff_t *buff, ul_cbuff_put_info_t *put_info, unsigned in ul_cbuff_inline int ul_cbuff_head_put(ul_cbuff_t *buff, ul_cbuff_put_info_t *put_info) { - if(buff->state->readers>0) - put_info->msg_head->flags+=buff->state->readers; ul_cbuff_mark_ready(put_info->msg_head); put_info->msg_head=NULL; return 0; @@ -261,18 +264,8 @@ ul_cbuff_tail_attach(ul_cbuff_t *buff, ul_cbuff_tail_info_t *tail_info, int mode msg_head=(ul_cbuff_msg_head_t *)(buff->buff_start+state->head); if(state->readers>=0) state->readers++; - if((state->readers<0)||(state->firsttail==state->head)){ - tail_info->msg_head=msg_head; - tail_info->data.ptr=NULL; - }else{ - /* There is already some message(s) write in progress */ - tail_info->msg_head=NULL; - tail_info->msg_head->flags++; - /* Some data fields are abused for ready condition checking */ - tail_info->data.ptr=(unsigned char*)msg_head; - tail_info->data.wrap_ptr=buff->buff_start+state->firsttail; - tail_info->data.wrap_len=state->cycles; - } + tail_info->msg_head=msg_head; + tail_info->data.ptr=NULL; return 0; } @@ -280,23 +273,7 @@ ul_cbuff_inline int ul_cbuff_tail_incontact(ul_cbuff_t *buff, ul_cbuff_tail_info_t *tail_info) { if(tail_info->msg_head==NULL){ - unsigned char *new_firsttail=buff->buff_start+buff->state->firsttail; - unsigned char *old_head=tail_info->data.ptr; - unsigned char *old_firsttail=tail_info->data.wrap_ptr; - unsigned int old_cycles=tail_info->data.wrap_len; - unsigned int new_cycles=buff->state->cycles; - - if(old_firsttailmsg_head=(ul_cbuff_msg_head_t *)old_head; - return 1; + return 0; } return 1; } -- 2.39.2