mksh/mksh.logging/src.1mai/atrshmlog_internal.c
int atrshmlog_init_one_buffer(atr_shm_log_area_t *i_shm,
                  int i_index_buffer)
{
  int result = -1;
  
  pthread_mutexattr_t pshared_mode;

  atr_shm_log_buffer_t* b = &(i_shm->logbuffers[i_index_buffer]);

  /* this is the only critical part : we have to initialize the mutex */

  /* we init first the attribute, shareable for processes */
  { 
    int init_attr_result = pthread_mutexattr_init(&pshared_mode);

    --result;
    
    if (init_attr_result != 0)
      return result;
  }
    
  /* ok. we have the attr. now we declaire its inter process shared */
  {
    int share_mode = PTHREAD_PROCESS_SHARED;
      
    int result_set_proc = pthread_mutexattr_setpshared(&pshared_mode, share_mode);

    --result;

    if (result_set_proc != 0)
      {
    pthread_mutexattr_destroy(&pshared_mode);
      
    return result;
      }
  }

  /* ok. we can now init the mutex itself */
  {
    pthread_mutex_t* m = &(b->lock_mutex);
    
    int result_mutex_init = pthread_mutex_init(m, &pshared_mode);

    --result;
      
    if (result_mutex_init != 0)
      {
    pthread_mutexattr_destroy(&pshared_mode);
      
    return result;
      }
  }
    
  /* ok, we have to clean up on our side */
  {
    int result_attr_destroy = pthread_mutexattr_destroy(&pshared_mode);

    --result;
      
    if (result_attr_destroy != 0)
      return result;
  }

  /* ok. we are through. we have to set the final infos and thats it */
  b->size = 0;
  
  b->safeguard = SAFEGUARDVALUE;

  for (int i = 0; i  <= ATRSHMLOGSLOTCOUNT; i++)
    b->slots[i] = 0;

  b->state = atr_shm_log_writeable;

  b->count_writes = 0;
  
  b->count_uses = 0;
  
  b->count_memcpy = 0;

  b->count_state_ok_first_check = 0;

  b->count_state_not_ok = 0;

  b->count_state_not_ok_second = 0;
 
  b->count_mutex_lock= 0 ;

  b->count_safeguard_problem= 0 ;

  b->count_state_check_ok_second_check= 0 ;

  b->count_buffer_filled= 0 ;

  b->count_slot_checks= 0 ;

  b->count_slots_full= 0 ;

  return 0;
}
/* helper: we initialize one buffer
   pthread version 
 */
we initialize one buffer
pthread version
we initialize one buffer pthread version
int atrshmlog_init_one_buffer(atr_shm_log_area_t *i_shm,
                  int i_index_buffer)
{
  int result = -1;
  pthread_mutexattr_t pshared_mode;
  atr_shm_log_buffer_t* b = &(i_shm->logbuffers[i_index_buffer]);
  { 
    int init_attr_result = pthread_mutexattr_init(&pshared_mode);
    --result;
    if (init_attr_result != 0)
      return result;
  }
  {
    int share_mode = PTHREAD_PROCESS_SHARED;
    int result_set_proc = pthread_mutexattr_setpshared(&pshared_mode, share_mode);
    --result;
    if (result_set_proc != 0)
      {
    pthread_mutexattr_destroy(&pshared_mode);
    return result;
      }
  }
  {
    pthread_mutex_t* m = &(b->lock_mutex);
    int result_mutex_init = pthread_mutex_init(m, &pshared_mode);
    --result;
    if (result_mutex_init != 0)
      {
    pthread_mutexattr_destroy(&pshared_mode);
    return result;
      }
  }
  {
    int result_attr_destroy = pthread_mutexattr_destroy(&pshared_mode);
    --result;
    if (result_attr_destroy != 0)
      return result;
  }
  b->size = 0;
  b->safeguard = SAFEGUARDVALUE;
  for (int i = 0; i  <= ATRSHMLOGSLOTCOUNT; i++)
    b->slots[i] = 0;
  b->state = atr_shm_log_writeable;
  b->count_writes = 0;
  b->count_uses = 0;
  b->count_memcpy = 0;
  b->count_state_ok_first_check = 0;
  b->count_state_not_ok = 0;
  b->count_state_not_ok_second = 0;
  b->count_mutex_lock= 0 ;
  b->count_safeguard_problem= 0 ;
  b->count_state_check_ok_second_check= 0 ;
  b->count_buffer_filled= 0 ;
  b->count_slot_checks= 0 ;
  b->count_slots_full= 0 ;
  return 0;
}
int atrshmlog_init_one_buffer ( atr_shm_log_area_t * i_shm , int i_index_buffer ) { int result = -1 ; pthread_mutexattr_t pshared_mode ; atr_shm_log_buffer_t * b = & ( i_shm -> logbuffers [ i_index_buffer ] ) ; { int init_attr_result = pthread_mutexattr_init ( & pshared_mode ) ; -- result ; if ( init_attr_result != 0 ) return result ; } { int share_mode = PTHREAD_PROCESS_SHARED ; int result_set_proc = pthread_mutexattr_setpshared ( & pshared_mode , share_mode ) ; -- result ; if ( result_set_proc != 0 ) { pthread_mutexattr_destroy ( & pshared_mode ) ; return result ; } } { pthread_mutex_t * m = & ( b -> lock_mutex ) ; int result_mutex_init = pthread_mutex_init ( m , & pshared_mode ) ; -- result ; if ( result_mutex_init != 0 ) { pthread_mutexattr_destroy ( & pshared_mode ) ; return result ; } } { int result_attr_destroy = pthread_mutexattr_destroy ( & pshared_mode ) ; -- result ; if ( result_attr_destroy != 0 ) return result ; } b -> size = 0 ; b -> safeguard = SAFEGUARDVALUE ; for ( int i = 0 ; i <= ATRSHMLOGSLOTCOUNT ; i ++ ) b -> slots [ i ] = 0 ; b -> state = atr_shm_log_writeable ; b -> count_writes = 0 ; b -> count_uses = 0 ; b -> count_memcpy = 0 ; b -> count_state_ok_first_check = 0 ; b -> count_state_not_ok = 0 ; b -> count_state_not_ok_second = 0 ; b -> count_mutex_lock = 0 ; b -> count_safeguard_problem = 0 ; b -> count_state_check_ok_second_check = 0 ; b -> count_buffer_filled = 0 ; b -> count_slot_checks = 0 ; b -> count_slots_full = 0 ; return 0 ; }
helper: we initialize one buffer
pthread version
helper : we initialize one buffer pthread version
/* this is the only critical part : we have to initialize the mutex */ /* we init first the attribute, shareable for processes */ /* ok. we have the attr. now we declaire its inter process shared */ /* ok. we can now init the mutex itself */ /* ok, we have to clean up on our side */ /* ok. we are through. we have to set the final infos and thats it */