From 0dc80a5c8dfc43d1550f489b1f4abba36eee675a Mon Sep 17 00:00:00 2001 From: Deeksha Goplani Date: Mon, 13 May 2024 22:17:23 +0530 Subject: [PATCH] locks improvement --- driver/others/memory.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/driver/others/memory.c b/driver/others/memory.c index 784a1f0282..53e49b452d 100644 --- a/driver/others/memory.c +++ b/driver/others/memory.c @@ -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 */ @@ -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; @@ -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");