sigio.c 1.1 KB
Newer Older
1
/*
L
Linus Torvalds 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14
 * Copyright (C) 2002 - 2003 Jeff Dike (jdike@addtoit.com)
 * Licensed under the GPL
 */

#include "linux/kernel.h"
#include "linux/list.h"
#include "linux/slab.h"
#include "linux/signal.h"
#include "linux/interrupt.h"
#include "init.h"
#include "sigio.h"
#include "irq_user.h"
#include "irq_kern.h"
15
#include "os.h"
L
Linus Torvalds 已提交
16 17 18 19

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

A
Al Viro 已提交
20
static irqreturn_t sigio_interrupt(int irq, void *data)
L
Linus Torvalds 已提交
21
{
22 23
	char c;

24
	os_read_file(sigio_irq_fd, &c, sizeof(c));
L
Linus Torvalds 已提交
25
	reactivate_fd(sigio_irq_fd, SIGIO_WRITE_IRQ);
J
Jeff Dike 已提交
26
	return IRQ_HANDLED;
L
Linus Torvalds 已提交
27 28 29 30 31 32 33
}

int write_sigio_irq(int fd)
{
	int err;

	err = um_request_irq(SIGIO_WRITE_IRQ, fd, IRQ_READ, sigio_interrupt,
J
Jeff Dike 已提交
34
			     IRQF_DISABLED|IRQF_SAMPLE_RANDOM, "write sigio",
L
Linus Torvalds 已提交
35 36 37 38
			     NULL);
	if(err){
		printk("write_sigio_irq : um_request_irq failed, err = %d\n",
		       err);
J
Jeff Dike 已提交
39
		return -1;
L
Linus Torvalds 已提交
40 41
	}
	sigio_irq_fd = fd;
J
Jeff Dike 已提交
42
	return 0;
L
Linus Torvalds 已提交
43 44
}

J
Jeff Dike 已提交
45
/* These are called from os-Linux/sigio.c to protect its pollfds arrays. */
L
Linus Torvalds 已提交
46 47 48 49 50 51 52 53 54 55 56
static DEFINE_SPINLOCK(sigio_spinlock);

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

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