mirror of
https://github.com/schoebel/mars
synced 2025-03-11 07:47:41 +00:00
client: replace spinlock with mutex
This commit is contained in:
parent
8b6f93a6db
commit
2fef63b72a
@ -238,17 +238,16 @@ static
|
||||
void _hash_insert(struct client_output *output, struct client_mref_aspect *mref_a)
|
||||
{
|
||||
struct mref_object *mref = mref_a->object;
|
||||
unsigned long flags;
|
||||
int hash_index;
|
||||
|
||||
traced_lock(&output->lock, flags);
|
||||
mutex_lock(&output->mutex);
|
||||
list_del(&mref_a->io_head);
|
||||
list_add_tail(&mref_a->io_head, &output->mref_list);
|
||||
list_del(&mref_a->hash_head);
|
||||
mref->ref_id = ++output->last_id;
|
||||
hash_index = mref->ref_id % CLIENT_HASH_MAX;
|
||||
list_add_tail(&mref_a->hash_head, &output->hash_table[hash_index]);
|
||||
traced_unlock(&output->lock, flags);
|
||||
mutex_unlock(&output->mutex);
|
||||
}
|
||||
|
||||
static void client_ref_io(struct client_output *output, struct mref_object *mref)
|
||||
@ -300,7 +299,6 @@ int receiver_thread(void *data)
|
||||
struct list_head *tmp;
|
||||
struct client_mref_aspect *mref_a = NULL;
|
||||
struct mref_object *mref = NULL;
|
||||
unsigned long flags;
|
||||
|
||||
if (output->recv_error) {
|
||||
/* The protocol may be out of sync.
|
||||
@ -333,13 +331,13 @@ int receiver_thread(void *data)
|
||||
{
|
||||
int hash_index = cmd.cmd_int1 % CLIENT_HASH_MAX;
|
||||
|
||||
traced_lock(&output->lock, flags);
|
||||
mutex_lock(&output->mutex);
|
||||
for (tmp = output->hash_table[hash_index].next; tmp != &output->hash_table[hash_index]; tmp = tmp->next) {
|
||||
struct mref_object *tmp_mref;
|
||||
mref_a = container_of(tmp, struct client_mref_aspect, hash_head);
|
||||
tmp_mref = mref_a->object;
|
||||
if (unlikely(!tmp_mref)) {
|
||||
traced_unlock(&output->lock, flags);
|
||||
mutex_unlock(&output->mutex);
|
||||
MARS_ERR("bad internal mref pointer\n");
|
||||
status = -EBADR;
|
||||
goto done;
|
||||
@ -351,7 +349,7 @@ int receiver_thread(void *data)
|
||||
break;
|
||||
}
|
||||
}
|
||||
traced_unlock(&output->lock, flags);
|
||||
mutex_unlock(&output->mutex);
|
||||
|
||||
if (unlikely(!mref)) {
|
||||
MARS_WRN("got unknown id = %d for callback\n", cmd.cmd_int1);
|
||||
@ -415,9 +413,7 @@ int receiver_thread(void *data)
|
||||
static
|
||||
void _do_resubmit(struct client_output *output)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
traced_lock(&output->lock, flags);
|
||||
mutex_lock(&output->mutex);
|
||||
if (!list_empty(&output->wait_list)) {
|
||||
struct list_head *first = output->wait_list.next;
|
||||
struct list_head *last = output->wait_list.prev;
|
||||
@ -428,7 +424,7 @@ void _do_resubmit(struct client_output *output)
|
||||
INIT_LIST_HEAD(&output->wait_list);
|
||||
MARS_IO("done re-submit %p %p\n", first, last);
|
||||
}
|
||||
traced_unlock(&output->lock, flags);
|
||||
mutex_unlock(&output->mutex);
|
||||
}
|
||||
|
||||
static
|
||||
@ -440,7 +436,6 @@ void _do_timeout(struct client_output *output, struct list_head *anchor, bool fo
|
||||
LIST_HEAD(tmp_list);
|
||||
int rounds = 0;
|
||||
long io_timeout = brick->power.io_timeout;
|
||||
unsigned long flags;
|
||||
|
||||
if (io_timeout <= 0)
|
||||
io_timeout = global_net_io_timeout;
|
||||
@ -453,7 +448,7 @@ void _do_timeout(struct client_output *output, struct list_head *anchor, bool fo
|
||||
|
||||
io_timeout *= HZ;
|
||||
|
||||
traced_lock(&output->lock, flags);
|
||||
mutex_lock(&output->mutex);
|
||||
for (tmp = anchor->next, next = tmp->next; tmp != anchor; tmp = next, next = tmp->next) {
|
||||
struct client_mref_aspect *mref_a;
|
||||
|
||||
@ -468,7 +463,7 @@ void _do_timeout(struct client_output *output, struct list_head *anchor, bool fo
|
||||
list_del_init(&mref_a->io_head);
|
||||
list_add_tail(&mref_a->tmp_head, &tmp_list);
|
||||
}
|
||||
traced_unlock(&output->lock, flags);
|
||||
mutex_unlock(&output->mutex);
|
||||
|
||||
while (!list_empty(&tmp_list)) {
|
||||
struct client_mref_aspect *mref_a;
|
||||
@ -501,7 +496,6 @@ static int sender_thread(void *data)
|
||||
{
|
||||
struct client_output *output = data;
|
||||
struct client_brick *brick = output->brick;
|
||||
unsigned long flags;
|
||||
bool do_kill = false;
|
||||
int status = 0;
|
||||
|
||||
@ -569,16 +563,16 @@ static int sender_thread(void *data)
|
||||
|
||||
/* Grab the next mref from the queue
|
||||
*/
|
||||
traced_lock(&output->lock, flags);
|
||||
mutex_lock(&output->mutex);
|
||||
if (list_empty(&output->mref_list)) {
|
||||
traced_unlock(&output->lock, flags);
|
||||
mutex_unlock(&output->mutex);
|
||||
continue;
|
||||
}
|
||||
tmp = output->mref_list.next;
|
||||
list_del(tmp);
|
||||
list_add(tmp, &output->wait_list);
|
||||
mref_a = container_of(tmp, struct client_mref_aspect, io_head);
|
||||
traced_unlock(&output->lock, flags);
|
||||
mutex_unlock(&output->mutex);
|
||||
|
||||
mref = mref_a->object;
|
||||
|
||||
@ -739,7 +733,7 @@ static int client_output_construct(struct client_output *output)
|
||||
for (i = 0; i < CLIENT_HASH_MAX; i++) {
|
||||
INIT_LIST_HEAD(&output->hash_table[i]);
|
||||
}
|
||||
spin_lock_init(&output->lock);
|
||||
mutex_init(&output->mutex);
|
||||
INIT_LIST_HEAD(&output->mref_list);
|
||||
INIT_LIST_HEAD(&output->wait_list);
|
||||
init_waitqueue_head(&output->event);
|
||||
|
@ -64,7 +64,7 @@ struct client_output {
|
||||
MARS_OUTPUT(client);
|
||||
atomic_t fly_count;
|
||||
atomic_t timeout_count;
|
||||
spinlock_t lock;
|
||||
struct mutex mutex;
|
||||
struct list_head mref_list;
|
||||
struct list_head wait_list;
|
||||
wait_queue_head_t event;
|
||||
|
Loading…
Reference in New Issue
Block a user