aboutsummaryrefslogtreecommitdiff
path: root/src/threading
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2022-09-02 18:19:53 +0200
committerJan200101 <sentrycraft123@gmail.com>2022-09-02 18:19:53 +0200
commit833b16d109444ed15643246f1f419d6e96f101c3 (patch)
tree6750778410ae1eb096d558bb91eecd77186e6381 /src/threading
parentc90a2c9ea1644507c0993513d1fc7925e19b4ea8 (diff)
downloadOFQT-833b16d109444ed15643246f1f419d6e96f101c3.tar.gz
OFQT-833b16d109444ed15643246f1f419d6e96f101c3.zip
stop threads when condition is reached, gracefully deal with status text
Diffstat (limited to 'src/threading')
-rw-r--r--src/threading/pool.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/threading/pool.c b/src/threading/pool.c
index 266254e..1598852 100644
--- a/src/threading/pool.c
+++ b/src/threading/pool.c
@@ -9,6 +9,7 @@
struct worker_t {
struct pool_t* pool;
int id;
+ int done;
};
struct pool_t* pool_init()
@@ -51,19 +52,17 @@ static void* task_executor(void* pinfo)
{
struct pool_task_t* pool_end = pool->tasks + pool->pool_size;
struct pool_task_t* task = pool->task_next++;
- while (pool_end > task)
+ while (pool_end > task && (pool->condition == NULL || *pool->condition))
{
if (!task->done)
{
task->func(task->arg);
task->done = 1;
}
-
task = pool->task_next++;
}
}
-
- return NULL;
+ worker->done = 1;
}
void pool_complete(struct pool_t* pool)
@@ -81,13 +80,15 @@ void pool_complete(struct pool_t* pool)
worker->pool = pool;
worker->id = i;
+ worker->done = 0;
pthread_create(thread, NULL, task_executor, worker);
}
for (int i = 0; i < pool->workers; ++i)
{
- pthread_join(threads[i], NULL);
+ if (!workers[i].done)
+ pthread_join(threads[i], NULL);
}
free(threads);