Skip to content

Commit 9e87e6f

Browse files
authored
Merge pull request #1464 from martin-frbg/issue1461
Add locks only for non-OPENMP multithreading
2 parents e7366a4 + 3119b2a commit 9e87e6f

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

driver/others/memory.c

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,15 @@ static void *alloc_mmap(void *address){
455455
}
456456

457457
if (map_address != (void *)-1) {
458+
#if defined(SMP) && !defined(USE_OPENMP)
458459
LOCK_COMMAND(&alloc_lock);
460+
#endif
459461
release_info[release_pos].address = map_address;
460462
release_info[release_pos].func = alloc_mmap_free;
461463
release_pos ++;
464+
#if defined(SMP) && !defined(USE_OPENMP)
462465
UNLOCK_COMMAND(&alloc_lock);
466+
#endif
463467
}
464468

465469
#ifdef OS_LINUX
@@ -601,14 +605,18 @@ static void *alloc_mmap(void *address){
601605
#if defined(OS_LINUX) && !defined(NO_WARMUP)
602606
}
603607
#endif
604-
LOCK_COMMAND(&alloc_lock);
605608

606609
if (map_address != (void *)-1) {
610+
#if defined(SMP) && !defined(USE_OPENMP)
611+
LOCK_COMMAND(&alloc_lock);
612+
#endif
607613
release_info[release_pos].address = map_address;
608614
release_info[release_pos].func = alloc_mmap_free;
609615
release_pos ++;
616+
#if defined(SMP) && !defined(USE_OPENMP)
617+
UNLOCK_COMMAND(&alloc_lock);
618+
#endif
610619
}
611-
UNLOCK_COMMAND(&alloc_lock);
612620

613621
return map_address;
614622
}
@@ -1007,7 +1015,10 @@ void *blas_memory_alloc(int procpos){
10071015
NULL,
10081016
};
10091017
void *(**func)(void *address);
1018+
1019+
#if defined(SMP) && !defined(USE_OPENMP)
10101020
LOCK_COMMAND(&alloc_lock);
1021+
#endif
10111022

10121023
if (!memory_initialized) {
10131024

@@ -1041,7 +1052,9 @@ void *blas_memory_alloc(int procpos){
10411052
memory_initialized = 1;
10421053

10431054
}
1055+
#if defined(SMP) && !defined(USE_OPENMP)
10441056
UNLOCK_COMMAND(&alloc_lock);
1057+
#endif
10451058

10461059
#ifdef DEBUG
10471060
printf("Alloc Start ...\n");
@@ -1056,12 +1069,15 @@ void *blas_memory_alloc(int procpos){
10561069

10571070
do {
10581071
if (!memory[position].used && (memory[position].pos == mypos)) {
1072+
#if defined(SMP) && !defined(USE_OPENMP)
10591073
LOCK_COMMAND(&alloc_lock);
1074+
#endif
10601075
/* blas_lock(&memory[position].lock);*/
10611076

10621077
if (!memory[position].used) goto allocation;
1063-
1078+
#if defined(SMP) && !defined(USE_OPENMP)
10641079
UNLOCK_COMMAND(&alloc_lock);
1080+
#endif
10651081
/* blas_unlock(&memory[position].lock);*/
10661082
}
10671083

@@ -1076,12 +1092,15 @@ void *blas_memory_alloc(int procpos){
10761092

10771093
do {
10781094
/* if (!memory[position].used) { */
1095+
#if defined(SMP) && !defined(USE_OPENMP)
10791096
LOCK_COMMAND(&alloc_lock);
1097+
#endif
10801098
/* blas_lock(&memory[position].lock);*/
10811099

10821100
if (!memory[position].used) goto allocation;
1083-
1101+
#if defined(SMP) && !defined(USE_OPENMP)
10841102
UNLOCK_COMMAND(&alloc_lock);
1103+
#endif
10851104
/* blas_unlock(&memory[position].lock);*/
10861105
/* } */
10871106

@@ -1098,8 +1117,10 @@ void *blas_memory_alloc(int procpos){
10981117
#endif
10991118

11001119
memory[position].used = 1;
1101-
1120+
#if defined(SMP) && !defined(USE_OPENMP)
11021121
UNLOCK_COMMAND(&alloc_lock);
1122+
#endif
1123+
11031124
/* blas_unlock(&memory[position].lock);*/
11041125

11051126
if (!memory[position].addr) {
@@ -1146,9 +1167,13 @@ void *blas_memory_alloc(int procpos){
11461167

11471168
} while ((BLASLONG)map_address == -1);
11481169

1170+
#if defined(SMP) && !defined(USE_OPENMP)
11491171
LOCK_COMMAND(&alloc_lock);
1172+
#endif
11501173
memory[position].addr = map_address;
1174+
#if defined(SMP) && !defined(USE_OPENMP)
11511175
UNLOCK_COMMAND(&alloc_lock);
1176+
#endif
11521177

11531178
#ifdef DEBUG
11541179
printf(" Mapping Succeeded. %p(%d)\n", (void *)memory[position].addr, position);
@@ -1165,7 +1190,9 @@ void *blas_memory_alloc(int procpos){
11651190

11661191
if (memory_initialized == 1) {
11671192

1193+
#if defined(SMP) && !defined(USE_OPENMP)
11681194
LOCK_COMMAND(&alloc_lock);
1195+
#endif
11691196

11701197
if (memory_initialized == 1) {
11711198

@@ -1174,8 +1201,9 @@ void *blas_memory_alloc(int procpos){
11741201
memory_initialized = 2;
11751202
}
11761203

1204+
#if defined(SMP) && !defined(USE_OPENMP)
11771205
UNLOCK_COMMAND(&alloc_lock);
1178-
1206+
#endif
11791207
}
11801208
#endif
11811209

@@ -1202,8 +1230,9 @@ void blas_memory_free(void *free_area){
12021230
#endif
12031231

12041232
position = 0;
1233+
#if defined(SMP) && !defined(USE_OPENMP)
12051234
LOCK_COMMAND(&alloc_lock);
1206-
1235+
#endif
12071236
while ((position < NUM_BUFFERS) && (memory[position].addr != free_area))
12081237
position++;
12091238

@@ -1217,7 +1246,9 @@ void blas_memory_free(void *free_area){
12171246
WMB;
12181247

12191248
memory[position].used = 0;
1249+
#if defined(SMP) && !defined(USE_OPENMP)
12201250
UNLOCK_COMMAND(&alloc_lock);
1251+
#endif
12211252

12221253
#ifdef DEBUG
12231254
printf("Unmap Succeeded.\n\n");
@@ -1232,8 +1263,9 @@ void blas_memory_free(void *free_area){
12321263
for (position = 0; position < NUM_BUFFERS; position++)
12331264
printf("%4ld %p : %d\n", position, memory[position].addr, memory[position].used);
12341265
#endif
1266+
#if defined(SMP) && !defined(USE_OPENMP)
12351267
UNLOCK_COMMAND(&alloc_lock);
1236-
1268+
#endif
12371269
return;
12381270
}
12391271

0 commit comments

Comments
 (0)