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>
24 #if defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
29 PRE_InitPreempt(struct timeval *slice)
43 #ifdef HAVE_UCONTEXT_H
47 #if defined(AFS_OSF_ENV) || defined(AFS_S390_LINUX20_ENV)
48 int PRE_Block = 0; /* used in lwp.c and process.s */
50 char PRE_Block = 0; /* used in lwp.c and process.s */
53 #if HAVE_SIGACTION && defined(SA_SIGINFO)
55 AlarmHandler(int sig, siginfo_t *st, ucontext_t *scp)
58 AlarmHandler(int sig, int code, struct sigcontext *scp)
61 if (PRE_Block == 0 && lwp_cpptr->level == 0) {
63 #if HAVE_SIGACTION && defined(SA_SIGINFO)
64 sigprocmask(SIG_SETMASK, &scp->uc_sigmask, NULL);
66 sigsetmask(scp->sc_mask);
68 LWP_DispatchProcess();
75 PRE_InitPreempt(struct timeval *slice)
78 #if HAVE_SIGACTION && defined(SA_SIGINFO)
79 struct sigaction action;
88 itv.it_interval.tv_sec = itv.it_value.tv_sec = DEFAULTSLICE;
89 itv.it_interval.tv_usec = itv.it_value.tv_usec = 0;
91 itv.it_interval = itv.it_value = *slice;
94 #if HAVE_SIGACTION && defined(SA_SIGINFO)
95 memset(&action, 0, sizeof(action));
96 action.sa_sigaction = AlarmHandler;
97 action.sa_flags = SA_SIGINFO;
99 if ((sigaction(SIGALRM, &action, NULL) == -1)
100 || (setitimer(ITIMER_REAL, &itv, NULL) == -1))
101 return (LWP_ESYSTEM);
103 memset(&vec, 0, sizeof(vec));
104 vec.sv_handler = AlarmHandler;
105 vec.sv_mask = vec.sv_onstack = 0;
107 if ((sigvec(SIGALRM, &vec, (struct sigvec *)0) == -1)
108 || (setitimer(ITIMER_REAL, &itv, (struct itimerval *)0) == -1))
109 return (LWP_ESYSTEM);
112 return (LWP_SUCCESS);
118 struct itimerval itv;
119 #if HAVE_SIGACTION && defined(SA_SIGINFO)
120 struct sigaction action;
128 itv.it_value.tv_sec = itv.it_value.tv_usec = 0;
130 #if HAVE_SIGACTION && defined(SA_SIGINFO)
131 memset(&action, 0, sizeof(action));
132 action.sa_handler = SIG_DFL;
134 if ((setitimer(ITIMER_REAL, &itv, NULL) == -1)
135 || (sigaction(SIGALRM, &action, NULL) == -1))
136 return (LWP_ESYSTEM);
139 memset(&vec, 0, sizeof(vec));
140 vec.sv_handler = SIG_DFL;
141 vec.sv_mask = vec.sv_onstack = 0;
143 if ((setitimer(ITIMER_REAL, &itv, (struct itimerval *)0) == -1)
144 || (sigvec(SIGALRM, &vec, (struct sigvec *)0) == -1))
145 return (LWP_ESYSTEM);
147 return (LWP_SUCCESS);
150 #endif /* AFS_LINUX20_ENV */