function lfds700_ringbuffer_read

From liblfds.org
Revision as of 02:03, 30 December 2015 by Admin (talk | contribs) (→‎Example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Source Files

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

Opaque Structures

struct lfds700_misc_prng_state;
struct lfds700_ringbuffer_state;

Prototype

int lfds700_ringbuffer_read( struct lfds700_ringbuffer_state *rs,
                             void **key,
                             void **value,
                             struct lfds700_misc_prng_state *ps );

Parameters

struct lfds700_ringbuffer_state *rs

A pointer to an initialized struct lfds700_ringbuffer_state.

void **key

Set to the value of the key in the current read element. This argument can be NULL, in which case it is not used (and so the caller cannot know the key).

void **value

Set to the value of the value in the current read element. This argument can be NULL, in which case it is not used (and so the caller cannot know the value).

struct lfds700_misc_prng_state *ps

A pointer to an initialized struct lfds700_misc_prng_state.

Return Value

This function returns 1 on successful read, 0 if the ringbuffer has no unread elements.

Notes

Reads the oldest unread element in the ringbuffer. This element, which is to say the key and value in the element, are read by and only by one reader. Both

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";

  void
    *temp_key,
    *temp_value;

  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_read( &rs, &temp_key, &temp_value, &ps );

  // TRD : prints "quarks" and "all the way down"
  printf( "key = %s\n"
          "value = %s\n", (char *) key, (char *) value );

  lfds700_ringbuffer_cleanup( rs, NULL );

  lfds700_misc_library_cleanup();

  return( EXIT_SUCCESS );
}

See Also