Skip to content
Snippets Groups Projects
Unverified Commit 9d7b9651 authored by Matei-Cristian MANTU's avatar Matei-Cristian MANTU
Browse files

Refactored process_neighbours, looks better now

parent fde6d59d
No related branches found
No related tags found
No related merge requests found
Pipeline #41632 passed
...@@ -14,8 +14,6 @@ r ...@@ -14,8 +14,6 @@ r
r r
r r
r r
r
r
b main b main
r r
n n
...@@ -254,3 +252,5 @@ r ...@@ -254,3 +252,5 @@ r
r r
r r
r r
r
r
...@@ -71,7 +71,7 @@ os_task_t *dequeue_task(os_threadpool_t *tp) ...@@ -71,7 +71,7 @@ os_task_t *dequeue_task(os_threadpool_t *tp)
os_task_t *t; os_task_t *t;
pthread_mutex_lock(&tp->queue_lock); pthread_mutex_lock(&tp->queue_lock);
if (queue_is_empty(tp) && tp->active > 0) while (queue_is_empty(tp) && tp->active > 0)
pthread_cond_wait(&tp->active_cond, &tp->queue_lock); pthread_cond_wait(&tp->active_cond, &tp->queue_lock);
if (!queue_is_empty(tp)) { if (!queue_is_empty(tp)) {
t = list_entry(tp->head.next, os_task_t, list); t = list_entry(tp->head.next, os_task_t, list);
...@@ -89,7 +89,7 @@ static void *thread_loop_function(void *arg) ...@@ -89,7 +89,7 @@ static void *thread_loop_function(void *arg)
os_threadpool_t *tp = (os_threadpool_t *) arg; os_threadpool_t *tp = (os_threadpool_t *) arg;
pthread_mutex_lock(&main_mutex); pthread_mutex_lock(&main_mutex);
if (!main_done) while (!main_done)
pthread_cond_wait(&main_cond, &main_mutex); pthread_cond_wait(&main_cond, &main_mutex);
pthread_mutex_unlock(&main_mutex); pthread_mutex_unlock(&main_mutex);
while (1) { while (1) {
......
...@@ -25,8 +25,10 @@ void os_destroy_arg(void *arg) ...@@ -25,8 +25,10 @@ void os_destroy_arg(void *arg)
free(arg); free(arg);
} }
static void process_node(unsigned int idx);
/* Define graph task argument. */ /* Define graph task argument. */
void process_neighbours(void *arg) static void process_neighbours(void *arg)
{ {
unsigned int idx = *(unsigned int *)arg; unsigned int idx = *(unsigned int *)arg;
os_node_t *node = graph->nodes[idx]; os_node_t *node = graph->nodes[idx];
...@@ -36,17 +38,9 @@ void process_neighbours(void *arg) ...@@ -36,17 +38,9 @@ void process_neighbours(void *arg)
pthread_mutex_unlock(&sum_lock); pthread_mutex_unlock(&sum_lock);
pthread_mutex_lock(&graph_lock); pthread_mutex_lock(&graph_lock);
for (unsigned int i = 0; i < node->num_neighbours; ++i) { for (unsigned int i = 0; i < node->num_neighbours; ++i)
if (graph->visited[node->neighbours[i]] == NOT_VISITED) { if (graph->visited[node->neighbours[i]] == NOT_VISITED)
graph->visited[node->neighbours[i]] = DONE; process_node(node->neighbours[i]);
unsigned int *new_arg = malloc(sizeof(unsigned int));
*new_arg = node->neighbours[i];
os_task_t *new_task = create_task(process_neighbours, (void *)new_arg, os_destroy_arg);
enqueue_task(tp, new_task);
}
}
pthread_mutex_unlock(&graph_lock); pthread_mutex_unlock(&graph_lock);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment