treewide: rework mutex

Wrap mutex calls with traceable messages to help debugging resource locks.

[cleanup commit message]
Signed-off-by: Nick Hainke <vincent@systemli.org>
This commit is contained in:
Ian Clowes 2022-01-31 10:54:38 +00:00 committed by Nick Hainke
parent 0a962bea1f
commit be49c35686
6 changed files with 76 additions and 46 deletions

View file

@ -124,7 +124,7 @@ void *receive_msg_enc(void *args) {
}
int send_string(char *msg, bool is_enc) {
pthread_mutex_lock(&send_mutex);
dawn_mutex_lock(&send_mutex);
char* final_msg = NULL;
size_t msglen = 0;
@ -143,7 +143,7 @@ int send_string(char *msg, bool is_enc) {
char* gcrypt_buf = gcrypt_encrypt_msg(msg, strlen(msg) + 1, &gcrypt_len);
if (!gcrypt_buf) {
dawnlog_error("sendto() error: not enough memory\n");
pthread_mutex_unlock(&send_mutex);
dawn_mutex_unlock(&send_mutex);
exit(EXIT_FAILURE);
}
@ -153,7 +153,7 @@ int send_string(char *msg, bool is_enc) {
dawnlog_error("sendto() error: not enough memory\n");
dawn_free(gcrypt_buf);
gcrypt_buf = NULL;
pthread_mutex_unlock(&send_mutex);
dawn_mutex_unlock(&send_mutex);
exit(EXIT_FAILURE);
}
@ -175,7 +175,7 @@ int send_string(char *msg, bool is_enc) {
// Tidy up probbaly unnecessary if we're exiting, but...
if (is_enc)
dawn_free(final_msg);
pthread_mutex_unlock(&send_mutex);
dawn_mutex_unlock(&send_mutex);
exit(EXIT_FAILURE);
}
@ -186,7 +186,7 @@ int send_string(char *msg, bool is_enc) {
final_msg = NULL;
}
pthread_mutex_unlock(&send_mutex);
dawn_mutex_unlock(&send_mutex);
return 0;
}