function lfds700_ringbuffer_write

From liblfds.org
Jump to navigation Jump to search

Source Files

└───liblfds700
    ├───inc
    │   └───liblfds700
    │           lfds700_ringbuffer.h
    └───src
        └───lfds700_ringbuffer
                lfds700_ringbuffer_write.c

Opaque Structures

struct lfds700_misc_prng_state;
struct lfds700_ringbuffer_state;

Prototype

void lfds700_ringbuffer_write( struct lfds700_ringbuffer_state *rs,
                               void *key,
                               void *value,
                               enum lfds700_liblfds_flag *overwrite_occurred_flag,
                               void **overwritten_key,
                               void **overwritten_value,
                               struct lfds700_misc_prng_state *ps );

Parameters

struct lfds700_ringbuffer_state *rs

A pointer to an initialized struct lfds700_ringbuffer_state.

void *key

A void pointer which is written into the ringbuffer as the key. If the ringbuffer is full, the oldest unread element is overwritten.

void *value

A void pointer which is written into the ringbuffer as the value. If the ringbuffer is full, the oldest unread element is overwritten.

enum lfds700_flag *overwrite_occurred_flag

If this argument is non-NULL, then if the ringbuffer was full and the oldest unread element overwritten, '*overwrite_occurred_flag is set to LFDS700_RAISED' otherwise it is set to LFDS700_LOWERED'.

void **overwritten_key

If this argument is non-NULL, and if the ringbuffer was full and so the oldest unread element was overwritten, '*overwritten_value is set to the key present in the overwritten element.

void **overwritten_value

If this argument is non-NULL, and if the ringbuffer was full and so the oldest unread element was overwritten, '*overwritten_value is set to the value present in the overwritten element.

struct lfds700_misc_prng_state *ps

A pointer to an initialized struct lfds700_misc_prng_state.

Notes

This function writes a key/value pair into the ringbuffer. If the ringbuffer is full, the oldest unread element is overwritten and, if they are provided (rather than being NULL), *overwrite_occurred_flag is set to LFDS700_RAISED and *overwritten_key and *overwritten_value are set to the key and value in the overwritten element.

Example

#include <stdio.h>
#include "liblfds700.h"

int main()
{
  struct lfds700_misc_prng_state
    ps;

  struct lfds700_ringbuffer_element
    *re;

  struct lfds700_ringbuffer_state
    rs;

  char
    key[64] = "quarks",
    value[64] = "all the way down";

  lfds700_misc_library_init_valid_on_current_logical_core();

  lfds700_misc_prng_init( &ps );

  re = malloc( sizeof(struct lfds700_ringbuffer_element) * 11 );

  lfds700_ringbuffer_init_valid_on_current_logical_core( &rs, re, 11, &ps, NULL );

  lfds700_ringbuffer_write( &rs, (void *) key, (void *) value, NULL, NULL, NULL, &ps );

  lfds700_ringbuffer_cleanup( rs, NULL );

  free( re );

  lfds700_misc_library_cleanup();

  return( EXIT_SUCCESS );
}

See Also