aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarat Dukhan <maratek@google.com>2020-03-23 00:59:45 -0700
committerMarat Dukhan <maratek@google.com>2020-03-23 00:59:45 -0700
commit2bde094c58c0fcde46b537b538f8bbaef7ef9b16 (patch)
treeb0d28f69a03b39462e68300897e07917293983b6 /src
parent39e0461712bc666abd5f82f22cab46f0dcb502e7 (diff)
downloadpthreadpool-2bde094c58c0fcde46b537b538f8bbaef7ef9b16.tar.gz
Avoid spinning thread-pool when task has the only item
Diffstat (limited to 'src')
-rw-r--r--src/threadpool-pthreads.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/threadpool-pthreads.c b/src/threadpool-pthreads.c
index ddc67bd..fd67f2f 100644
--- a/src/threadpool-pthreads.c
+++ b/src/threadpool-pthreads.c
@@ -495,7 +495,7 @@ void pthreadpool_parallelize_1d(
size_t range,
uint32_t flags)
{
- if (threadpool == NULL || threadpool->threads_count <= 1) {
+ if (threadpool == NULL || threadpool->threads_count <= 1 || range <= 1) {
/* No thread pool used: execute task sequentially on the calling thread */
struct fpu_state saved_fpu_state = { 0 };
if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
@@ -620,7 +620,7 @@ void pthreadpool_parallelize_1d_tile_1d(
size_t tile,
uint32_t flags)
{
- if (threadpool == NULL || threadpool->threads_count <= 1) {
+ if (threadpool == NULL || threadpool->threads_count <= 1 || range <= tile) {
/* No thread pool used: execute task sequentially on the calling thread */
struct fpu_state saved_fpu_state = { 0 };
if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
@@ -666,7 +666,7 @@ void pthreadpool_parallelize_2d(
size_t range_j,
uint32_t flags)
{
- if (threadpool == NULL || threadpool->threads_count <= 1) {
+ if (threadpool == NULL || threadpool->threads_count <= 1 || (range_i | range_j) <= 1) {
/* No thread pool used: execute task sequentially on the calling thread */
struct fpu_state saved_fpu_state = { 0 };
if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
@@ -720,7 +720,7 @@ void pthreadpool_parallelize_2d_tile_1d(
size_t tile_j,
uint32_t flags)
{
- if (threadpool == NULL || threadpool->threads_count <= 1) {
+ if (threadpool == NULL || threadpool->threads_count <= 1 || (range_i <= 1 && range_j <= tile_j)) {
/* No thread pool used: execute task sequentially on the calling thread */
struct fpu_state saved_fpu_state = { 0 };
if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
@@ -782,7 +782,7 @@ void pthreadpool_parallelize_2d_tile_2d(
size_t tile_j,
uint32_t flags)
{
- if (threadpool == NULL || threadpool->threads_count <= 1) {
+ if (threadpool == NULL || threadpool->threads_count <= 1 || (range_i <= tile_i && range_j <= tile_j)) {
/* No thread pool used: execute task sequentially on the calling thread */
struct fpu_state saved_fpu_state = { 0 };
if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
@@ -851,7 +851,7 @@ void pthreadpool_parallelize_3d_tile_2d(
size_t tile_k,
uint32_t flags)
{
- if (threadpool == NULL || threadpool->threads_count <= 1) {
+ if (threadpool == NULL || threadpool->threads_count <= 1 || (range_i <= 1 && range_j <= tile_j && range_k <= tile_k)) {
/* No thread pool used: execute task sequentially on the calling thread */
struct fpu_state saved_fpu_state = { 0 };
if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
@@ -930,7 +930,7 @@ void pthreadpool_parallelize_4d_tile_2d(
size_t tile_l,
uint32_t flags)
{
- if (threadpool == NULL || threadpool->threads_count <= 1) {
+ if (threadpool == NULL || threadpool->threads_count <= 1 || ((range_i | range_j) <= 1 && range_k <= tile_k && range_l <= tile_l)) {
/* No thread pool used: execute task sequentially on the calling thread */
struct fpu_state saved_fpu_state = { 0 };
if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
@@ -1019,7 +1019,7 @@ void pthreadpool_parallelize_5d_tile_2d(
size_t tile_m,
uint32_t flags)
{
- if (threadpool == NULL || threadpool->threads_count <= 1) {
+ if (threadpool == NULL || threadpool->threads_count <= 1 || ((range_i | range_j | range_k) <= 1 && range_l <= tile_l && range_m <= tile_m)) {
/* No thread pool used: execute task sequentially on the calling thread */
struct fpu_state saved_fpu_state = { 0 };
if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {
@@ -1116,7 +1116,7 @@ void pthreadpool_parallelize_6d_tile_2d(
size_t tile_n,
uint32_t flags)
{
- if (threadpool == NULL || threadpool->threads_count <= 1) {
+ if (threadpool == NULL || threadpool->threads_count <= 1 || ((range_i | range_j | range_k | range_l) <= 1 && range_m <= tile_m && range_n <= tile_n)) {
/* No thread pool used: execute task sequentially on the calling thread */
struct fpu_state saved_fpu_state = { 0 };
if (flags & PTHREADPOOL_FLAG_DISABLE_DENORMALS) {