/* * Copyright (c) 1995, 1996 Gunther Schadow. All rights reserved. * * 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. */ #include "pg_config.h" #include "trip.h" #include "trap.h" #include result claim_line(pid_t pid, int pri) { sigset_t mask; struct sigsave ss_CLAIM, ss_YIELD; svsignal(SIGYIELD, &ss_YIELD); svsignal(SIGCLAIM, &ss_CLAIM); if(pri == PRI_HIGH) ssignal(SIGCLAIM, SIG_IGN, 0); else atsignal(SIGCLAIM, 0) { sigaddset(&mask, SIGYIELD); sigprocmask(SIG_BLOCK, &mask, NULL); syslog(LOG_WARNING, "concurrent claim has piority"); ss_CLAIM.ss_blk = FALSE; rssignal(SIGCLAIM, &ss_CLAIM); rssignal(SIGYIELD, &ss_YIELD); kill(getpid(), SIGCLAIM); } atsignal(SIGYIELD, 0) { DBG(syslog(LOG_DEBUG, "the line is free")); dsignal(SIGCLAIM); rssignal(SIGCLAIM, &ss_CLAIM); rssignal(SIGYIELD, &ss_YIELD); return SUCCESS; } while(TRUE) { if(kill(pid, SIGCLAIM) == FAIL) { syslog(LOG_WARNING, "no concurrent process %d", pid); dsignal(SIGCLAIM); rssignal(SIGCLAIM, &ss_CLAIM); rssignal(SIGYIELD, &ss_YIELD); return FAIL; } usleep(CLAIM_SLEEP_TIMER); } } void wait_line() { sigset_t mask; sigprocmask(SIG_SETMASK, NULL, &mask); sigdelset(&mask, SIGYIELD); while(TRUE) sigsuspend(&mask); }