OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [gdb/] [testsuite/] [gdb.base/] [sigrepeat.c] - Diff between revs 227 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 227 Rev 816
/* This testcase is part of GDB, the GNU debugger.
/* This testcase is part of GDB, the GNU debugger.
 
 
   Copyright 2004, 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
   Copyright 2004, 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 
   This program is free software; you can redistribute it and/or modify
   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
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
*/
*/
 
 
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <signal.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/time.h>
 
 
static volatile int done[2];
static volatile int done[2];
static volatile int repeats[2];
static volatile int repeats[2];
static int itimer[2] = { ITIMER_REAL, ITIMER_VIRTUAL };
static int itimer[2] = { ITIMER_REAL, ITIMER_VIRTUAL };
static int alarm[2] = { SIGALRM, SIGVTALRM };
static int alarm[2] = { SIGALRM, SIGVTALRM };
 
 
static void
static void
handler (int sig)
handler (int sig)
{
{
  int sigi;
  int sigi;
  switch (sig)
  switch (sig)
    {
    {
    case SIGALRM: sigi = 0; break;
    case SIGALRM: sigi = 0; break;
    case SIGVTALRM: sigi = 1; break;
    case SIGVTALRM: sigi = 1; break;
    default: abort ();
    default: abort ();
    }
    }
  if (repeats[sigi]++ > 3)
  if (repeats[sigi]++ > 3)
    {
    {
      /* Hit with enough signals, cancel everything and get out.  */
      /* Hit with enough signals, cancel everything and get out.  */
      {
      {
        struct itimerval itime;
        struct itimerval itime;
        memset (&itime, 0, sizeof (itime));
        memset (&itime, 0, sizeof (itime));
        setitimer (itimer[sigi], &itime, NULL);
        setitimer (itimer[sigi], &itime, NULL);
      }
      }
      {
      {
        struct sigaction action;
        struct sigaction action;
        memset (&action, 0, sizeof (action));
        memset (&action, 0, sizeof (action));
        action.sa_handler = SIG_IGN;
        action.sa_handler = SIG_IGN;
        sigaction (sig, &action, NULL);
        sigaction (sig, &action, NULL);
      }
      }
      done[sigi] = 1;
      done[sigi] = 1;
      return;
      return;
    }
    }
  /* Set up a nested virtual timer.  */
  /* Set up a nested virtual timer.  */
  while (1)
  while (1)
    {
    {
      /* Wait until a signal has become pending, that way when this
      /* Wait until a signal has become pending, that way when this
         handler returns it will be immediatly delivered leading to
         handler returns it will be immediatly delivered leading to
         back-to-back signals.  */
         back-to-back signals.  */
      sigset_t set;
      sigset_t set;
      sigemptyset (&set);
      sigemptyset (&set);
      if (sigpending (&set) < 0)
      if (sigpending (&set) < 0)
        {
        {
          perror ("sigrepeat");
          perror ("sigrepeat");
          abort ();
          abort ();
        }
        }
      if (sigismember (&set, sig))
      if (sigismember (&set, sig))
        break;
        break;
    }
    }
} /* handler */
} /* handler */
 
 
int
int
main ()
main ()
{
{
  int i;
  int i;
  /* Set up the signal handler.  */
  /* Set up the signal handler.  */
  for (i = 0; i < 2; i++)
  for (i = 0; i < 2; i++)
    {
    {
      struct sigaction action;
      struct sigaction action;
      memset (&action, 0, sizeof (action));
      memset (&action, 0, sizeof (action));
      action.sa_handler = handler;
      action.sa_handler = handler;
      sigaction (alarm[i], &action, NULL);
      sigaction (alarm[i], &action, NULL);
    }
    }
 
 
  /* Set up a rapidly repeating timers.  A timer, rather than SIGSEGV,
  /* Set up a rapidly repeating timers.  A timer, rather than SIGSEGV,
     is used as after a timer handler returns the interrupted code can
     is used as after a timer handler returns the interrupted code can
     safely resume.  The intent is for the program to swamp GDB with a
     safely resume.  The intent is for the program to swamp GDB with a
     backlog of pending signals.  */
     backlog of pending signals.  */
  for (i = 0; i < 2; i++)
  for (i = 0; i < 2; i++)
    {
    {
      struct itimerval itime;
      struct itimerval itime;
      memset (&itime, 0, sizeof (itime));
      memset (&itime, 0, sizeof (itime));
      itime.it_interval.tv_usec = 1;
      itime.it_interval.tv_usec = 1;
      itime.it_value.tv_usec = 250 * 1000;
      itime.it_value.tv_usec = 250 * 1000;
      setitimer (itimer[i], &itime, NULL);
      setitimer (itimer[i], &itime, NULL);
    }
    }
 
 
  /* Wait.  */
  /* Wait.  */
  while (!done[0] && !done[1]); /* infinite loop */
  while (!done[0] && !done[1]); /* infinite loop */
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.