Skip to content

Commit 4343fd8

Browse files
Fix issues found when building libproc on mission server (#33)
* Fix issues found when building libproc on mission server * Fix multiple definition error Co-authored-by: johnbellardo <[email protected]>
1 parent 7de7db2 commit 4343fd8

10 files changed

+497
-111
lines changed

cmd.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,16 @@ struct CMD_XDRCommandInfo {
135135
void *arg;
136136
};
137137

138+
#ifndef XDR_PRINT_STYLE_ENUM
139+
#define XDR_PRINT_STYLE_ENUM
138140
#ifdef __cplusplus
139-
enum XDR_PRINT_STYLE : short;
141+
enum XDR_PRINT_STYLE : short { XDR_PRINT_HUMAN, XDR_PRINT_KVP, XDR_PRINT_CSV_HEADER,
142+
XDR_PRINT_CSV_DATA };
143+
140144
#else
141-
enum XDR_PRINT_STYLE;
145+
enum XDR_PRINT_STYLE { XDR_PRINT_HUMAN, XDR_PRINT_KVP, XDR_PRINT_CSV_HEADER,
146+
XDR_PRINT_CSV_DATA };
147+
#endif
142148
#endif
143149

144150
extern void CMD_register_commands(struct CMD_XDRCommandInfo*, int);

events.c

+27-27
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ typedef struct _ScheduleCB
5858
void *arg;
5959
size_t pos;
6060
struct timeval timeStep;
61-
pqueue_t *queue;
61+
ps_pqueue_t *queue;
6262
uint32_t count;
6363
char breakpoint;
6464
char name[128];
@@ -108,7 +108,7 @@ struct EventState
108108
int hashSize; // The hash size of the event handler
109109
int keepGoing; // Whether the handler should loop or not
110110
struct GPIOInterruptDesc gpio_intrs[2]; // GPIO interrupt state
111-
pqueue_t *queue, *dbg_queue; // The schedule queue
111+
ps_pqueue_t *queue, *dbg_queue; // The schedule queue
112112
struct EventTimer *evt_timer;
113113
char custom_timer;
114114
enum EVTDebuggerState initialDebuggerState;
@@ -300,14 +300,14 @@ struct EventState *EVT_initWithSize(int hashSize, EVT_debug_state_cb debug_cb,
300300
for (i = 0; i < res->hashSize; i++)
301301
res->events[i] = NULL;
302302

303-
res->queue = pqueue_init(hashSize, cmp_pri, get_pri, set_pri,
303+
res->queue = ps_pqueue_init(hashSize, cmp_pri, get_pri, set_pri,
304304
get_pos, set_pos);
305305
if (res->queue == NULL){
306306
free(res);
307307
return NULL;
308308
}
309309

310-
res->dbg_queue = pqueue_init(hashSize, cmp_pri, get_pri, set_pri,
310+
res->dbg_queue = ps_pqueue_init(hashSize, cmp_pri, get_pri, set_pri,
311311
get_pos, set_pos);
312312
if (res->dbg_queue == NULL){
313313
free(res->queue);
@@ -442,22 +442,22 @@ void EVT_free_handler(EVTHandler *ctx)
442442
}
443443
}
444444

445-
while ((curProc = pqueue_peek(ctx->queue))) {
446-
pqueue_pop(ctx->queue);
445+
while ((curProc = ps_pqueue_peek(ctx->queue))) {
446+
ps_pqueue_pop(ctx->queue);
447447
// Call the callback and see if it wants to be kept
448448
if (curProc != &ctx->null_evt)
449449
free(curProc);
450450
}
451451

452-
while ((curProc = pqueue_peek(ctx->dbg_queue))) {
453-
pqueue_pop(ctx->dbg_queue);
452+
while ((curProc = ps_pqueue_peek(ctx->dbg_queue))) {
453+
ps_pqueue_pop(ctx->dbg_queue);
454454
// Call the callback and see if it wants to be kept
455455
if (curProc != &ctx->null_evt)
456456
free(curProc);
457457
}
458458

459-
pqueue_free(ctx->queue);
460-
pqueue_free(ctx->dbg_queue);
459+
ps_pqueue_free(ctx->queue);
460+
ps_pqueue_free(ctx->dbg_queue);
461461
free(ctx);
462462
}
463463

@@ -695,7 +695,7 @@ static int evt_process_timed_event(EVTHandler *ctx,
695695
curProc->scheduleTime = curTime;
696696
timeradd(&curProc->nextAwake,
697697
&curProc->timeStep, &curProc->nextAwake);
698-
pqueue_insert(curProc->queue, curProc);
698+
ps_pqueue_insert(curProc->queue, curProc);
699699
} else {
700700
if (curProc != &ctx->null_evt) {
701701
free(curProc);
@@ -821,13 +821,13 @@ char EVT_start_loop(EVTHandler *ctx)
821821
args.maxFd = ctx->maxFd + 1;
822822
args.mono_to = NULL;
823823

824-
curProc = pqueue_peek(ctx->queue);
824+
curProc = ps_pqueue_peek(ctx->queue);
825825
if (!time_paused && curProc)
826826
nextAwake = &curProc->nextAwake;
827827
else
828828
nextAwake = NULL;
829829

830-
curProc = pqueue_peek(ctx->dbg_queue);
830+
curProc = ps_pqueue_peek(ctx->dbg_queue);
831831
if (curProc)
832832
args.mono_to = &curProc->nextAwake;
833833

@@ -836,29 +836,29 @@ char EVT_start_loop(EVTHandler *ctx)
836836
&select_event_loop_cb, &args);
837837

838838
// Process Timed Events
839-
while (!time_paused && (curProc = pqueue_peek(ctx->queue))) {
839+
while (!time_paused && (curProc = ps_pqueue_peek(ctx->queue))) {
840840
ctx->evt_timer->get_monotonic_time(ctx->evt_timer, &curTime);
841841

842842
if (timercmp(&curProc->nextAwake, &curTime, >)) {
843843
// Event is not yet ready
844844
break;
845845
}
846-
pqueue_pop(ctx->queue);
846+
ps_pqueue_pop(ctx->queue);
847847
curProc->pos = SIZE_MAX;
848848
if (!evt_process_timed_event(ctx, curProc, curTime, 0))
849849
goto next_loop_iteration;
850850
real_event = 1;
851851
}
852852

853-
while ((curProc = pqueue_peek(ctx->dbg_queue))) {
853+
while ((curProc = ps_pqueue_peek(ctx->dbg_queue))) {
854854
ET_default_monotonic(NULL, &curTime);
855855

856856
if (timercmp(&curProc->nextAwake, &curTime, >)) {
857857
// Event is not yet ready
858858
break;
859859
}
860860
curProc->pos = SIZE_MAX;
861-
pqueue_pop(ctx->dbg_queue);
861+
ps_pqueue_pop(ctx->dbg_queue);
862862
evt_process_timed_event(ctx, curProc, curTime, 1);
863863
}
864864

@@ -952,7 +952,7 @@ void *EVT_sched_add(EVTHandler *handler, struct timeval time,
952952
newSchedCB->breakpoint = 0;
953953
newSchedCB->count = 0;
954954

955-
if (0 == pqueue_insert(newSchedCB->queue, newSchedCB)){
955+
if (0 == ps_pqueue_insert(newSchedCB->queue, newSchedCB)){
956956
return newSchedCB;
957957
}
958958

@@ -990,7 +990,7 @@ void *EVT_sched_add_with_timestep(EVTHandler *handler, struct timeval time,
990990
newSchedCB->name[0] = 0;
991991
newSchedCB->breakpoint = 0;
992992

993-
if (0 == pqueue_insert(newSchedCB->queue, newSchedCB)){
993+
if (0 == ps_pqueue_insert(newSchedCB->queue, newSchedCB)){
994994
return newSchedCB;
995995
}
996996

@@ -1021,7 +1021,7 @@ void *EVT_sched_remove(EVTHandler *handler, void *eventId)
10211021
if (evt != &handler->null_evt)
10221022
free(evt);
10231023
}
1024-
else if (0 == pqueue_remove(evt->queue, eventId)) {
1024+
else if (0 == ps_pqueue_remove(evt->queue, eventId)) {
10251025
evt->pos = SIZE_MAX;
10261026
result = evt->arg;
10271027
if (evt != &handler->null_evt)
@@ -1057,7 +1057,7 @@ char EVT_sched_update(EVTHandler *handler, void *eventId, struct timeval time)
10571057

10581058
timeradd(&evt->scheduleTime, &time, &evt->nextAwake);
10591059
evt->timeStep = time;
1060-
pqueue_change_priority(evt->queue, evt->nextAwake, evt);
1060+
ps_pqueue_change_priority(evt->queue, evt->nextAwake, evt);
10611061

10621062
return 0;
10631063
}
@@ -1080,11 +1080,11 @@ char EVT_sched_move_to_mono(EVTHandler *handler, void *eventId)
10801080
return 1;
10811081
}
10821082

1083-
pqueue_remove(evt->queue, eventId);
1083+
ps_pqueue_remove(evt->queue, eventId);
10841084
ET_default_monotonic(NULL, &evt->scheduleTime);
10851085
timeradd(&evt->scheduleTime, &evt->timeStep, &evt->nextAwake);
10861086
evt->queue = handler->dbg_queue;
1087-
pqueue_insert(evt->queue, evt);
1087+
ps_pqueue_insert(evt->queue, evt);
10881088

10891089
return 0;
10901090
}
@@ -1119,7 +1119,7 @@ char EVT_sched_update_partial_credit(EVTHandler *handler, void *eventId,
11191119
evt->nextAwake = now;
11201120

11211121
evt->timeStep = time;
1122-
pqueue_change_priority(evt->queue, evt->nextAwake, evt);
1122+
ps_pqueue_change_priority(evt->queue, evt->nextAwake, evt);
11231123

11241124
return 0;
11251125
}
@@ -1406,15 +1406,15 @@ static int edbg_client_msg(struct ZMQLClient *client, const void *data,
14061406
!strcasecmp(cmd, "clear_timed_breakpoint") ) {
14071407
evt = NULL;
14081408
if (json_get_ptr_prop(data, dataLen, "id", &id) >= 0) {
1409-
for (i = 1; !evt && i <= pqueue_size(ctx->queue); i++)
1409+
for (i = 1; !evt && i <= ps_pqueue_size(ctx->queue); i++)
14101410
if (ctx->queue->d[i] == id)
14111411
evt = id;
14121412
}
14131413
else if (json_get_string_prop(data, dataLen, "function", &func) >= 0) {
14141414
if (func) {
14151415
id = dlsym(RTLD_DEFAULT, func);
14161416
free(func);
1417-
for (i = 1; id && !evt && i <= pqueue_size(ctx->queue); i++)
1417+
for (i = 1; id && !evt && i <= ps_pqueue_size(ctx->queue); i++)
14181418
if ( ((ScheduleCB*)ctx->queue->d[i])->callback == id)
14191419
evt = ctx->queue->d[i];
14201420
}
@@ -1557,7 +1557,7 @@ static void edbg_report_timed_events(struct IPCBuffer *json, EVTHandler *ctx,
15571557
first = 0;
15581558
}
15591559

1560-
for (i = 1; i <= pqueue_size(ctx->queue); i++) {
1560+
for (i = 1; i <= ps_pqueue_size(ctx->queue); i++) {
15611561
edbg_report_timed_event(json, (ScheduleCB *)ctx->queue->d[i],
15621562
cur_time, first);
15631563
first = 0;

events.h

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ typedef struct EventState EVTHandler;
7474
* @return The event handler.
7575
*/
7676
EVTHandler *EVT_create_handler(EVT_debug_state_cb debug_cb, void *arg);
77+
struct EventState *EVT_initWithSize(int hashSize, EVT_debug_state_cb debug_cb,
78+
void *arg);
7779

7880
/**
7981
* Free an event handler.

0 commit comments

Comments
 (0)