Commit 0ce0d523 authored by Tommy Olofsson's avatar Tommy Olofsson
Browse files

Event queue got killed before all events had the chance to gen executed.

parent c1d7038e
......@@ -100,7 +100,8 @@ struct firefly_transport_llp *firefly_transport_llp_udp_posix_new(
char err_buf[ERROR_STR_MAX_LEN];
#ifdef LABCOMM_COMPAT
err_buf[0] = '\0';
strerror_r(errno, err_buf); /* GERONIMO! */
err_buf[ERROR_STR_MAX_LEN-1] = '\0';
#else
strerror_r(errno, err_buf, sizeof(err_buf));
#endif
......@@ -142,14 +143,18 @@ void firefly_transport_llp_udp_posix_free(struct firefly_transport_llp *llp)
static void check_llp_free(struct firefly_transport_llp *llp)
{
struct transport_llp_udp_posix *llp_udp;
if (llp->state == FIREFLY_LLP_CLOSING && llp->conn_list == NULL) {
struct transport_llp_udp_posix *llp_udp;
llp_udp = llp->llp_platspec;
close(llp_udp->local_udp_socket);
printf("socket CLOSED\n");
free(llp_udp->local_addr);
firefly_resend_queue_free(llp_udp->resend_queue);
free(llp_udp);
free(llp);
} else {
printf("Failed to close llp properly!");
}
}
......@@ -167,6 +172,7 @@ int firefly_transport_llp_udp_posix_free_event(void *event_arg)
head = head->next;
}
check_llp_free(llp);
return 0;
}
......
......@@ -8,7 +8,8 @@
struct firefly_event_queue_vx_context {
SEM_ID lock;
SEM_ID signal;
SEM_ID signal; /* New items in queue. */
SEM_ID dead;
int tid_event_loop;
bool event_loop_stop;
};
......@@ -44,6 +45,11 @@ struct firefly_event_queue *firefly_event_queue_vx_new(size_t pool_size)
printf("fail to create csem.\n");
goto fail;
}
ctx->dead = semBCreate(SEM_Q_FIFO, SEM_EMPTY);
if (!ctx->dead) {
printf("fail to create bsem.\n");
goto fail;
}
ctx->event_loop_stop = 0;
eq = firefly_event_queue_new(firefly_event_queue_vx_add, pool_size, ctx);
if (!eq)
......@@ -56,6 +62,8 @@ struct firefly_event_queue *firefly_event_queue_vx_new(size_t pool_size)
semDelete(ctx->lock);
if (ctx->signal)
semDelete(ctx->signal);
if (ctx->dead)
semDelete(ctx->dead);
free(ctx);
if (eq)
firefly_event_queue_vx_free(&eq);
......@@ -109,11 +117,14 @@ void *firefly_event_vx_thread_main(void *args)
semGive(ctx->lock);
while (!finish || event_left > 0) {
/* TODO: Clean up. Posix version was weird. */
semTake(ctx->lock, WAIT_FOREVER);
event_left = firefly_event_queue_length(eq);
finish = ctx->event_loop_stop;
while (event_left <= 0 && !finish) {
semGive(ctx->lock);
semTake(ctx->signal, WAIT_FOREVER);
semTake(ctx->lock, WAIT_FOREVER);
finish = ctx->event_loop_stop;
event_left = firefly_event_queue_length(eq);
}
......@@ -130,6 +141,10 @@ void *firefly_event_vx_thread_main(void *args)
}
}
/* semTake(ctx->lock, WAIT_FOREVER); */
semGive(ctx->dead);
/* semGive(ctx->lock); */
return NULL;
}
......@@ -160,8 +175,11 @@ int firefly_event_queue_vx_stop(struct firefly_event_queue *eq)
semTake(ctx->lock, WAIT_FOREVER);
ctx->event_loop_stop = true;
semGive(ctx->lock);
semGive(ctx->signal);
semGive(ctx->signal); /* Signal ev. task to die. */
printf("eq not done yet...\n");
semTake(ctx->dead, WAIT_FOREVER);
printf("eq done!\n");
ret = taskDelete(ctx->tid_event_loop);
if (ret == ERROR) {
printf("Failed to delete eq task.\n");
......
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