Commit 85ce6d8a authored by Tommy Olofsson's avatar Tommy Olofsson
Browse files

Cleaned up the VxWorks code a bit after debugging.

parent 657fa256
......@@ -61,7 +61,12 @@ link_directories(${LINK_DIRECTORIES} ${LABCOMM_LIBRARIES})
## FLAGS {{{
set(C_STD "-std=c99")
set(ERR_FLAGS "-Wall -Wextra")
set(MACROS_DEF "-DDEBUG")
if(DEFINED $ENV{DEBUG})
set(MACROS_DEF "-DDEBUG -O0")
else()
set(MACROS_DEF "-DNDEBUG -O3")
endif()
if(CMAKE_CROSSCOMPILING)
if (VXWORKS_COMPILING)
......
......@@ -204,17 +204,13 @@ void protocol_data_received(struct firefly_connection *conn,
unsigned char *data, size_t size)
{
if (conn->open == FIREFLY_CONNECTION_OPEN) {
/* printf("Setting dec buf\n"); */
labcomm_decoder_ioctl(conn->transport_decoder,
FIREFLY_LABCOMM_IOCTL_READER_SET_BUFFER,
data, size);
int res = 0;
while (res >= 0) {
while (res >= 0)
res = labcomm_decoder_decode_one(conn->transport_decoder);
/* printf("do(): %d\n", res); */
}
} else
printf("FAIL IN %s\n", __func__);
}
}
void handle_channel_request(firefly_protocol_channel_request *chan_req,
......@@ -226,7 +222,6 @@ void handle_channel_request(firefly_protocol_channel_request *chan_req,
conn = context;
/* printf("%s\n", __func__); */
fecrr = FIREFLY_MALLOC(sizeof(*fecrr));
if (fecrr == NULL) {
firefly_error(FIREFLY_ERROR_ALLOC, 1,
......@@ -307,7 +302,6 @@ void handle_channel_response(firefly_protocol_channel_response *chan_res,
conn = context;
/* printf("%s", __func__); */
fecrr = FIREFLY_MALLOC(sizeof(*fecrr));
if (fecrr == NULL) {
firefly_error(FIREFLY_ERROR_ALLOC, 1,
......@@ -334,7 +328,6 @@ static void firefly_channel_send_channel_ack(
{
firefly_protocol_channel_ack ack;
/* printf("%s", __func__); */
if (chan != NULL) {
ack.ack = true;
ack.source_chan_id = chan->local_id;
......@@ -386,7 +379,6 @@ void handle_channel_ack(firefly_protocol_channel_ack *chan_ack, void *context)
struct firefly_event_chan_ack_recv *fecar;
int ret;
/* printf("%s\n", __func__); */
conn = context;
fecar = FIREFLY_MALLOC(sizeof(*fecar));
if (fecar == NULL) {
......@@ -433,7 +425,6 @@ void handle_channel_close(firefly_protocol_channel_close *chan_close,
struct firefly_connection *conn;
struct firefly_channel *chan;
/* printf("%s\n", __func__); */
conn = context;
chan = find_channel_by_local_id(conn, chan_close->dest_chan_id);
if (chan != NULL){
......@@ -453,7 +444,6 @@ void handle_data_sample(firefly_protocol_data_sample *data, void *context)
unsigned char *fers_data;
int ret;
/* printf("%s", __func__); */
conn = context;
fers = FIREFLY_RUNTIME_MALLOC(conn, sizeof(*fers));
fers_data = FIREFLY_RUNTIME_MALLOC(conn, data->app_enc_data.n_0);
......@@ -536,7 +526,6 @@ void handle_ack(firefly_protocol_ack *ack, void *context)
struct firefly_connection *conn;
struct firefly_channel *chan;
/* printf("%s\n", __func__); */
conn = context;
chan = find_channel_by_local_id(conn, ack->dest_chan_id);
if (chan == NULL) {
......@@ -625,7 +614,6 @@ void handle_channel_restrict_request(
struct firefly_event_channel_restrict_request *earg;
int ret;
/* printf("%s\n", __func__); */
conn = context;
earg = FIREFLY_MALLOC(sizeof(*earg));
if (!earg) {
......@@ -706,7 +694,6 @@ void handle_channel_restrict_ack(firefly_protocol_channel_restrict_ack *data,
conn = context;
/* printf("%s\n", __func__); */
earg = FIREFLY_MALLOC(sizeof(*earg));
if (!earg) {
firefly_error(FIREFLY_ERROR_ALLOC, 1,
......
......@@ -63,12 +63,7 @@ static int proto_reader_fill(struct labcomm_reader *r,
UNUSED_VAR(context);
result = r->count - r->pos;
r->error = (result <= 0 || r->data == NULL) ? -1 : 0;
#if 1
if (result <= 0)
printf("cnt:%d pos:%d\n", r->count, r->pos);
if (!r->data)
printf("no data\n");
#endif
return result;
}
......
......@@ -148,7 +148,6 @@ static void check_llp_free(struct firefly_transport_llp *llp)
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);
......@@ -260,11 +259,9 @@ void firefly_transport_udp_posix_write(unsigned char *data, size_t data_size,
int res;
conn_udp = conn->transport->context;
/* printf("sending\n"); */
res = sendto(conn_udp->socket, (void *) data, data_size, 0,
(struct sockaddr *) conn_udp->remote_addr,
sizeof(*conn_udp->remote_addr));
/* printf("sent\n"); */
if (res == -1) {
firefly_error(FIREFLY_ERROR_TRANS_WRITE, 1, "sendto() failed");
firefly_connection_raise_later(conn,
......@@ -296,7 +293,6 @@ void *firefly_transport_udp_posix_read_run(void *args)
{
struct firefly_transport_llp *llp;
printf("Reader task started\n");
llp = args;
while (true)
firefly_transport_udp_posix_read(llp);
......@@ -337,16 +333,14 @@ int firefly_transport_udp_posix_run(struct firefly_transport_llp *llp)
pthread_cancel(llp_udp->read_thread);
goto fail;
#else
printf("Spawning reader thread\n");
res = taskSpawn("ff_read_thread", 254, 0, 20000,
res = taskSpawn("ff_read_task", 254, 0, 20000,
(FUNCPTR)firefly_transport_udp_posix_read_run,
(int) llp,
0, 0, 0, 0, 0, 0, 0, 0, 0); /* TODO: arg */
if (res == ERROR)
goto fail;
llp_udp->tid_read = res;
printf("Spawning resend thread\n");
res = taskSpawn("ff_resend_thread", 254, 0, 20000,
res = taskSpawn("ff_resend_task", 254, 0, 20000,
(FUNCPTR)firefly_resend_run,
(int) largs,
0, 0, 0, 0, 0, 0, 0, 0, 0); /* TODO: arg */
......@@ -394,14 +388,12 @@ static int firefly_transport_udp_posix_read_event(void *event_arg)
struct transport_llp_udp_posix *llp_udp;
struct firefly_connection *conn;
/* printf("%s\n", __func__); */
ev_arg = event_arg;
llp_udp = ev_arg->llp->llp_platspec;
// Find existing connection or create new.
conn = find_connection(ev_arg->llp, &ev_arg->addr, connection_eq_inaddr);
if (conn == NULL) {
puts("re: new conn");
char ip_addr[INET_ADDRSTRLEN];
sockaddr_in_ipaddr(&ev_arg->addr, ip_addr);
int64_t ev_id = 0;
......@@ -414,7 +406,6 @@ static int firefly_transport_udp_posix_read_event(void *event_arg)
firefly_transport_udp_posix_read_event,
ev_arg, 1, &ev_id);
} else {
puts("no cb");
free(ev_arg->data);
}
} else {
......@@ -439,9 +430,7 @@ void firefly_transport_udp_posix_read(struct firefly_transport_llp *llp)
do {
FD_ZERO(&fs);
FD_SET(llp_udp->local_udp_socket, &fs);
/* printf("select\n"); */
res = select(llp_udp->local_udp_socket + 1, &fs, NULL, NULL, NULL);
/* printf("select ret %d\n", res); */
} while (res == -1 && errno == EINTR);
if (res == -1) {
if (errno == ENOMEM) {
......@@ -479,10 +468,8 @@ void firefly_transport_udp_posix_read(struct firefly_transport_llp *llp)
return;
}
len = sizeof(remote_addr);
/* printf("receiving %d. ", pkg_len); */
res = recvfrom(llp_udp->local_udp_socket, (void *) ev_arg->data, pkg_len, 0,
(struct sockaddr *) &remote_addr, (void *) &len);
/* printf("received %d\n", res); */
if (res == -1) {
char err_buf[ERROR_STR_MAX_LEN];
#ifdef LABCOMM_COMPAT
......@@ -502,7 +489,6 @@ void firefly_transport_udp_posix_read(struct firefly_transport_llp *llp)
FIREFLY_PRIORITY_HIGH,
firefly_transport_udp_posix_read_event,
ev_arg, 0, NULL);
/* printf("put read ev\n"); */
}
bool sockaddr_in_eq(struct sockaddr_in *one, struct sockaddr_in *other)
......
......@@ -12,4 +12,11 @@
#define UNUSED_VAR(x) ((void)(x)) /* Supress unsued variable compiler
warings. */
/* Debug prints on stdout (VxWorks does not have stderr). */
#ifdef DEBUG
#define TRACE(...) do { printf(__VA_ARGS__); } while (0)
#else
#define TRACE(...) do { } while (0)
#endif
#endif
......@@ -6,6 +6,7 @@
#include <utils/firefly_event_queue_vx.h>
#include <utils/firefly_event_queue.h>
#include <utils/firefly_event_queue_private.h>
#include <utils/cppmacros.h>
struct firefly_event_queue_vx_context {
SEM_ID lock;
......@@ -27,28 +28,28 @@ struct firefly_event_queue *firefly_event_queue_vx_new(size_t pool_size)
if ((ctx = calloc(1, sizeof(*ctx)))) {
ctx->lock = semMCreate(SEM_INVERSION_SAFE | SEM_Q_PRIORITY);
if (!ctx->lock) {
printf("fail to create msem: ");
TRACE("fail to create msem: ");
switch (errno) {
case S_semLib_INVALID_OPTION:
printf("invalid option");
TRACE("invalid option");
break;
case S_memLib_NOT_ENOUGH_MEMORY:
printf("no mem");
TRACE("no mem");
break;
default:
printf("other");
TRACE("other");
}
printf("\n");
TRACE("\n");
goto fail;
}
ctx->signal = semCCreate(0, 0);
if (!ctx->signal) {
printf("fail to create csem.\n");
TRACE("fail to create csem.\n");
goto fail;
}
ctx->dead = semBCreate(SEM_Q_FIFO, SEM_EMPTY);
if (!ctx->dead) {
printf("fail to create bsem.\n");
TRACE("fail to create bsem.\n");
goto fail;
}
ctx->event_loop_stop = 0;
......@@ -132,22 +133,17 @@ void *firefly_event_vx_thread_main(void *args)
ev = firefly_event_pop(eq);
semGive(ctx->lock);
if (ev) {
/* TODO: Retval can indicate badly contructed event, or
/* TODO: Retval can indicate badly contructed event, or
* failed execution. Should this be handled?
*/
/* printf("exec ev: %p\n", ev->execute); */
firefly_event_execute(ev);
/* printf("done exec ev\n"); */
semTake(ctx->lock, WAIT_FOREVER);
firefly_event_return(eq, &ev);
semGive(ctx->lock);
}
}
/* semTake(ctx->lock, WAIT_FOREVER); */
semGive(ctx->dead);
/* semGive(ctx->lock); */
printf("EVENT THREAD TERMINATING\n");
TRACE("EVENT THREAD TERMINATING\n");
return NULL;
}
......@@ -181,12 +177,12 @@ int firefly_event_queue_vx_stop(struct firefly_event_queue *eq)
semGive(ctx->lock);
semGive(ctx->signal); /* Signal ev. task to die. */
printf("eq not done yet...\n");
TRACE("eq not done yet...\n");
semTake(ctx->dead, WAIT_FOREVER);
printf("eq done!\n");
TRACE("eq done!\n");
ret = taskDelete(ctx->tid_event_loop);
if (ret == ERROR) {
printf("Failed to delete eq task.\n");
TRACE("Failed to delete eq task.\n");
return -1;
}
......
......@@ -69,7 +69,7 @@ unsigned char firefly_resend_add(struct resend_queue *rq,
if (!re)
return 0;
re->data = data;
re->data = (char *) data;
re->size = size;
clock_gettime(CLOCK_REALTIME, &re->resend_at);
timespec_add_ms(&re->resend_at, timeout_ms);
......@@ -249,19 +249,6 @@ int firefly_resend_wait(struct resend_queue *rq,
return result;
}
static void firefly_resend_cleanup(void *arg)
{
struct firefly_resend_loop_args *largs;
struct resend_queue *rq;
largs = arg;
rq = largs->rq;
/* TODO: Fix */
/* pthread_mutex_unlock(&rq->lock); */
free(arg);
}
void *firefly_resend_run(void *args)
{
struct firefly_resend_loop_args *largs;
......@@ -273,31 +260,22 @@ void *firefly_resend_run(void *args)
int res;
largs = args;
/* pthread_cleanup_push(firefly_resend_cleanup, args); */
rq = largs->rq;
for (;;) {
/* int prev_state; */
res = firefly_resend_wait(rq, &data, &size, &conn, &id);
/* pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &prev_state); */
taskSafe();
if (res < 0) {
if (largs->on_no_ack)
largs->on_no_ack(conn);
} else {
conn->transport->write(data, size, conn,
false, NULL);
conn->transport->write(data, size, conn, false, NULL);
free(data);
firefly_resend_readd(rq, id);
}
/* pthread_setcancelstate(prev_state, NULL); */
taskUnsafe();
}
/* pthread_cleanup_pop(1); */
firefly_resend_cleanup(args);
return NULL;
}
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