2010-02-14 22:20:19 +03:00
|
|
|
/* -*- Mode: C; c-basic-offset:4 ; -*- */
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2008 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OPAL_RING_BUFFER_H
|
|
|
|
#define OPAL_RING_BUFFER_H
|
|
|
|
|
|
|
|
#include "opal_config.h"
|
|
|
|
|
2010-07-29 06:12:44 +04:00
|
|
|
#include "opal/threads/threads.h"
|
2010-02-14 22:20:19 +03:00
|
|
|
#include "opal/class/opal_object.h"
|
|
|
|
#include "opal/util/output.h"
|
|
|
|
|
|
|
|
BEGIN_C_DECLS
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dynamic pointer ring
|
|
|
|
*/
|
|
|
|
struct opal_ring_buffer_t {
|
|
|
|
/** base class */
|
|
|
|
opal_object_t super;
|
|
|
|
/** synchronization object */
|
|
|
|
opal_mutex_t lock;
|
2010-07-29 06:12:44 +04:00
|
|
|
opal_condition_t cond;
|
|
|
|
bool in_use;
|
2010-02-14 22:20:19 +03:00
|
|
|
/* head/tail indices */
|
2011-01-13 04:54:05 +03:00
|
|
|
int head;
|
|
|
|
int tail;
|
2010-02-14 22:20:19 +03:00
|
|
|
/** size of list, i.e. number of elements in addr */
|
|
|
|
int size;
|
|
|
|
/** pointer to ring */
|
|
|
|
char **addr;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Convenience typedef
|
|
|
|
*/
|
|
|
|
typedef struct opal_ring_buffer_t opal_ring_buffer_t;
|
|
|
|
/**
|
|
|
|
* Class declaration
|
|
|
|
*/
|
|
|
|
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_ring_buffer_t);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the ring buffer, defining its size.
|
|
|
|
*
|
|
|
|
* @param ring Pointer to a ring buffer (IN/OUT)
|
|
|
|
* @param size The number of elements in the ring (IN)
|
|
|
|
*
|
|
|
|
* @return OPAL_SUCCESS if all initializations were succesful. Otherwise,
|
|
|
|
* the error indicate what went wrong in the function.
|
|
|
|
*/
|
|
|
|
OPAL_DECLSPEC int opal_ring_buffer_init(opal_ring_buffer_t* ring, int size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Push an item onto the ring buffer
|
|
|
|
*
|
|
|
|
* @param ring Pointer to ring (IN)
|
|
|
|
* @param ptr Pointer value (IN)
|
|
|
|
*
|
|
|
|
* @return OPAL_SUCCESS. Returns error if ring cannot take
|
|
|
|
* another entry
|
|
|
|
*/
|
2011-01-13 04:54:05 +03:00
|
|
|
OPAL_DECLSPEC void* opal_ring_buffer_push(opal_ring_buffer_t *ring, void *ptr);
|
2010-02-14 22:20:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-01-13 04:54:05 +03:00
|
|
|
* Pop an item off of the ring. The oldest entry on the ring will be
|
2010-02-14 22:20:19 +03:00
|
|
|
* returned. If nothing on the ring, NULL is returned.
|
|
|
|
*
|
|
|
|
* @param ring Pointer to ring (IN)
|
|
|
|
*
|
|
|
|
* @return Error code. NULL indicates an error.
|
|
|
|
*/
|
|
|
|
|
2011-01-13 04:54:05 +03:00
|
|
|
OPAL_DECLSPEC void* opal_ring_buffer_pop(opal_ring_buffer_t *ring);
|
2010-02-14 22:20:19 +03:00
|
|
|
|
2011-01-13 04:54:05 +03:00
|
|
|
/*
|
|
|
|
* Access an element of the ring, without removing it, indexed
|
|
|
|
* starting at the tail
|
|
|
|
*/
|
|
|
|
OPAL_DECLSPEC void* opal_ring_buffer_poke(opal_ring_buffer_t *ring, int i);
|
2010-02-14 22:20:19 +03:00
|
|
|
|
|
|
|
END_C_DECLS
|
|
|
|
|
|
|
|
#endif /* OPAL_RING_BUFFER_H */
|