Commit b1aa697a authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

make the logging work even if we're using a single thread.

parent 03735423
......@@ -195,6 +195,19 @@ void threadpool_init(struct threadpool *tp, int num_threads) {
tp->num_threads = num_threads;
tp->num_threads_waiting = 0;
#ifdef SWIFT_DEBUG_THREADPOOL
if ((tp->logs = (struct mapper_log *)malloc(sizeof(struct mapper_log) *
num_threads)) == NULL)
error("Failed to allocate mapper logs.");
for (int k = 0; k < num_threads; k++) {
tp->logs[k].size = threadpool_log_initial_size;
tp->logs[k].count = 0;
if ((tp->logs[k].log = (struct mapper_log_entry *)malloc(
sizeof(struct mapper_log_entry) * tp->logs[k].size)) == NULL)
error("Failed to allocate mapper log.");
}
#endif
/* If there is only a single thread, do nothing more as of here as
we will just do work in the (blocked) calling thread. */
if (num_threads == 1) return;
......@@ -213,19 +226,6 @@ void threadpool_init(struct threadpool *tp, int num_threads) {
tp->map_data_chunk = 0;
tp->map_function = NULL;
#ifdef SWIFT_DEBUG_THREADPOOL
if ((tp->logs = (struct mapper_log *)malloc(sizeof(struct mapper_log) *
num_threads)) == NULL)
error("Failed to allocate mapper logs.");
for (int k = 0; k < num_threads; k++) {
tp->logs[k].size = threadpool_log_initial_size;
tp->logs[k].count = 0;
if ((tp->logs[k].log = (struct mapper_log_entry *)malloc(
sizeof(struct mapper_log_entry) * tp->logs[k].size)) == NULL)
error("Failed to allocate mapper log.");
}
#endif
/* Allocate the threads. */
if ((tp->threads = (pthread_t *)malloc(sizeof(pthread_t) * num_threads)) ==
NULL) {
......@@ -268,7 +268,13 @@ void threadpool_map(struct threadpool *tp, threadpool_map_function map_function,
/* If we just have a single thread, call the map function directly. */
if (tp->num_threads == 1) {
#ifdef SWIFT_DEBUG_THREADPOOL
ticks tic = getticks();
#endif
map_function(map_data, N, extra_data);
#ifdef SWIFT_DEBUG_THREADPOOL
threadpool_log(tp, 0, N, tic, getticks());
#endif
return;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment