Skip to content

Commit 69d9f36

Browse files
authored
Merge pull request #1468 from martin-frbg/martin-frbg-patch-1
Limit the additional locking from PRs 1052,1299 to non-OpenMP cases
2 parents 5f855d9 + 7646974 commit 69d9f36

File tree

1 file changed

+50
-16
lines changed

1 file changed

+50
-16
lines changed

driver/others/memory.c

+50-16
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,6 +1015,11 @@ void *blas_memory_alloc(int procpos){
10071015
NULL,
10081016
};
10091017
void *(**func)(void *address);
1018+
1019+
#if defined(USE_OPENMP)
1020+
if (!memory_initialized) {
1021+
#endif
1022+
10101023
LOCK_COMMAND(&alloc_lock);
10111024

10121025
if (!memory_initialized) {
@@ -1042,6 +1055,9 @@ void *blas_memory_alloc(int procpos){
10421055

10431056
}
10441057
UNLOCK_COMMAND(&alloc_lock);
1058+
#if defined(USE_OPENMP)
1059+
}
1060+
#endif
10451061

10461062
#ifdef DEBUG
10471063
printf("Alloc Start ...\n");
@@ -1056,13 +1072,17 @@ void *blas_memory_alloc(int procpos){
10561072

10571073
do {
10581074
if (!memory[position].used && (memory[position].pos == mypos)) {
1075+
#if defined(SMP) && !defined(USE_OPENMP)
10591076
LOCK_COMMAND(&alloc_lock);
1060-
/* blas_lock(&memory[position].lock);*/
1061-
1077+
#else
1078+
blas_lock(&memory[position].lock);
1079+
#endif
10621080
if (!memory[position].used) goto allocation;
1063-
1081+
#if defined(SMP) && !defined(USE_OPENMP)
10641082
UNLOCK_COMMAND(&alloc_lock);
1065-
/* blas_unlock(&memory[position].lock);*/
1083+
#else
1084+
blas_unlock(&memory[position].lock);
1085+
#endif
10661086
}
10671087

10681088
position ++;
@@ -1075,15 +1095,19 @@ void *blas_memory_alloc(int procpos){
10751095
position = 0;
10761096

10771097
do {
1078-
/* if (!memory[position].used) { */
1098+
#if defined(SMP) && !defined(USE_OPENMP)
10791099
LOCK_COMMAND(&alloc_lock);
1080-
/* blas_lock(&memory[position].lock);*/
1081-
1100+
#else
1101+
if (!memory[position].used) {
1102+
blas_lock(&memory[position].lock);
1103+
#endif
10821104
if (!memory[position].used) goto allocation;
1083-
1105+
#if defined(SMP) && !defined(USE_OPENMP)
10841106
UNLOCK_COMMAND(&alloc_lock);
1085-
/* blas_unlock(&memory[position].lock);*/
1086-
/* } */
1107+
#else
1108+
blas_unlock(&memory[position].lock);
1109+
}
1110+
#endif
10871111

10881112
position ++;
10891113

@@ -1098,9 +1122,11 @@ void *blas_memory_alloc(int procpos){
10981122
#endif
10991123

11001124
memory[position].used = 1;
1101-
1125+
#if defined(SMP) && !defined(USE_OPENMP)
11021126
UNLOCK_COMMAND(&alloc_lock);
1103-
/* blas_unlock(&memory[position].lock);*/
1127+
#else
1128+
blas_unlock(&memory[position].lock);
1129+
#endif
11041130

11051131
if (!memory[position].addr) {
11061132
do {
@@ -1146,9 +1172,13 @@ void *blas_memory_alloc(int procpos){
11461172

11471173
} while ((BLASLONG)map_address == -1);
11481174

1175+
#if defined(SMP) && !defined(USE_OPENMP)
11491176
LOCK_COMMAND(&alloc_lock);
1177+
#endif
11501178
memory[position].addr = map_address;
1179+
#if defined(SMP) && !defined(USE_OPENMP)
11511180
UNLOCK_COMMAND(&alloc_lock);
1181+
#endif
11521182

11531183
#ifdef DEBUG
11541184
printf(" Mapping Succeeded. %p(%d)\n", (void *)memory[position].addr, position);
@@ -1202,8 +1232,9 @@ void blas_memory_free(void *free_area){
12021232
#endif
12031233

12041234
position = 0;
1235+
#if defined(SMP) && !defined(USE_OPENMP)
12051236
LOCK_COMMAND(&alloc_lock);
1206-
1237+
#endif
12071238
while ((position < NUM_BUFFERS) && (memory[position].addr != free_area))
12081239
position++;
12091240

@@ -1217,7 +1248,9 @@ void blas_memory_free(void *free_area){
12171248
WMB;
12181249

12191250
memory[position].used = 0;
1251+
#if defined(SMP) && !defined(USE_OPENMP)
12201252
UNLOCK_COMMAND(&alloc_lock);
1253+
#endif
12211254

12221255
#ifdef DEBUG
12231256
printf("Unmap Succeeded.\n\n");
@@ -1232,8 +1265,9 @@ void blas_memory_free(void *free_area){
12321265
for (position = 0; position < NUM_BUFFERS; position++)
12331266
printf("%4ld %p : %d\n", position, memory[position].addr, memory[position].used);
12341267
#endif
1268+
#if defined(SMP) && !defined(USE_OPENMP)
12351269
UNLOCK_COMMAND(&alloc_lock);
1236-
1270+
#endif
12371271
return;
12381272
}
12391273

0 commit comments

Comments
 (0)