Skip to content

Commit 12f726e

Browse files
gonnetxnnpack-bot
authored andcommitted
Use a pthreadpool_atomic_size_t instead of an fxdiv_divisor_size_t for threads_count as the former can be loaded and stored atomically.
This avoids confusing the thread sanitizer in some situations. PiperOrigin-RevId: 821114197
1 parent 75b23a5 commit 12f726e

4 files changed

Lines changed: 152 additions & 167 deletions

File tree

src/fastpath.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_1d_fastpath(
3939
(pthreadpool_task_1d_t)pthreadpool_load_relaxed_void_p(&threadpool->task);
4040
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
4141

42-
const size_t threads_count = threadpool->threads_count.value;
42+
const size_t threads_count = threadpool->threads_count;
4343
const size_t range_threshold = -threads_count;
4444

4545
/* Process thread's own range of items */
@@ -77,7 +77,7 @@ pthreadpool_thread_parallelize_1d_with_thread_fastpath(
7777
&threadpool->task);
7878
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
7979

80-
const size_t threads_count = threadpool->threads_count.value;
80+
const size_t threads_count = threadpool->threads_count;
8181
const size_t range_threshold = -threads_count;
8282

8383
/* Process thread's own range of items */
@@ -126,7 +126,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_1d_with_uarch_fastpath(
126126
}
127127
#endif
128128

129-
const size_t threads_count = threadpool->threads_count.value;
129+
const size_t threads_count = threadpool->threads_count;
130130
const size_t range_threshold = -threads_count;
131131

132132
/* Process thread's own range of items */
@@ -163,7 +163,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_1d_tile_1d_fastpath(
163163
&threadpool->task);
164164
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
165165

166-
const size_t threads_count = threadpool->threads_count.value;
166+
const size_t threads_count = threadpool->threads_count;
167167
const size_t range_threshold = -threads_count;
168168

169169
/* Process thread's own range of items */
@@ -206,7 +206,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_2d_fastpath(
206206
(pthreadpool_task_2d_t)pthreadpool_load_relaxed_void_p(&threadpool->task);
207207
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
208208

209-
const size_t threads_count = threadpool->threads_count.value;
209+
const size_t threads_count = threadpool->threads_count;
210210
const size_t range_threshold = -threads_count;
211211

212212
/* Process thread's own range of items */
@@ -258,7 +258,7 @@ pthreadpool_thread_parallelize_2d_with_thread_fastpath(
258258
&threadpool->task);
259259
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
260260

261-
const size_t threads_count = threadpool->threads_count.value;
261+
const size_t threads_count = threadpool->threads_count;
262262
const size_t range_threshold = -threads_count;
263263

264264
/* Process thread's own range of items */
@@ -309,7 +309,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_2d_tile_1d_fastpath(
309309
&threadpool->task);
310310
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
311311

312-
const size_t threads_count = threadpool->threads_count.value;
312+
const size_t threads_count = threadpool->threads_count;
313313
const size_t range_threshold = -threads_count;
314314

315315
/* Process thread's own range of items */
@@ -378,7 +378,7 @@ pthreadpool_thread_parallelize_2d_tile_1d_with_uarch_fastpath(
378378
}
379379
#endif
380380

381-
const size_t threads_count = threadpool->threads_count.value;
381+
const size_t threads_count = threadpool->threads_count;
382382
const size_t range_threshold = -threads_count;
383383

384384
/* Process thread's own range of items */
@@ -449,7 +449,7 @@ pthreadpool_thread_parallelize_2d_tile_1d_with_uarch_with_thread_fastpath(
449449
}
450450
#endif
451451

452-
const size_t threads_count = threadpool->threads_count.value;
452+
const size_t threads_count = threadpool->threads_count;
453453
const size_t range_threshold = -threads_count;
454454

455455
/* Process thread's own range of items */
@@ -508,7 +508,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_2d_tile_2d_fastpath(
508508
&threadpool->task);
509509
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
510510

511-
const size_t threads_count = threadpool->threads_count.value;
511+
const size_t threads_count = threadpool->threads_count;
512512
const size_t range_threshold = -threads_count;
513513

514514
/* Process thread's own range of items */
@@ -581,7 +581,7 @@ pthreadpool_thread_parallelize_2d_tile_2d_with_uarch_fastpath(
581581
}
582582
#endif
583583

584-
const size_t threads_count = threadpool->threads_count.value;
584+
const size_t threads_count = threadpool->threads_count;
585585
const size_t range_threshold = -threads_count;
586586

587587
/* Process thread's own range of items */
@@ -644,7 +644,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_3d_fastpath(
644644
(pthreadpool_task_3d_t)pthreadpool_load_relaxed_void_p(&threadpool->task);
645645
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
646646

647-
const size_t threads_count = threadpool->threads_count.value;
647+
const size_t threads_count = threadpool->threads_count;
648648
const size_t range_threshold = -threads_count;
649649

650650
/* Process thread's own range of items */
@@ -706,7 +706,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_3d_tile_1d_fastpath(
706706
&threadpool->task);
707707
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
708708

709-
const size_t threads_count = threadpool->threads_count.value;
709+
const size_t threads_count = threadpool->threads_count;
710710
const size_t range_threshold = -threads_count;
711711

712712
/* Process thread's own range of items */
@@ -773,7 +773,7 @@ pthreadpool_thread_parallelize_3d_tile_1d_with_thread_fastpath(
773773
pthreadpool_load_relaxed_void_p(&threadpool->task);
774774
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
775775

776-
const size_t threads_count = threadpool->threads_count.value;
776+
const size_t threads_count = threadpool->threads_count;
777777
const size_t range_threshold = -threads_count;
778778

779779
/* Process thread's own range of items */
@@ -853,7 +853,7 @@ pthreadpool_thread_parallelize_3d_tile_1d_with_uarch_fastpath(
853853
}
854854
#endif
855855

856-
const size_t threads_count = threadpool->threads_count.value;
856+
const size_t threads_count = threadpool->threads_count;
857857
const size_t range_threshold = -threads_count;
858858

859859
/* Process thread's own range of items */
@@ -934,7 +934,7 @@ pthreadpool_thread_parallelize_3d_tile_1d_with_uarch_with_thread_fastpath(
934934
}
935935
#endif
936936

937-
const size_t threads_count = threadpool->threads_count.value;
937+
const size_t threads_count = threadpool->threads_count;
938938
const size_t range_threshold = -threads_count;
939939

940940
/* Process thread's own range of items */
@@ -1003,7 +1003,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_3d_tile_2d_fastpath(
10031003
&threadpool->task);
10041004
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
10051005

1006-
const size_t threads_count = threadpool->threads_count.value;
1006+
const size_t threads_count = threadpool->threads_count;
10071007
const size_t range_threshold = -threads_count;
10081008

10091009
/* Process thread's own range of items */
@@ -1087,7 +1087,7 @@ pthreadpool_thread_parallelize_3d_tile_2d_with_uarch_fastpath(
10871087
}
10881088
#endif
10891089

1090-
const size_t threads_count = threadpool->threads_count.value;
1090+
const size_t threads_count = threadpool->threads_count;
10911091
const size_t range_threshold = -threads_count;
10921092

10931093
/* Process thread's own range of items */
@@ -1161,7 +1161,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_4d_fastpath(
11611161
(pthreadpool_task_4d_t)pthreadpool_load_relaxed_void_p(&threadpool->task);
11621162
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
11631163

1164-
const size_t threads_count = threadpool->threads_count.value;
1164+
const size_t threads_count = threadpool->threads_count;
11651165
const size_t range_threshold = -threads_count;
11661166

11671167
/* Process thread's own range of items */
@@ -1234,7 +1234,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_4d_tile_1d_fastpath(
12341234
&threadpool->task);
12351235
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
12361236

1237-
const size_t threads_count = threadpool->threads_count.value;
1237+
const size_t threads_count = threadpool->threads_count;
12381238
const size_t range_threshold = -threads_count;
12391239

12401240
/* Process thread's own range of items */
@@ -1311,7 +1311,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_4d_tile_2d_fastpath(
13111311
&threadpool->task);
13121312
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
13131313

1314-
const size_t threads_count = threadpool->threads_count.value;
1314+
const size_t threads_count = threadpool->threads_count;
13151315
const size_t range_threshold = -threads_count;
13161316

13171317
/* Process thread's own range of items */
@@ -1405,7 +1405,7 @@ pthreadpool_thread_parallelize_4d_tile_2d_with_uarch_fastpath(
14051405
}
14061406
#endif
14071407

1408-
const size_t threads_count = threadpool->threads_count.value;
1408+
const size_t threads_count = threadpool->threads_count;
14091409
const size_t range_threshold = -threads_count;
14101410

14111411
/* Process thread's own range of items */
@@ -1490,7 +1490,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_5d_fastpath(
14901490
(pthreadpool_task_5d_t)pthreadpool_load_relaxed_void_p(&threadpool->task);
14911491
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
14921492

1493-
const size_t threads_count = threadpool->threads_count.value;
1493+
const size_t threads_count = threadpool->threads_count;
14941494
const size_t range_threshold = -threads_count;
14951495

14961496
/* Process thread's own range of items */
@@ -1573,7 +1573,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_5d_tile_1d_fastpath(
15731573
&threadpool->task);
15741574
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
15751575

1576-
const size_t threads_count = threadpool->threads_count.value;
1576+
const size_t threads_count = threadpool->threads_count;
15771577
const size_t range_threshold = -threads_count;
15781578

15791579
/* Process thread's own range of items */
@@ -1661,7 +1661,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_5d_tile_2d_fastpath(
16611661
&threadpool->task);
16621662
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
16631663

1664-
const size_t threads_count = threadpool->threads_count.value;
1664+
const size_t threads_count = threadpool->threads_count;
16651665
const size_t range_threshold = -threads_count;
16661666

16671667
/* Process thread's own range of items */
@@ -1752,7 +1752,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_6d_fastpath(
17521752
(pthreadpool_task_6d_t)pthreadpool_load_relaxed_void_p(&threadpool->task);
17531753
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
17541754

1755-
const size_t threads_count = threadpool->threads_count.value;
1755+
const size_t threads_count = threadpool->threads_count;
17561756
const size_t range_threshold = -threads_count;
17571757

17581758
/* Process thread's own range of items */
@@ -1846,7 +1846,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_6d_tile_1d_fastpath(
18461846
&threadpool->task);
18471847
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
18481848

1849-
const size_t threads_count = threadpool->threads_count.value;
1849+
const size_t threads_count = threadpool->threads_count;
18501850
const size_t range_threshold = -threads_count;
18511851

18521852
/* Process thread's own range of items */
@@ -1944,7 +1944,7 @@ PTHREADPOOL_INTERNAL void pthreadpool_thread_parallelize_6d_tile_2d_fastpath(
19441944
&threadpool->task);
19451945
void* const argument = pthreadpool_load_relaxed_void_p(&threadpool->argument);
19461946

1947-
const size_t threads_count = threadpool->threads_count.value;
1947+
const size_t threads_count = threadpool->threads_count;
19481948
const size_t range_threshold = -threads_count;
19491949

19501950
/* Process thread's own range of items */

0 commit comments

Comments
 (0)