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>
26 #if defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
31 PRE_InitPreempt(struct timeval *slice)
45 #ifdef HAVE_UCONTEXT_H
49 #if defined(AFS_OSF_ENV) || defined(AFS_S390_LINUX20_ENV)
50 int PRE_Block = 0; /* used in lwp.c and process.s */
52 char PRE_Block = 0; /* used in lwp.c and process.s */
55 #if HAVE_SIGACTION && defined(SA_SIGINFO)
57 AlarmHandler(int sig, siginfo_t *st, ucontext_t *scp)
60 AlarmHandler(int sig, int code, struct sigcontext *scp)
63 if (PRE_Block == 0 && lwp_cpptr->level == 0) {
65 #if HAVE_SIGACTION && defined(SA_SIGINFO)
66 sigprocmask(SIG_SETMASK, &scp->uc_sigmask, NULL);
68 sigsetmask(scp->sc_mask);
70 LWP_DispatchProcess();
77 PRE_InitPreempt(struct timeval *slice)
80 #if HAVE_SIGACTION && defined(SA_SIGINFO)
81 struct sigaction action;
90 itv.it_interval.tv_sec = itv.it_value.tv_sec = DEFAULTSLICE;
91 itv.it_interval.tv_usec = itv.it_value.tv_usec = 0;
93 itv.it_interval = itv.it_value = *slice;
96 #if HAVE_SIGACTION && defined(SA_SIGINFO)
97 memset((char *)&action, 0, sizeof(action));
98 action.sa_sigaction = AlarmHandler;
99 action.sa_flags = SA_SIGINFO;
101 if ((sigaction(SIGALRM, &action, NULL) == -1)
102 || (setitimer(ITIMER_REAL, &itv, NULL) == -1))
103 return (LWP_ESYSTEM);
105 memset((char *)&vec, 0, sizeof(vec));
106 vec.sv_handler = AlarmHandler;
107 vec.sv_mask = vec.sv_onstack = 0;
109 if ((sigvec(SIGALRM, &vec, (struct sigvec *)0) == -1)
110 || (setitimer(ITIMER_REAL, &itv, (struct itimerval *)0) == -1))
111 return (LWP_ESYSTEM);
114 return (LWP_SUCCESS);
120 struct itimerval itv;
121 #if HAVE_SIGACTION && defined(SA_SIGINFO)
122 struct sigaction action;
130 itv.it_value.tv_sec = itv.it_value.tv_usec = 0;
132 #if HAVE_SIGACTION && defined(SA_SIGINFO)
133 memset((char *)&action, 0, sizeof(action));
134 action.sa_handler = SIG_DFL;
136 if ((setitimer(ITIMER_REAL, &itv, NULL) == -1)
137 || (sigaction(SIGALRM, &action, NULL) == -1))
138 return (LWP_ESYSTEM);
141 memset((char *)&vec, 0, sizeof(vec));
142 vec.sv_handler = SIG_DFL;
143 vec.sv_mask = vec.sv_onstack = 0;
145 if ((setitimer(ITIMER_REAL, &itv, (struct itimerval *)0) == -1)
146 || (sigvec(SIGALRM, &vec, (struct sigvec *)0) == -1))
147 return (LWP_ESYSTEM);
149 return (LWP_SUCCESS);
152 #endif /* AFS_LINUX20_ENV */