fix a few more bugs - move thread safety management outside of these
routines. This commit was SVN r2188.
Этот коммит содержится в:
родитель
b0ea8e0b06
Коммит
2c70be74cf
@ -17,7 +17,9 @@
|
||||
* This defines a set of functions to create, and manipulate a FIFO
|
||||
* set up in a circular buffer. FIFO elements are assumed to be
|
||||
* pointers. Pointers are written to the head, and read from the
|
||||
* tail.
|
||||
* tail. For thread safety, a spin lock is provided in the
|
||||
* ompi_cb_fifo_ctl_t structure, but it's use must be managed by
|
||||
* the calling routines - this is not by these set of routines.
|
||||
*/
|
||||
|
||||
/* error code */
|
||||
@ -240,38 +242,6 @@ static inline int ompi_cb_fifo_write_to_slot(int slot, void* data, ompi_cb_fifo_
|
||||
*
|
||||
*/
|
||||
static inline int ompi_cb_fifo_write_to_head(void *data, ompi_cb_fifo_t *fifo) {
|
||||
int slot = OMPI_CB_ERROR, index;
|
||||
spinlock(&(fifo->head->lock));
|
||||
index = fifo->head->fifo_index;
|
||||
/* make sure the head is pointing at a free element - avoid wrap
|
||||
* around */
|
||||
if (fifo->queue[index] == OMPI_CB_FREE) {
|
||||
slot = index;
|
||||
fifo->queue[slot] = data;
|
||||
(fifo->head->fifo_index)++;
|
||||
(fifo->head->fifo_index) &= fifo->mask;
|
||||
}
|
||||
spinunlock(&(fifo->head->lock));
|
||||
|
||||
/* return */
|
||||
return slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try and write pointer ot the head of the queue without locking
|
||||
* the head structure
|
||||
*
|
||||
* Try to write pointer to the head of the queue
|
||||
*
|
||||
* @param data Pointer value to write in specified slot (IN)
|
||||
*
|
||||
* @param fifo Pointer to data structure defining this fifo (IN)
|
||||
*
|
||||
* @returncode Slot index to which data is written
|
||||
*
|
||||
*/
|
||||
static inline int ompi_cb_fifo_write_to_head_no_lock(void *data, ompi_cb_fifo_t *fifo)
|
||||
{
|
||||
int slot = OMPI_CB_ERROR, index;
|
||||
index = fifo->head->fifo_index;
|
||||
/* make sure the head is pointing at a free element - avoid wrap
|
||||
@ -287,6 +257,7 @@ static inline int ompi_cb_fifo_write_to_head_no_lock(void *data, ompi_cb_fifo_t
|
||||
return slot;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reserve slot in the fifo array
|
||||
*
|
||||
@ -300,34 +271,6 @@ static inline int ompi_cb_fifo_write_to_head_no_lock(void *data, ompi_cb_fifo_t
|
||||
static inline int ompi_cb_fifo_get_slot(ompi_cb_fifo_t *fifo) {
|
||||
int return_value = OMPI_CB_ERROR,index;
|
||||
|
||||
spinlock(&(fifo->head->lock));
|
||||
index = fifo->head->fifo_index;
|
||||
/* try and reserve slot */
|
||||
if (fifo->queue[index] == OMPI_CB_FREE) {
|
||||
fifo->queue[index] = OMPI_CB_RESERVED;
|
||||
return_value = index;
|
||||
(fifo->head->fifo_index)++;
|
||||
(fifo->head->fifo_index) &= fifo->mask;
|
||||
}
|
||||
spinunlock(&(fifo->head->lock));
|
||||
|
||||
/* return */
|
||||
return return_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve slot in the fifo array - no locking for thread safety done
|
||||
*
|
||||
* @param fifo Pointer to data structure defining this fifo (IN)
|
||||
*
|
||||
* @returncode Slot index to which data is written
|
||||
*
|
||||
* @returncode OMPI_CB_ERROR failed to allocate index
|
||||
*
|
||||
*/
|
||||
static inline int ompi_cb_fifo_get_slot_no_lock(ompi_cb_fifo_t *fifo)
|
||||
{
|
||||
int return_value = OMPI_CB_ERROR,index;
|
||||
index = fifo->head->fifo_index;
|
||||
/* try and reserve slot */
|
||||
if (fifo->queue[index] == OMPI_CB_FREE) {
|
||||
@ -351,39 +294,29 @@ static inline int ompi_cb_fifo_get_slot_no_lock(ompi_cb_fifo_t *fifo)
|
||||
* @returncode Slot index to which data is written
|
||||
*
|
||||
*/
|
||||
static inline int ompi_cb_fifo_read_from_tail(void** data, ompi_cb_fifo_t *fifo)
|
||||
static inline void *ompi_cb_fifo_read_from_tail(ompi_cb_fifo_t *fifo)
|
||||
{
|
||||
int read_from_tail = OMPI_CB_ERROR,index = 0,clearIndex, i;
|
||||
int index = 0,clearIndex, i;
|
||||
void *read_from_tail = (void *)OMPI_CB_ERROR;
|
||||
|
||||
/* check to see that the data is valid */
|
||||
if ((fifo->queue[fifo->tail->fifo_index] == OMPI_CB_FREE) ||
|
||||
(fifo->queue[fifo->tail->fifo_index] == OMPI_CB_RESERVED))
|
||||
{
|
||||
return OMPI_CB_ERROR;
|
||||
}
|
||||
|
||||
/* lock tail - for thread safety */
|
||||
spinlock(&(fifo->tail->lock));
|
||||
|
||||
/* make sure that there is still data to read - other thread
|
||||
* may have gotten here first */
|
||||
if ( (fifo->queue[fifo->tail->fifo_index] == OMPI_CB_FREE ) ||
|
||||
(fifo->queue[fifo->tail->fifo_index] == OMPI_CB_RESERVED ) ) {
|
||||
spinunlock(&(fifo->tail->lock));
|
||||
return OMPI_CB_ERROR;
|
||||
return (void *)OMPI_CB_ERROR;
|
||||
}
|
||||
|
||||
/* set return data */
|
||||
index = fifo->tail->fifo_index;
|
||||
*data = fifo->queue[index];
|
||||
read_from_tail = (void *)fifo->queue[index];
|
||||
fifo->tail->num_to_clear++;
|
||||
|
||||
/* check to see if time to do a lazy free of queue slots */
|
||||
if (fifo->tail->num_to_clear == ompi_lazy_free_frequency) {
|
||||
clearIndex = index - ompi_lazy_free_frequency + 1;
|
||||
if (fifo->tail->num_to_clear == fifo->lazy_free_frequency) {
|
||||
clearIndex = index - fifo->lazy_free_frequency + 1;
|
||||
clearIndex &= fifo->mask;
|
||||
|
||||
for (i = 0; i < ompi_lazy_free_frequency; i++) {
|
||||
for (i = 0; i < fifo->lazy_free_frequency; i++) {
|
||||
fifo->queue[clearIndex] = OMPI_CB_FREE;
|
||||
clearIndex++;
|
||||
clearIndex &= fifo->mask;
|
||||
@ -392,69 +325,6 @@ static inline int ompi_cb_fifo_read_from_tail(void** data, ompi_cb_fifo_t *fifo)
|
||||
}
|
||||
|
||||
/* increment counter for later lazy free */
|
||||
read_from_tail = fifo->tail->fifo_index;
|
||||
(fifo->tail->fifo_index)++;
|
||||
(fifo->tail->fifo_index) &= fifo->mask;
|
||||
|
||||
/* unlock tail */
|
||||
spinunlock(&(fifo->tail->lock));
|
||||
|
||||
/* return */
|
||||
return read_from_tail;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Try to read pointer from the tail of the queue - no locking for
|
||||
* thread safety.
|
||||
*
|
||||
* @param data Pointer to where data was be written (out)
|
||||
*
|
||||
* @param fifo Pointer to data structure defining this fifo (IN)
|
||||
*
|
||||
* @returncode Slot index to which data is written
|
||||
*
|
||||
*/
|
||||
static inline int ompi_cb_fifo_read_from_tail_no_lock(void** data, ompi_cb_fifo_t *fifo)
|
||||
{
|
||||
int read_from_tail = OMPI_CB_ERROR,index = 0,clearIndex, i;
|
||||
|
||||
/* check to see that the data is valid */
|
||||
if ((fifo->queue[fifo->tail->fifo_index] == OMPI_CB_FREE) ||
|
||||
(fifo->queue[fifo->tail->fifo_index] == OMPI_CB_RESERVED))
|
||||
{
|
||||
return OMPI_CB_ERROR;
|
||||
}
|
||||
|
||||
/* lock tail - for thread safety */
|
||||
|
||||
/* make sure that there is still data to read - other thread
|
||||
* may have gotten here first */
|
||||
if ((fifo->queue[fifo->tail->fifo_index] == OMPI_CB_FREE ) ||
|
||||
(fifo->queue[fifo->tail->fifo_index] == OMPI_CB_RESERVED )) {
|
||||
return OMPI_CB_ERROR;
|
||||
}
|
||||
|
||||
/* set return data */
|
||||
index = fifo->tail->fifo_index;
|
||||
*data = fifo->queue[index];
|
||||
fifo->tail->num_to_clear++;
|
||||
|
||||
/* check to see if time to do a lazy free of queue slots */
|
||||
if (fifo->tail->num_to_clear == ompi_lazy_free_frequency) {
|
||||
clearIndex = index - ompi_lazy_free_frequency + 1;
|
||||
clearIndex &= fifo->mask;
|
||||
|
||||
for (i = 0; i < ompi_lazy_free_frequency; i++) {
|
||||
fifo->queue[clearIndex] = OMPI_CB_FREE;
|
||||
clearIndex++;
|
||||
clearIndex &= fifo->mask;
|
||||
}
|
||||
fifo->tail->num_to_clear = 0;
|
||||
}
|
||||
|
||||
/* increment counter for later lazy free */
|
||||
read_from_tail = fifo->tail->fifo_index;
|
||||
(fifo->tail->fifo_index)++;
|
||||
(fifo->tail->fifo_index) &= fifo->mask;
|
||||
|
||||
@ -462,7 +332,6 @@ static inline int ompi_cb_fifo_read_from_tail_no_lock(void** data, ompi_cb_fifo_
|
||||
return read_from_tail;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the fifo size
|
||||
*
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user