rtdb/kogmo_rtdb_objdata.c
/*! \brief Find an Object-History-Slot by its Slot-Number with adjustment.
 * For internal use only.
 * adj: 0 = get current slot, must be called first for initialization!
 *     -1 = get previous slot,
 *     +1 = get next slot
 * Note:
 *  - currslot & firstslot are internal and will be changed
 * \returns Pointer to its Data or NULL if not found or history-overrun
 */
\brief Find an Object-History-Slot by its Slot-Number with adjustment.
For internal use only.
adj: 0 = get current slot, must be called first for initialization.
-1 = get previous slot,
+1 = get next slot
Note:
- currslot & firstslot are internal and will be changed
\returns Pointer to its Data or NULL if not found or history-overrun
\ brief Find an Object - History - Slot by its Slot - Number with adjustment . For internal use only . adj : 0 = get current slot must be called first for initialization . - 1 = get previous slot + 1 = get next slot Note : - currslot & firstslot are internal and will be changed \ returns Pointer to its Data or NULL if not found or history - overrun
inline static void *
kogmo_rtdb_obj_histscan (kogmo_rtdb_handle_t *db_h, int32_t adj,
                         kogmo_rtdb_obj_info_t *scan_objmeta_p,
                         int32_t *currslot_p2, int32_t *firstslot_p)
{
  kogmo_rtdb_subobj_base_t *objbase;
  int32_t currslot_tmp;
  int32_t *currslot_p; 
  if ( scan_objmeta_p -> history_size == 0)
    return NULL;
  if ( currslot_p2 )
    {
      currslot_p = currslot_p2;
    }
  else
    {
      currslot_p = &currslot_tmp;
      *currslot_p = scan_objmeta_p -> history_slot;
    }
  if ( adj == 0 )
    {
      *currslot_p = scan_objmeta_p -> history_slot;
      if ( firstslot_p )
        *firstslot_p = *currslot_p;
    }
  else
    {
      *currslot_p += adj;
    }
  if ( currslot_p < 0 ) 
    return NULL;
  *currslot_p = (*currslot_p + scan_objmeta_p -> history_size ) % scan_objmeta_p -> history_size;
  if ( firstslot_p && *currslot_p == *firstslot_p && adj != 0 )
    {
      return NULL;
    }
  objbase = (kogmo_rtdb_subobj_base_t *)
             & ( db_h->localdata_p -> heap [
                                             scan_objmeta_p -> buffer_idx +
                                             *currslot_p * scan_objmeta_p -> size_max
                                           ] );
  if ( CMP_INT64_HIGH(objbase -> committed_ts, invalid_ts) )
    {
      return NULL;
    }
  return objbase;
}
inline static void * kogmo_rtdb_obj_histscan ( kogmo_rtdb_handle_t * db_h , int32_t adj , kogmo_rtdb_obj_info_t * scan_objmeta_p , int32_t * currslot_p2 , int32_t * firstslot_p ) { kogmo_rtdb_subobj_base_t * objbase ; int32_t currslot_tmp ; int32_t * currslot_p ; if ( scan_objmeta_p -> history_size == 0 ) return NULL ; if ( currslot_p2 ) { currslot_p = currslot_p2 ; } else { currslot_p = & currslot_tmp ; * currslot_p = scan_objmeta_p -> history_slot ; } if ( adj == 0 ) { * currslot_p = scan_objmeta_p -> history_slot ; if ( firstslot_p ) * firstslot_p = * currslot_p ; } else { * currslot_p += adj ; } if ( currslot_p < 0 ) return NULL ; * currslot_p = ( * currslot_p + scan_objmeta_p -> history_size ) % scan_objmeta_p -> history_size ; if ( firstslot_p && * currslot_p == * firstslot_p && adj != 0 ) { return NULL ; } objbase = ( kogmo_rtdb_subobj_base_t * ) & ( db_h -> localdata_p -> heap [ scan_objmeta_p -> buffer_idx + * currslot_p * scan_objmeta_p -> size_max ] ) ; if ( CMP_INT64_HIGH ( objbase -> committed_ts , invalid_ts ) ) { return NULL ; } return objbase ; }
\brief Find an Object-History-Slot by its Slot-Number with adjustment.
\ brief Find an Object - History - Slot by its Slot - Number with adjustment .
// = currslot_p2 ? currslot_p2 : &currslot_tmp; //xDBG("histscan: request: adj:%i, curr:%i last:%i",adj,xx*currslot_p,xx*firstslot_p); // get current slot = the latest data // no writes yet // calculate next slot position //xDBG("histscan: calculated next slot: %i",*currslot_p); // wrap-around check //xDBG("histscan: error: wrap around!"); // calculate object data pointer from history slot number //xDBG("histscan: error: unused slot"); //xDBG("histscan: result: curr:%i last:%i",*currslot_p,*firstslot_p);