19 #ifndef OPAL_FREE_LIST_H
20 #define OPAL_FREE_LIST_H
22 #include "opal_config.h"
25 #include "opal/threads/condition.h"
26 #include "opal/constants.h"
34 size_t fl_max_to_alloc;
35 size_t fl_num_allocated;
36 size_t fl_num_per_alloc;
37 size_t fl_num_waiting;
65 OPAL_DECLSPEC
int opal_free_list_init(
69 int num_elements_to_alloc,
70 int max_elements_to_alloc,
71 int num_elements_per_alloc);
73 OPAL_DECLSPEC
int opal_free_list_grow(
opal_free_list_t* flist,
size_t num_elements) __opal_attribute_nonnull__(1);
88 #define OPAL_FREE_LIST_GET(fl, item, rc) \
90 if(opal_using_threads()) { \
91 opal_mutex_lock(&((fl)->fl_lock)); \
92 item = (opal_free_list_item_t*) \
93 opal_list_remove_first(&((fl)->super)); \
94 if( OPAL_UNLIKELY(NULL == item) ) { \
95 opal_free_list_grow((fl), (fl)->fl_num_per_alloc); \
96 item = (opal_free_list_item_t*) \
97 opal_list_remove_first(&((fl)->super)); \
99 opal_mutex_unlock(&((fl)->fl_lock)); \
101 item = (opal_free_list_item_t*) \
102 opal_list_remove_first(&((fl)->super)); \
103 if( OPAL_UNLIKELY(NULL == item) ) { \
104 opal_free_list_grow((fl), (fl)->fl_num_per_alloc); \
105 item = (opal_free_list_item_t*) \
106 opal_list_remove_first(&((fl)->super)); \
109 rc = (NULL == item) ? OPAL_ERR_TEMP_OUT_OF_RESOURCE : OPAL_SUCCESS; \
125 #define OPAL_FREE_LIST_WAIT(fl, item, rc) \
127 OPAL_THREAD_LOCK(&((fl)->fl_lock)); \
128 while( NULL == (item = (opal_free_list_item_t*) opal_list_remove_first(&((fl)->super))) ) { \
129 if( OPAL_LIKELY((fl)->fl_max_to_alloc <= (fl)->fl_num_allocated) ) { \
130 (fl)->fl_num_waiting++; \
131 opal_condition_wait(&((fl)->fl_condition), &((fl)->fl_lock)); \
132 (fl)->fl_num_waiting--; \
134 opal_free_list_grow((fl), (fl)->fl_num_per_alloc); \
137 OPAL_THREAD_UNLOCK(&((fl)->fl_lock)); \
150 #define OPAL_FREE_LIST_RETURN(fl, item) \
152 OPAL_THREAD_LOCK(&(fl)->fl_lock); \
153 opal_list_prepend(&((fl)->super), ((opal_list_item_t*) item)); \
154 if( OPAL_UNLIKELY((fl)->fl_num_waiting > 0) ) { \
155 opal_condition_signal(&((fl)->fl_condition)); \
157 OPAL_THREAD_UNLOCK(&(fl)->fl_lock); \
Definition: condition.h:49
Definition: mutex_unix.h:53
The opal_list_t interface is used to provide a generic doubly-linked list container for Open MPI...
Definition: opal_list.h:98
Class descriptor.
Definition: opal_object.h:152
Definition: opal_free_list.h:47
Definition: opal_free_list.h:31
Definition: opal_list.h:147
Compiler-specific prefetch functions.
#define OBJ_CLASS_DECLARATION(NAME)
Declaration for class descriptor.
Definition: opal_object.h:236