server: replace spinlock with mutex

This commit is contained in:
Thomas Schoebel-Theuer 2020-06-12 09:37:53 +02:00 committed by Thomas Schoebel-Theuer
parent 37da08d6a4
commit f7dbb5c0d0
2 changed files with 8 additions and 10 deletions

View File

@ -115,7 +115,6 @@ int cb_thread(void *data)
struct mref_object *mref; struct mref_object *mref;
struct list_head *tmp; struct list_head *tmp;
bool cork; bool cork;
unsigned long flags;
wait_event_interruptible_timeout( wait_event_interruptible_timeout(
brick->cb_event, brick->cb_event,
@ -123,19 +122,19 @@ int cb_thread(void *data)
!list_empty(&brick->cb_write_list), !list_empty(&brick->cb_write_list),
1 * HZ); 1 * HZ);
traced_lock(&brick->cb_lock, flags); mutex_lock(&brick->cb_mutex);
tmp = brick->cb_write_list.next; tmp = brick->cb_write_list.next;
if (tmp == &brick->cb_write_list) { if (tmp == &brick->cb_write_list) {
tmp = brick->cb_read_list.next; tmp = brick->cb_read_list.next;
if (tmp == &brick->cb_read_list) { if (tmp == &brick->cb_read_list) {
traced_unlock(&brick->cb_lock, flags); mutex_unlock(&brick->cb_mutex);
brick_msleep(1000 / HZ); brick_yield();
continue; continue;
} }
} }
list_del_init(tmp); list_del_init(tmp);
cork = !list_empty(&brick->cb_write_list); cork = !list_empty(&brick->cb_write_list);
traced_unlock(&brick->cb_lock, flags); mutex_unlock(&brick->cb_mutex);
mref_a = container_of(tmp, struct server_mref_aspect, cb_head); mref_a = container_of(tmp, struct server_mref_aspect, cb_head);
mref = mref_a->object; mref = mref_a->object;
@ -196,7 +195,6 @@ void server_endio(struct generic_callback *cb)
struct server_mref_aspect *mref_a; struct server_mref_aspect *mref_a;
struct mref_object *mref; struct mref_object *mref;
struct server_brick *brick; struct server_brick *brick;
unsigned long flags;
mref_a = cb->cb_private; mref_a = cb->cb_private;
CHECK_PTR(mref_a, err); CHECK_PTR(mref_a, err);
@ -213,13 +211,13 @@ void server_endio(struct generic_callback *cb)
return; return;
} }
traced_lock(&brick->cb_lock, flags); mutex_lock(&brick->cb_mutex);
if (mref->ref_flags & MREF_WRITE) { if (mref->ref_flags & MREF_WRITE) {
list_add_tail(&mref_a->cb_head, &brick->cb_write_list); list_add_tail(&mref_a->cb_head, &brick->cb_write_list);
} else { } else {
list_add_tail(&mref_a->cb_head, &brick->cb_read_list); list_add_tail(&mref_a->cb_head, &brick->cb_read_list);
} }
traced_unlock(&brick->cb_lock, flags); mutex_unlock(&brick->cb_mutex);
wake_up_interruptible(&brick->cb_event); wake_up_interruptible(&brick->cb_event);
return; return;
@ -755,7 +753,7 @@ static int server_brick_construct(struct server_brick *brick)
init_waitqueue_head(&brick->startup_event); init_waitqueue_head(&brick->startup_event);
init_waitqueue_head(&brick->cb_event); init_waitqueue_head(&brick->cb_event);
sema_init(&brick->socket_sem, 1); sema_init(&brick->socket_sem, 1);
spin_lock_init(&brick->cb_lock); mutex_init(&brick->cb_mutex);
INIT_LIST_HEAD(&brick->cb_read_list); INIT_LIST_HEAD(&brick->cb_read_list);
INIT_LIST_HEAD(&brick->cb_write_list); INIT_LIST_HEAD(&brick->cb_write_list);
return 0; return 0;

View File

@ -61,7 +61,7 @@ struct server_brick {
struct task_struct *cb_thread; struct task_struct *cb_thread;
wait_queue_head_t startup_event; wait_queue_head_t startup_event;
wait_queue_head_t cb_event; wait_queue_head_t cb_event;
spinlock_t cb_lock; struct mutex cb_mutex;
struct list_head cb_read_list; struct list_head cb_read_list;
struct list_head cb_write_list; struct list_head cb_write_list;
atomic_t in_flight; atomic_t in_flight;