Merge pull request #4693 from goplanid/locks-improvement

Lock Management Improvements for Memory Allocation Efficiency
This commit is contained in:
Martin Kroeker 2024-05-26 23:14:52 +02:00 committed by GitHub
commit 0073affe63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 9 deletions

View File

@ -2746,7 +2746,7 @@ struct newmemstruct
}; };
static volatile struct newmemstruct *newmemory; static volatile struct newmemstruct *newmemory;
static int memory_initialized = 0; static volatile int memory_initialized = 0;
static int memory_overflowed = 0; static int memory_overflowed = 0;
/* Memory allocation routine */ /* Memory allocation routine */
/* procpos ... indicates where it comes from */ /* procpos ... indicates where it comes from */
@ -2791,14 +2791,12 @@ void *blas_memory_alloc(int procpos){
}; };
void *(**func)(void *address); void *(**func)(void *address);
#if defined(USE_OPENMP) if (!memory_initialized) {
#if defined(SMP) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
if (!memory_initialized) { if (!memory_initialized) {
#endif #endif
LOCK_COMMAND(&alloc_lock);
if (!memory_initialized) {
#if defined(WHEREAMI) && !defined(USE_OPENMP) #if defined(WHEREAMI) && !defined(USE_OPENMP)
for (position = 0; position < NUM_BUFFERS; position ++){ for (position = 0; position < NUM_BUFFERS; position ++){
memory[position].addr = (void *)0; memory[position].addr = (void *)0;
@ -2827,12 +2825,12 @@ void *blas_memory_alloc(int procpos){
#endif #endif
memory_initialized = 1; memory_initialized = 1;
WMB;
#if defined(SMP) && !defined(USE_OPENMP)
} }
UNLOCK_COMMAND(&alloc_lock); UNLOCK_COMMAND(&alloc_lock);
#if defined(USE_OPENMP)
}
#endif #endif
}
#ifdef DEBUG #ifdef DEBUG
printf("Alloc Start ...\n"); printf("Alloc Start ...\n");