projects
/
buftee
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Reduce locking in writer_routine().
[buftee]
/
buftee.c
diff --git
a/buftee.c
b/buftee.c
index
c31ba69
..
23d2d2c
100644
(file)
--- a/
buftee.c
+++ b/
buftee.c
@@
-276,11
+276,9
@@
static void unlock(pthread_mutex_t* mutex) {
static void* writer_routine(void *arg) {
struct writer_thread* my = arg;
static void* writer_routine(void *arg) {
struct writer_thread* my = arg;
+ struct buf* buf = NULL;
+ lock(&shared_queue_mutex);
for (;;) {
for (;;) {
- // FIXME: less locking
- struct buf* buf = NULL;
-
- lock(&shared_queue_mutex);
while (!stopping && STAILQ_EMPTY(&my->queue)) {
// Sleep.
pthread_cond_wait(&shared_wakeup_cond, &shared_queue_mutex);
while (!stopping && STAILQ_EMPTY(&my->queue)) {
// Sleep.
pthread_cond_wait(&shared_wakeup_cond, &shared_queue_mutex);
@@
-302,7
+300,6
@@
static void* writer_routine(void *arg) {
// Unreference buffer, freeing it if we have to.
lock(&shared_queue_mutex);
unref_buf(buf);
// Unreference buffer, freeing it if we have to.
lock(&shared_queue_mutex);
unref_buf(buf);
- unlock(&shared_queue_mutex);
}
warnx("thread exiting cleanly");
return NULL;
}
warnx("thread exiting cleanly");
return NULL;