update output function and fix segfault
This commit is contained in:
@@ -6,14 +6,20 @@ int ListCount(LIST *list) {
|
||||
}
|
||||
|
||||
void *ListFirst(LIST *list) {
|
||||
if (list->size != 0) {
|
||||
list->current = list->head;
|
||||
return list->current->data;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *ListLast(LIST *list) {
|
||||
if (list->size != 0) {
|
||||
list->current = list->tail;
|
||||
return list->current->data;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *ListNext(LIST *list) {
|
||||
if (list->current->next != NULL) {
|
||||
|
||||
@@ -69,12 +69,16 @@ void *output(void *arg) {
|
||||
char msg[30];
|
||||
while (1) {
|
||||
pthread_mutex_lock(&receivemut);
|
||||
if (ListCount(receivelist) != 0) {
|
||||
ListFirst(receivelist);
|
||||
strcpy(msg, ListCurr(receivelist));
|
||||
ListRemove(receivelist);
|
||||
}
|
||||
pthread_mutex_unlock(&receivemut);
|
||||
if (ListCount(receivelist) != 0) {
|
||||
printf("%s\n", msg);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user