diff options
author | Lars Henriksen <LarsHenriksen@get2net.dk> | 2018-09-15 22:12:06 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2018-10-21 20:02:57 +0200 |
commit | d1075e525f45d783ac38d64cc5929393946072c1 (patch) | |
tree | a46de97fbc662094ea55ba7425252a5969f9dc69 /src | |
parent | 53b55930e8021f28a5393896b29b6a01d81cadd3 (diff) | |
download | calcurse-d1075e525f45d783ac38d64cc5929393946072c1.tar.gz calcurse-d1075e525f45d783ac38d64cc5929393946072c1.zip |
Mutex for the system message queue
The main thread only reads and removes events from the queue. All other threads
only insert events in the queue. Hence, only insertion and removal need protection.
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/queue.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/queue.c b/src/queue.c index 939b502..dad7056 100644 --- a/src/queue.c +++ b/src/queue.c @@ -4,6 +4,7 @@ * A queue for calcurse system messages. */ llist_t sysqueue; +static pthread_mutex_t que_mutex = PTHREAD_MUTEX_INITIALIZER; void que_init(void) { @@ -30,7 +31,9 @@ struct event *que_ins(char *mesg, time_t time, int id) ev->day = time; ev->id = id; ev->note = NULL; + pthread_mutex_lock(&que_mutex); LLIST_ADD(&sysqueue, ev); + pthread_mutex_unlock(&que_mutex); return ev; } @@ -52,11 +55,14 @@ void que_rem(void) if (!sysqueue.head) return; - else - ev = sysqueue.head->data; + ev = sysqueue.head->data; + + pthread_mutex_lock(&que_mutex); + LLIST_REMOVE(&sysqueue, sysqueue.head); + pthread_mutex_unlock(&que_mutex); + mem_free(ev->mesg); mem_free(ev); - LLIST_REMOVE(&sysqueue, sysqueue.head); } /* |