sigio.c 1004 字节
Newer Older
1
/*
J
Jeff Dike 已提交
2
 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
L
Linus Torvalds 已提交
3 4 5
 * Licensed under the GPL
 */

J
Jeff Dike 已提交
6
#include <linux/interrupt.h>
L
Linus Torvalds 已提交
7
#include "irq_kern.h"
8
#include "os.h"
J
Jeff Dike 已提交
9
#include "sigio.h"
L
Linus Torvalds 已提交
10 11 12 13

/* Protected by sigio_lock() called from write_sigio_workaround */
static int sigio_irq_fd = -1;

A
Al Viro 已提交
14
static irqreturn_t sigio_interrupt(int irq, void *data)
L
Linus Torvalds 已提交
15
{
16 17
	char c;

18
	os_read_file(sigio_irq_fd, &c, sizeof(c));
L
Linus Torvalds 已提交
19
	reactivate_fd(sigio_irq_fd, SIGIO_WRITE_IRQ);
J
Jeff Dike 已提交
20
	return IRQ_HANDLED;
L
Linus Torvalds 已提交
21 22 23 24 25 26 27
}

int write_sigio_irq(int fd)
{
	int err;

	err = um_request_irq(SIGIO_WRITE_IRQ, fd, IRQ_READ, sigio_interrupt,
28
			     0, "write sigio", NULL);
J
Jeff Dike 已提交
29 30 31
	if (err) {
		printk(KERN_ERR "write_sigio_irq : um_request_irq failed, "
		       "err = %d\n", err);
J
Jeff Dike 已提交
32
		return -1;
L
Linus Torvalds 已提交
33 34
	}
	sigio_irq_fd = fd;
J
Jeff Dike 已提交
35
	return 0;
L
Linus Torvalds 已提交
36 37
}

J
Jeff Dike 已提交
38
/* These are called from os-Linux/sigio.c to protect its pollfds arrays. */
L
Linus Torvalds 已提交
39 40 41 42 43 44 45 46 47 48 49
static DEFINE_SPINLOCK(sigio_spinlock);

void sigio_lock(void)
{
	spin_lock(&sigio_spinlock);
}

void sigio_unlock(void)
{
	spin_unlock(&sigio_spinlock);
}