2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /*******************************************************************\
12 * Information Technology Center *
13 * Carnegie-Mellon University *
15 \*******************************************************************/
16 #include <afsconfig.h>
17 #include <afs/param.h>
25 #if defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
30 PRE_InitPreempt(struct timeval *slice)
42 #ifdef HAVE_UCONTEXT_H
46 #if defined(AFS_OSF_ENV) || defined(AFS_S390_LINUX20_ENV)
47 int PRE_Block = 0; /* used in lwp.c and process.s */
49 char PRE_Block = 0; /* used in lwp.c and process.s */
52 #if HAVE_SIGACTION && defined(SA_SIGINFO)
54 AlarmHandler(int sig, siginfo_t *st, ucontext_t *scp)
57 AlarmHandler(int sig, int code, struct sigcontext *scp)
60 if (PRE_Block == 0 && lwp_cpptr->level == 0) {
62 #if HAVE_SIGACTION && defined(SA_SIGINFO)
63 sigprocmask(SIG_SETMASK, &scp->uc_sigmask, NULL);
65 sigsetmask(scp->sc_mask);
67 LWP_DispatchProcess();
74 PRE_InitPreempt(struct timeval *slice)
77 #if HAVE_SIGACTION && defined(SA_SIGINFO)
78 struct sigaction action;
87 itv.it_interval.tv_sec = itv.it_value.tv_sec = DEFAULTSLICE;
88 itv.it_interval.tv_usec = itv.it_value.tv_usec = 0;
90 itv.it_interval = itv.it_value = *slice;
93 #if HAVE_SIGACTION && defined(SA_SIGINFO)
94 memset(&action, 0, sizeof(action));
95 action.sa_sigaction = AlarmHandler;
96 action.sa_flags = SA_SIGINFO;
98 if ((sigaction(SIGALRM, &action, NULL) == -1)
99 || (setitimer(ITIMER_REAL, &itv, NULL) == -1))
100 return (LWP_ESYSTEM);
102 memset(&vec, 0, sizeof(vec));
103 vec.sv_handler = AlarmHandler;
104 vec.sv_mask = vec.sv_onstack = 0;
106 if ((sigvec(SIGALRM, &vec, (struct sigvec *)0) == -1)
107 || (setitimer(ITIMER_REAL, &itv, (struct itimerval *)0) == -1))
108 return (LWP_ESYSTEM);
111 return (LWP_SUCCESS);
117 struct itimerval itv;
118 #if HAVE_SIGACTION && defined(SA_SIGINFO)
119 struct sigaction action;
127 itv.it_value.tv_sec = itv.it_value.tv_usec = 0;
129 #if HAVE_SIGACTION && defined(SA_SIGINFO)
130 memset(&action, 0, sizeof(action));
131 action.sa_handler = SIG_DFL;
133 if ((setitimer(ITIMER_REAL, &itv, NULL) == -1)
134 || (sigaction(SIGALRM, &action, NULL) == -1))
135 return (LWP_ESYSTEM);
138 memset(&vec, 0, sizeof(vec));
139 vec.sv_handler = SIG_DFL;
140 vec.sv_mask = vec.sv_onstack = 0;
142 if ((setitimer(ITIMER_REAL, &itv, (struct itimerval *)0) == -1)
143 || (sigvec(SIGALRM, &vec, (struct sigvec *)0) == -1))
144 return (LWP_ESYSTEM);
146 return (LWP_SUCCESS);
149 #endif /* AFS_LINUX20_ENV */