src/dbs/atrshmlogreaderd_db.c
int add_buffers(int i_count)
{
  mb_t * m = malloc(i_count * sizeof(mb_t));

  if (m)
    {
      char* buffers = malloc(i_count * MB_INFOSIZE);
      
      if (buffers)
	{
	  mb_t* mb = m;
	   
	  for (int i = 0; i  < i_count; i++, mb++, buffers += MB_INFOSIZE)
	    {
	      mb->next = &mb[1]; 
	      mb->next_append = &mb[1];
	      mb->next_full = 0;
	      mb->lcount = 0;
	      mb->ob = buffers;
	    }

	  /* we correct the last buffer */
	  mb--;
	  mb->next = (mb_t*)atomic_load(&tps);
	  mb->next_append = (mb_t*)atomic_load(&tpa);

	  // push on stack ...
	  while(!atomic_compare_exchange_weak_explicit(&tps,
							(intptr_t*)&mb->next,
							(intptr_t)m,
						       memory_order_release,
						       memory_order_relaxed))
	    ;

	   // push on stack ...
	  while(!atomic_compare_exchange_weak_explicit(&tpa,
						       (intptr_t*)&mb->next_append,
						       (intptr_t)m,
						       memory_order_release,
						       memory_order_relaxed))
	    ;
	   
	  return 0;
	}
    }
  
  return -1;
}
/**
 * we need additional buffers and we deliver them
 */
we need additional buffers and we deliver them
we need additional buffers and we deliver them
int add_buffers(int i_count)
{
  mb_t * m = malloc(i_count * sizeof(mb_t));
  if (m)
    {
      char* buffers = malloc(i_count * MB_INFOSIZE);
      if (buffers)
	{
	  mb_t* mb = m;
	  for (int i = 0; i  < i_count; i++, mb++, buffers += MB_INFOSIZE)
	    {
	      mb->next = &mb[1]; 
	      mb->next_append = &mb[1];
	      mb->next_full = 0;
	      mb->lcount = 0;
	      mb->ob = buffers;
	    }
	  mb--;
	  mb->next = (mb_t*)atomic_load(&tps);
	  mb->next_append = (mb_t*)atomic_load(&tpa);
	  while(!atomic_compare_exchange_weak_explicit(&tps,
							(intptr_t*)&mb->next,
							(intptr_t)m,
						       memory_order_release,
						       memory_order_relaxed))
	    ;
	  while(!atomic_compare_exchange_weak_explicit(&tpa,
						       (intptr_t*)&mb->next_append,
						       (intptr_t)m,
						       memory_order_release,
						       memory_order_relaxed))
	    ;
	  return 0;
	}
    }
  return -1;
}
int add_buffers ( int i_count ) { mb_t * m = malloc ( i_count * sizeof ( mb_t ) ) ; if ( m ) { char * buffers = malloc ( i_count * MB_INFOSIZE ) ; if ( buffers ) { mb_t * mb = m ; for ( int i = 0 ; i < i_count ; i ++ , mb ++ , buffers += MB_INFOSIZE ) { mb -> next = & mb [ 1 ] ; mb -> next_append = & mb [ 1 ] ; mb -> next_full = 0 ; mb -> lcount = 0 ; mb -> ob = buffers ; } mb -- ; mb -> next = ( mb_t * ) atomic_load ( & tps ) ; mb -> next_append = ( mb_t * ) atomic_load ( & tpa ) ; while ( ! atomic_compare_exchange_weak_explicit ( & tps , ( intptr_t * ) & mb -> next , ( intptr_t ) m , memory_order_release , memory_order_relaxed ) ) ; while ( ! atomic_compare_exchange_weak_explicit ( & tpa , ( intptr_t * ) & mb -> next_append , ( intptr_t ) m , memory_order_release , memory_order_relaxed ) ) ; return 0 ; } } return -1 ; }
we need additional buffers and we deliver them
we need additional buffers and we deliver them
/* we correct the last buffer */ // push on stack ... // push on stack ...