]> rtime.felk.cvut.cz Git - ulut.git/commitdiff
Simplify CBUFF tail/consumer attachment.
authorPavel Pisa <pisa@cmp.felk.cvut.cz>
Sun, 25 Nov 2012 22:08:13 +0000 (23:08 +0100)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Sun, 25 Nov 2012 22:11:25 +0000 (23:11 +0100)
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 <pisa@cmp.felk.cvut.cz>
ulut/ul_cbuff.h

index bc54c0c05cfc5e020cfee93dcb21bb5600781618..29d662f49032e57b0516e2d507312cee7afd6a0b 100644 (file)
@@ -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_firsttail<old_head){
-      if((new_firsttail<old_head)&&(new_cycles==old_cycles))
-        return 0;
-    }else{
-      if(new_cycles==old_cycles)
-        return 0;
-      if((new_firsttail<old_head)&&((new_cycles-old_cycles)==1))
-        return 0;
-    }
-    tail_info->msg_head=(ul_cbuff_msg_head_t *)old_head;
-    return 1;
+    return 0;
   }
   return 1;
 }