Skip to content

Commit e3a80e6

Browse files
authored
Merge pull request #1466 from xianyi/revert-1464-issue1461
Revert "Add locks only for non-OPENMP multithreading"
2 parents 9e87e6f + 8866e39 commit e3a80e6

File tree

1 file changed

+8
-40
lines changed

1 file changed

+8
-40
lines changed

Diff for: driver/others/memory.c

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

457457
if (map_address != (void *)-1) {
458-
#if defined(SMP) && !defined(USE_OPENMP)
459458
LOCK_COMMAND(&alloc_lock);
460-
#endif
461459
release_info[release_pos].address = map_address;
462460
release_info[release_pos].func = alloc_mmap_free;
463461
release_pos ++;
464-
#if defined(SMP) && !defined(USE_OPENMP)
465462
UNLOCK_COMMAND(&alloc_lock);
466-
#endif
467463
}
468464

469465
#ifdef OS_LINUX
@@ -605,18 +601,14 @@ static void *alloc_mmap(void *address){
605601
#if defined(OS_LINUX) && !defined(NO_WARMUP)
606602
}
607603
#endif
604+
LOCK_COMMAND(&alloc_lock);
608605

609606
if (map_address != (void *)-1) {
610-
#if defined(SMP) && !defined(USE_OPENMP)
611-
LOCK_COMMAND(&alloc_lock);
612-
#endif
613607
release_info[release_pos].address = map_address;
614608
release_info[release_pos].func = alloc_mmap_free;
615609
release_pos ++;
616-
#if defined(SMP) && !defined(USE_OPENMP)
617-
UNLOCK_COMMAND(&alloc_lock);
618-
#endif
619610
}
611+
UNLOCK_COMMAND(&alloc_lock);
620612

621613
return map_address;
622614
}
@@ -1015,10 +1007,7 @@ void *blas_memory_alloc(int procpos){
10151007
NULL,
10161008
};
10171009
void *(**func)(void *address);
1018-
1019-
#if defined(SMP) && !defined(USE_OPENMP)
10201010
LOCK_COMMAND(&alloc_lock);
1021-
#endif
10221011

10231012
if (!memory_initialized) {
10241013

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

10541043
}
1055-
#if defined(SMP) && !defined(USE_OPENMP)
10561044
UNLOCK_COMMAND(&alloc_lock);
1057-
#endif
10581045

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

10701057
do {
10711058
if (!memory[position].used && (memory[position].pos == mypos)) {
1072-
#if defined(SMP) && !defined(USE_OPENMP)
10731059
LOCK_COMMAND(&alloc_lock);
1074-
#endif
10751060
/* blas_lock(&memory[position].lock);*/
10761061

10771062
if (!memory[position].used) goto allocation;
1078-
#if defined(SMP) && !defined(USE_OPENMP)
1063+
10791064
UNLOCK_COMMAND(&alloc_lock);
1080-
#endif
10811065
/* blas_unlock(&memory[position].lock);*/
10821066
}
10831067

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

10931077
do {
10941078
/* if (!memory[position].used) { */
1095-
#if defined(SMP) && !defined(USE_OPENMP)
10961079
LOCK_COMMAND(&alloc_lock);
1097-
#endif
10981080
/* blas_lock(&memory[position].lock);*/
10991081

11001082
if (!memory[position].used) goto allocation;
1101-
#if defined(SMP) && !defined(USE_OPENMP)
1083+
11021084
UNLOCK_COMMAND(&alloc_lock);
1103-
#endif
11041085
/* blas_unlock(&memory[position].lock);*/
11051086
/* } */
11061087

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

11191100
memory[position].used = 1;
1120-
#if defined(SMP) && !defined(USE_OPENMP)
1101+
11211102
UNLOCK_COMMAND(&alloc_lock);
1122-
#endif
1123-
11241103
/* blas_unlock(&memory[position].lock);*/
11251104

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

11681147
} while ((BLASLONG)map_address == -1);
11691148

1170-
#if defined(SMP) && !defined(USE_OPENMP)
11711149
LOCK_COMMAND(&alloc_lock);
1172-
#endif
11731150
memory[position].addr = map_address;
1174-
#if defined(SMP) && !defined(USE_OPENMP)
11751151
UNLOCK_COMMAND(&alloc_lock);
1176-
#endif
11771152

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

11911166
if (memory_initialized == 1) {
11921167

1193-
#if defined(SMP) && !defined(USE_OPENMP)
11941168
LOCK_COMMAND(&alloc_lock);
1195-
#endif
11961169

11971170
if (memory_initialized == 1) {
11981171

@@ -1201,9 +1174,8 @@ void *blas_memory_alloc(int procpos){
12011174
memory_initialized = 2;
12021175
}
12031176

1204-
#if defined(SMP) && !defined(USE_OPENMP)
12051177
UNLOCK_COMMAND(&alloc_lock);
1206-
#endif
1178+
12071179
}
12081180
#endif
12091181

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

12321204
position = 0;
1233-
#if defined(SMP) && !defined(USE_OPENMP)
12341205
LOCK_COMMAND(&alloc_lock);
1235-
#endif
1206+
12361207
while ((position < NUM_BUFFERS) && (memory[position].addr != free_area))
12371208
position++;
12381209

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

12481219
memory[position].used = 0;
1249-
#if defined(SMP) && !defined(USE_OPENMP)
12501220
UNLOCK_COMMAND(&alloc_lock);
1251-
#endif
12521221

12531222
#ifdef DEBUG
12541223
printf("Unmap Succeeded.\n\n");
@@ -1263,9 +1232,8 @@ void blas_memory_free(void *free_area){
12631232
for (position = 0; position < NUM_BUFFERS; position++)
12641233
printf("%4ld %p : %d\n", position, memory[position].addr, memory[position].used);
12651234
#endif
1266-
#if defined(SMP) && !defined(USE_OPENMP)
12671235
UNLOCK_COMMAND(&alloc_lock);
1268-
#endif
1236+
12691237
return;
12701238
}
12711239

0 commit comments

Comments
 (0)