~ubuntu-branches/ubuntu/warty/openafs/warty

« back to all changes in this revision

Viewing changes to src/lwp/preempt.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2004-01-10 16:37:33 UTC
  • Revision ID: james.westby@ubuntu.com-20040110163733-jvr0n1uahshlb1uu
Tags: upstream-1.2.11
ImportĀ upstreamĀ versionĀ 1.2.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2000, International Business Machines Corporation and others.
 
3
 * All Rights Reserved.
 
4
 * 
 
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
 
8
 */
 
9
 
 
10
/*******************************************************************\
 
11
*                                                                   *
 
12
*       Information Technology Center                               *
 
13
*       Carnegie-Mellon University                                  *
 
14
*                                                                   *
 
15
\*******************************************************************/
 
16
#include <afsconfig.h>
 
17
#include <afs/param.h>
 
18
 
 
19
RCSID("$Header: /afs/sipb.mit.edu/project/openafs/debian/cvs/openafs/src/lwp/preempt.c,v 1.1.1.12 2002/09/26 19:06:55 hartmans Exp $");
 
20
 
 
21
 
 
22
#if defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) || defined(AFS_DJGPP_ENV)
 
23
int PRE_Block = 0;
 
24
#else
 
25
#include <sys/time.h>
 
26
#include <signal.h>
 
27
#ifdef HAVE_UCONTEXT_H
 
28
#include <ucontext.h>
 
29
#endif
 
30
#include "lwp.h"
 
31
#include "preempt.h"
 
32
 
 
33
#if defined(AFS_OSF_ENV) || defined(AFS_S390_LINUX20_ENV)
 
34
int PRE_Block = 0;              /* used in lwp.c and process.s */
 
35
#else
 
36
char PRE_Block = 0;             /* used in lwp.c and process.s */
 
37
#endif
 
38
 
 
39
#if HAVE_SIGACTION && defined(SA_SIGINFO)
 
40
static void AlarmHandler(sig, st, scp)
 
41
    int sig;
 
42
    siginfo_t *st;
 
43
    ucontext_t *scp;
 
44
#else
 
45
static void AlarmHandler(sig, code, scp)
 
46
    int sig, code;
 
47
    struct sigcontext *scp;
 
48
#endif
 
49
    {
 
50
    if (PRE_Block == 0 && lwp_cpptr->level == 0)
 
51
        {
 
52
        PRE_BeginCritical();
 
53
#if HAVE_SIGACTION && defined(SA_SIGINFO)
 
54
        sigprocmask(SIG_SETMASK, &scp->uc_sigmask, NULL);
 
55
#else
 
56
        sigsetmask(scp->sc_mask);
 
57
#endif
 
58
        LWP_DispatchProcess();
 
59
        PRE_EndCritical();
 
60
        }
 
61
    
 
62
    }
 
63
 
 
64
int PRE_InitPreempt(slice)
 
65
    struct timeval *slice;
 
66
    {
 
67
    struct itimerval itv;
 
68
#if HAVE_SIGACTION && defined(SA_SIGINFO)
 
69
    struct sigaction action;
 
70
#else
 
71
    struct sigvec vec;
 
72
#endif
 
73
 
 
74
    if (lwp_cpptr == 0) return (LWP_EINIT);
 
75
    
 
76
    if (slice == 0)
 
77
        {
 
78
        itv.it_interval.tv_sec = itv.it_value.tv_sec = DEFAULTSLICE;
 
79
        itv.it_interval.tv_usec = itv.it_value.tv_usec = 0;
 
80
        }
 
81
    else
 
82
        {
 
83
        itv.it_interval = itv.it_value = *slice;
 
84
        }
 
85
 
 
86
#if HAVE_SIGACTION && defined(SA_SIGINFO)
 
87
    memset((char *)&action, 0, sizeof(action));
 
88
    action.sa_sigaction = AlarmHandler;
 
89
    action.sa_flags = SA_SIGINFO;
 
90
 
 
91
    if ((sigaction(SIGALRM, &action, (struct sigaction *)0) == -1) ||
 
92
        (setitimer(ITIMER_REAL, &itv, (struct itimerval *) 0) == -1))
 
93
        return(LWP_ESYSTEM);
 
94
#else
 
95
    memset((char *)&vec, 0, sizeof(vec));
 
96
    vec.sv_handler = AlarmHandler;
 
97
    vec.sv_mask = vec.sv_onstack = 0;
 
98
 
 
99
    if ((sigvec(SIGALRM, &vec, (struct sigvec *)0) == -1) ||
 
100
        (setitimer(ITIMER_REAL, &itv, (struct itimerval *) 0) == -1))
 
101
        return(LWP_ESYSTEM);
 
102
#endif
 
103
 
 
104
    return(LWP_SUCCESS);
 
105
    }
 
106
 
 
107
int PRE_EndPreempt()
 
108
    {
 
109
    struct itimerval itv;
 
110
#if HAVE_SIGACTION && defined(SA_SIGINFO)
 
111
    struct sigaction action;
 
112
#else
 
113
    struct sigvec vec;
 
114
#endif
 
115
 
 
116
    if (lwp_cpptr == 0) return (LWP_EINIT);
 
117
    
 
118
    itv.it_value.tv_sec = itv.it_value.tv_usec = 0;
 
119
 
 
120
#if HAVE_SIGACTION && defined(SA_SIGINFO)
 
121
    memset((char *)&action, 0, sizeof(action));
 
122
    action.sa_handler = SIG_DFL;
 
123
 
 
124
    if ((setitimer(ITIMER_REAL, &itv, (struct itimerval *) 0) == -1) ||
 
125
        (sigaction(SIGALRM, &action, (struct sigaction *)0) == -1))
 
126
        return(LWP_ESYSTEM);
 
127
#else
 
128
    memset((char *)&vec, 0, sizeof(vec));
 
129
    vec.sv_handler = SIG_DFL;
 
130
    vec.sv_mask = vec.sv_onstack = 0;
 
131
 
 
132
    if ((setitimer(ITIMER_REAL, &itv, (struct itimerval *) 0) == -1) ||
 
133
        (sigvec(SIGALRM, &vec, (struct sigvec *)0) == -1))
 
134
        return(LWP_ESYSTEM);
 
135
#endif
 
136
 
 
137
    return(LWP_SUCCESS);
 
138
    }
 
139
 
 
140
#endif /* AFS_LINUX20_ENV */