diff --git a/src/audio_device.c b/src/audio_device.c index 9e6c1e2..6ff8f80 100644 --- a/src/audio_device.c +++ b/src/audio_device.c @@ -321,9 +321,6 @@ DeviceError close_device(DeviceType type, uint32_t device_idx) running[type][device_idx] = NULL; if ( !device->ref_count ) { - -// printf("Closed device "); - if (type == input) { if ( !alcCaptureCloseDevice(device->dhndl) ) rc = de_AlError; } @@ -414,23 +411,26 @@ void* thread_poll (void* arg) // TODO: maybe use thread for every input source int32_t sample = 0; - while (true) + while (1) { lock; if (!thread_running) { unlock; break; } + + bool paused = thread_paused; unlock; - if (thread_paused) usleep(10000); /* Wait for unpause. */ - else - { - for (i = 0; i < size[input]; ++i) - { + /* Wait for unpause. */ + if (paused) { + usleep(10000); + } + + else { + for (i = 0; i < size[input]; ++i) { lock; - if (running[input][i] != NULL) - { + if (running[input][i] != NULL) { alcGetIntegerv(running[input][i]->dhndl, ALC_CAPTURE_SAMPLES, sizeof(int32_t), &sample); int f_size = (running[input][i]->sample_rate * running[input][i]->frame_duration / 1000); diff --git a/src/bootstrap.c b/src/bootstrap.c index 5c61bb0..9dec19b 100644 --- a/src/bootstrap.c +++ b/src/bootstrap.c @@ -79,7 +79,7 @@ extern struct Winthread Winthread; #define MAX_NODELIST_SIZE (MAX_RECV_CURL_DATA_SIZE) -struct Thread_Data { +static struct Thread_Data { pthread_t tid; pthread_attr_t attr; pthread_mutex_t lock; diff --git a/src/groupchat.c b/src/groupchat.c index 0e58cf3..27988c1 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -683,7 +683,9 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m) mvwvline(ctx->sidebar, 0, 0, ACS_VLINE, y2 - CHATBOX_HEIGHT); mvwaddch(ctx->sidebar, y2 - CHATBOX_HEIGHT, 0, ACS_BTEE); + pthread_mutex_lock(&Winthread.lock); int num_peers = groupchats[self->num].num_peers; + pthread_mutex_unlock(&Winthread.lock); wmove(ctx->sidebar, 0, 1); wattron(ctx->sidebar, A_BOLD); @@ -698,12 +700,19 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m) for (i = 0; i < num_peers && i < maxlines; ++i) { wmove(ctx->sidebar, i + 2, 1); + + pthread_mutex_lock(&Winthread.lock); int peer = i + groupchats[self->num].side_pos; + pthread_mutex_unlock(&Winthread.lock); /* truncate nick to fit in side panel without modifying list */ char tmpnck[TOX_MAX_NAME_LENGTH]; int maxlen = SIDEBAR_WIDTH - 2; + + pthread_mutex_lock(&Winthread.lock); memcpy(tmpnck, &groupchats[self->num].peer_names[peer * TOX_MAX_NAME_LENGTH], maxlen); + pthread_mutex_unlock(&Winthread.lock); + tmpnck[maxlen] = '\0'; wprintw(ctx->sidebar, "%s\n", tmpnck); diff --git a/src/video_device.c b/src/video_device.c index 2307049..7f2227e 100644 --- a/src/video_device.c +++ b/src/video_device.c @@ -236,7 +236,10 @@ VideoDeviceError init_video_devices() VideoDeviceError terminate_video_devices() { /* Cleanup if needed */ + lock; video_thread_running = false; + unlock; + usleep(20000); int i; @@ -614,16 +617,19 @@ void* video_thread_poll (void* arg) // TODO: maybe use thread for every input so (void)arg; uint32_t i; - while (video_thread_running) - { + while (1) { + lock; + if (!video_thread_running) { + unlock; + break; + } + unlock; + if ( video_thread_paused ) usleep(10000); /* Wait for unpause. */ - else - { - for (i = 0; i < size[vdt_input]; ++i) - { + else { + for (i = 0; i < size[vdt_input]; ++i) { lock; - if ( video_devices_running[vdt_input][i] != NULL ) - { + if ( video_devices_running[vdt_input][i] != NULL ) { /* Obtain frame image data from device buffers */ VideoDevice* device = video_devices_running[vdt_input][i]; uint16_t video_width = device->video_width;