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