Skip to content

Commit

Permalink
Merge pull request OpenMathLib#4693 from goplanid/locks-improvement
Browse files Browse the repository at this point in the history
Lock Management Improvements for Memory Allocation Efficiency
  • Loading branch information
martin-frbg committed May 26, 2024
2 parents 834e633 + 0dc80a5 commit 0073aff
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions driver/others/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -2746,7 +2746,7 @@ struct newmemstruct
};
static volatile struct newmemstruct *newmemory;

static int memory_initialized = 0;
static volatile int memory_initialized = 0;
static int memory_overflowed = 0;
/* Memory allocation routine */
/* procpos ... indicates where it comes from */
Expand Down Expand Up @@ -2791,14 +2791,12 @@ void *blas_memory_alloc(int procpos){
};
void *(**func)(void *address);

#if defined(USE_OPENMP)
if (!memory_initialized) {
#if defined(SMP) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
if (!memory_initialized) {
#endif

LOCK_COMMAND(&alloc_lock);

if (!memory_initialized) {

#if defined(WHEREAMI) && !defined(USE_OPENMP)
for (position = 0; position < NUM_BUFFERS; position ++){
memory[position].addr = (void *)0;
Expand Down Expand Up @@ -2827,12 +2825,12 @@ void *blas_memory_alloc(int procpos){
#endif

memory_initialized = 1;

WMB;
#if defined(SMP) && !defined(USE_OPENMP)
}
UNLOCK_COMMAND(&alloc_lock);
#if defined(USE_OPENMP)
}
#endif
}

#ifdef DEBUG
printf("Alloc Start ...\n");
Expand Down

0 comments on commit 0073aff

Please sign in to comment.