mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 17:53:01 +01:00
Fix a couple data races
This commit is contained in:
parent
1cba726bb8
commit
090fcfffe3
29
src/chat.c
29
src/chat.c
@ -1285,13 +1285,19 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
|
|||||||
|
|
||||||
/* Draw status bar */
|
/* Draw status bar */
|
||||||
StatusBar *statusbar = self->stb;
|
StatusBar *statusbar = self->stb;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&Winthread.lock);
|
||||||
|
Tox_Connection connection = statusbar->connection;
|
||||||
|
Tox_User_Status status = statusbar->status;
|
||||||
|
pthread_mutex_unlock(&Winthread.lock);
|
||||||
|
|
||||||
wmove(statusbar->topline, 0, 0);
|
wmove(statusbar->topline, 0, 0);
|
||||||
|
|
||||||
wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
||||||
wprintw(statusbar->topline, " [");
|
wprintw(statusbar->topline, " [");
|
||||||
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
||||||
|
|
||||||
switch (statusbar->connection) {
|
switch (connection) {
|
||||||
case TOX_CONNECTION_TCP:
|
case TOX_CONNECTION_TCP:
|
||||||
wattron(statusbar->topline, A_BOLD | COLOR_PAIR(STATUS_ONLINE));
|
wattron(statusbar->topline, A_BOLD | COLOR_PAIR(STATUS_ONLINE));
|
||||||
wprintw(statusbar->topline, "TCP");
|
wprintw(statusbar->topline, "TCP");
|
||||||
@ -1315,8 +1321,6 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
|
|||||||
wprintw(statusbar->topline, "]");
|
wprintw(statusbar->topline, "]");
|
||||||
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
||||||
|
|
||||||
Tox_User_Status status = statusbar->status;
|
|
||||||
|
|
||||||
if (status != TOX_USER_STATUS_NONE) {
|
if (status != TOX_USER_STATUS_NONE) {
|
||||||
const char *status_text = "ERROR";
|
const char *status_text = "ERROR";
|
||||||
int colour = MAGENTA;
|
int colour = MAGENTA;
|
||||||
@ -1376,13 +1380,15 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
|
|||||||
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH] = {'\0'};
|
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH] = {'\0'};
|
||||||
|
|
||||||
pthread_mutex_lock(&Winthread.lock);
|
pthread_mutex_lock(&Winthread.lock);
|
||||||
|
|
||||||
tox_friend_get_status_message(m, self->num, (uint8_t *) statusmsg, NULL);
|
tox_friend_get_status_message(m, self->num, (uint8_t *) statusmsg, NULL);
|
||||||
size_t s_len = tox_friend_get_status_message_size(m, self->num, NULL);
|
size_t s_len = tox_friend_get_status_message_size(m, self->num, NULL);
|
||||||
pthread_mutex_unlock(&Winthread.lock);
|
|
||||||
|
|
||||||
filter_str(statusmsg, s_len);
|
filter_str(statusmsg, s_len);
|
||||||
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
||||||
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
|
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&Winthread.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
self->x = x2;
|
self->x = x2;
|
||||||
@ -1390,19 +1396,27 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
|
|||||||
/* Truncate note if it doesn't fit in statusbar */
|
/* Truncate note if it doesn't fit in statusbar */
|
||||||
size_t maxlen = x2 - getcurx(statusbar->topline) - (KEY_IDENT_DIGITS * 2) - 6;
|
size_t maxlen = x2 - getcurx(statusbar->topline) - (KEY_IDENT_DIGITS * 2) - 6;
|
||||||
|
|
||||||
if (statusbar->statusmsg_len > maxlen) {
|
pthread_mutex_lock(&Winthread.lock);
|
||||||
statusbar->statusmsg[maxlen - 3] = '\0';
|
size_t statusmsg_len = statusbar->statusmsg_len;
|
||||||
|
pthread_mutex_unlock(&Winthread.lock);
|
||||||
|
|
||||||
|
if (statusmsg_len > maxlen) {
|
||||||
|
pthread_mutex_lock(&Winthread.lock);
|
||||||
|
statusbar->statusmsg[maxlen - 3] = 0;
|
||||||
strcat(statusbar->statusmsg, "...");
|
strcat(statusbar->statusmsg, "...");
|
||||||
statusbar->statusmsg_len = maxlen;
|
statusbar->statusmsg_len = maxlen;
|
||||||
|
pthread_mutex_unlock(&Winthread.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (statusbar->statusmsg[0]) {
|
if (statusmsg_len > 0) {
|
||||||
wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
||||||
wprintw(statusbar->topline, " | ");
|
wprintw(statusbar->topline, " | ");
|
||||||
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
||||||
|
|
||||||
wattron(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
wattron(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
||||||
|
pthread_mutex_lock(&Winthread.lock);
|
||||||
wprintw(statusbar->topline, "%s ", statusbar->statusmsg);
|
wprintw(statusbar->topline, "%s ", statusbar->statusmsg);
|
||||||
|
pthread_mutex_unlock(&Winthread.lock);
|
||||||
} else {
|
} else {
|
||||||
wattron(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
wattron(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
||||||
}
|
}
|
||||||
@ -1505,6 +1519,7 @@ static void chat_onInit(ToxWindow *self, Tox *m)
|
|||||||
|
|
||||||
/* Init statusbar info */
|
/* Init statusbar info */
|
||||||
StatusBar *statusbar = self->stb;
|
StatusBar *statusbar = self->stb;
|
||||||
|
|
||||||
statusbar->status = get_friend_status(self->num);
|
statusbar->status = get_friend_status(self->num);
|
||||||
statusbar->connection = get_friend_connection_status(self->num);
|
statusbar->connection = get_friend_connection_status(self->num);
|
||||||
|
|
||||||
|
17
src/prompt.c
17
src/prompt.c
@ -424,11 +424,14 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
|
|||||||
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH];
|
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH];
|
||||||
|
|
||||||
pthread_mutex_lock(&Winthread.lock);
|
pthread_mutex_lock(&Winthread.lock);
|
||||||
|
|
||||||
size_t slen = tox_self_get_status_message_size(m);
|
size_t slen = tox_self_get_status_message_size(m);
|
||||||
tox_self_get_status_message(m, (uint8_t *) statusmsg);
|
tox_self_get_status_message(m, (uint8_t *) statusmsg);
|
||||||
|
|
||||||
statusmsg[slen] = '\0';
|
statusmsg[slen] = '\0';
|
||||||
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
||||||
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
|
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
|
||||||
|
|
||||||
pthread_mutex_unlock(&Winthread.lock);
|
pthread_mutex_unlock(&Winthread.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,25 +441,29 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
|
|||||||
uint16_t maxlen = x2 - getcurx(statusbar->topline) - 3;
|
uint16_t maxlen = x2 - getcurx(statusbar->topline) - 3;
|
||||||
|
|
||||||
pthread_mutex_lock(&Winthread.lock);
|
pthread_mutex_lock(&Winthread.lock);
|
||||||
|
size_t statusmsg_len = statusbar->statusmsg_len;
|
||||||
|
pthread_mutex_unlock(&Winthread.lock);
|
||||||
|
|
||||||
if (statusbar->statusmsg_len > maxlen) {
|
if (statusmsg_len > maxlen) {
|
||||||
statusbar->statusmsg[maxlen - 3] = '\0';
|
pthread_mutex_lock(&Winthread.lock);
|
||||||
|
statusbar->statusmsg[maxlen - 3] = 0;
|
||||||
strcat(statusbar->statusmsg, "...");
|
strcat(statusbar->statusmsg, "...");
|
||||||
statusbar->statusmsg_len = maxlen;
|
statusbar->statusmsg_len = maxlen;
|
||||||
|
pthread_mutex_unlock(&Winthread.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (statusbar->statusmsg[0]) {
|
if (statusmsg_len) {
|
||||||
wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
||||||
wprintw(statusbar->topline, " | ");
|
wprintw(statusbar->topline, " | ");
|
||||||
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
||||||
|
|
||||||
wattron(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
wattron(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
||||||
|
pthread_mutex_lock(&Winthread.lock);
|
||||||
wprintw(statusbar->topline, "%s", statusbar->statusmsg);
|
wprintw(statusbar->topline, "%s", statusbar->statusmsg);
|
||||||
|
pthread_mutex_unlock(&Winthread.lock);
|
||||||
wattroff(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
wattroff(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&Winthread.lock);
|
|
||||||
|
|
||||||
int y;
|
int y;
|
||||||
int x;
|
int x;
|
||||||
getyx(self->window, y, x);
|
getyx(self->window, y, x);
|
||||||
|
@ -806,12 +806,14 @@ void draw_active_window(Tox *m)
|
|||||||
a->onDraw(a, m);
|
a->onDraw(a, m);
|
||||||
wrefresh(a->window);
|
wrefresh(a->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef AUDIO
|
#ifdef AUDIO
|
||||||
else if (a->is_call && timed_out(a->chatwin->infobox.lastupdate, 1)) {
|
else if (a->is_call && timed_out(a->chatwin->infobox.lastupdate, 1)) {
|
||||||
touchwin(a->window);
|
touchwin(a->window);
|
||||||
a->onDraw(a, m);
|
a->onDraw(a, m);
|
||||||
wrefresh(a->window);
|
wrefresh(a->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // AUDIO
|
#endif // AUDIO
|
||||||
|
|
||||||
#ifdef GAMES
|
#ifdef GAMES
|
||||||
|
Loading…
Reference in New Issue
Block a user