Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 135612
b: refs/heads/master
c: 98c1c68
h: refs/heads/master
v: v3
  • Loading branch information
Heiko Carstens authored and Martin Schwidefsky committed Mar 26, 2009
1 parent 1626b65 commit 6fb7349
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e74fe0cec92439115630b51195444b89b910800a
refs/heads/master: 98c1c6825247c71e3d8a9a5439ba21fce7563014
32 changes: 23 additions & 9 deletions trunk/drivers/s390/cio/crw.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
*/

#include <linux/semaphore.h>
#include <linux/mutex.h>
#include <linux/kthread.h>
#include <linux/init.h>
#include <asm/crw.h>

static struct semaphore crw_semaphore;
static DEFINE_MUTEX(crw_handler_mutex);
static crw_handler_t crw_handlers[NR_RSCS];

/**
Expand All @@ -25,11 +27,17 @@ static crw_handler_t crw_handlers[NR_RSCS];
*/
int crw_register_handler(int rsc, crw_handler_t handler)
{
int rc = 0;

if ((rsc < 0) || (rsc >= NR_RSCS))
return -EINVAL;
if (!cmpxchg(&crw_handlers[rsc], NULL, handler))
return 0;
return -EBUSY;
mutex_lock(&crw_handler_mutex);
if (crw_handlers[rsc])
rc = -EBUSY;
else
crw_handlers[rsc] = handler;
mutex_unlock(&crw_handler_mutex);
return rc;
}

/**
Expand All @@ -40,8 +48,9 @@ void crw_unregister_handler(int rsc)
{
if ((rsc < 0) || (rsc >= NR_RSCS))
return;
xchg(&crw_handlers[rsc], NULL);
synchronize_sched();
mutex_lock(&crw_handler_mutex);
crw_handlers[rsc] = NULL;
mutex_unlock(&crw_handler_mutex);
}

/*
Expand All @@ -58,6 +67,8 @@ static int crw_collect_info(void *unused)
ignore = down_interruptible(&crw_semaphore);
chain = 0;
while (1) {
crw_handler_t handler;

if (unlikely(chain > 1)) {
struct crw tmp_crw;

Expand Down Expand Up @@ -90,21 +101,24 @@ static int crw_collect_info(void *unused)
int i;

pr_debug("%s: crw overflow detected!\n", __func__);
mutex_lock(&crw_handler_mutex);
for (i = 0; i < NR_RSCS; i++) {
if (crw_handlers[i])
crw_handlers[i](NULL, NULL, 1);
}
mutex_unlock(&crw_handler_mutex);
chain = 0;
continue;
}
if (crw[0].chn && !chain) {
chain++;
continue;
}
if (crw_handlers[crw[chain].rsc])
crw_handlers[crw[chain].rsc](&crw[0],
chain ? &crw[1] : NULL,
0);
mutex_lock(&crw_handler_mutex);
handler = crw_handlers[crw[chain].rsc];
if (handler)
handler(&crw[0], chain ? &crw[1] : NULL, 0);
mutex_unlock(&crw_handler_mutex);
/* chain is always 0 or 1 here. */
chain = crw[chain].chn ? chain + 1 : 0;
}
Expand Down

0 comments on commit 6fb7349

Please sign in to comment.