1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
/* OpenCP Module Player
* copyright (c) '94-'10 Niklas Beisert <nbeisert@physik.tu-muenchen.de>
*
* IRQ handlers
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* revision history: (please note changes here)
* -nb980510 Niklas Beisert <nbeisert@physik.tu-muenchen.de>
* -first release
* -ss040613 Stian Skjelstad <stian@nixia.no>
* -POSIX signals looks so much cleaner, don't they?
*/
#include "config.h"
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "types.h"
#include "irq.h"
#ifndef _NSIG
#define _NSIG NSIG
#endif
static struct sigaction orgstate[_NSIG] = {{{0}}};
static int gotmask = 0;
static sigset_t orgmask;
int irqInit(int signum, void (*rout)(int), int recursive)
{
struct sigaction newstate;
memset(&newstate, 0, sizeof(newstate));
newstate.sa_handler=rout;
if (recursive)
newstate.sa_flags=SA_NODEFER;
newstate.sa_flags|=SA_RESTART;
/*
fprintf(stderr, "irqInit: setting irq %d to %p\n", signum, rout);
*/
if (sigaction(signum, &newstate, &orgstate[signum]))
{
perror("sigaction()");
exit(1);
}
if (!gotmask)
{
if (sigprocmask(SIG_SETMASK, NULL, &orgmask))
{
perror("sigprocmask(1)");
exit(1);
}
gotmask=1;
}
if (sigismember(&orgmask, signum))
{
sigset_t mask;
memset(&mask, 0, sizeof(mask));
sigaddset(&mask, signum);
if (sigprocmask(SIG_UNBLOCK, &mask, NULL))
{
perror("sigprocmask(2)");
exit(1);
}
}
return 1;
}
void irqDone(int signum)
{
if (sigismember(&orgmask, signum))
{
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, signum);
sigprocmask(SIG_BLOCK, &mask, NULL);
}
sigaction(signum, &orgstate[signum], NULL);
return;
}
|