~mysql/mysql-server/mysql-6.0

« back to all changes in this revision

Viewing changes to mit-pthreads/machdep/engine-sparc-netbsd-1.3.c

  • Committer: bk at mysql
  • Date: 2000-07-31 19:29:14 UTC
  • Revision ID: sp1r-bk@work.mysql.com-20000731192914-08846
Import changeset

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ==== machdep.c ============================================================
 
2
 * Copyright (c) 1993, 1994 Chris Provenzano, proven@athena.mit.edu
 
3
 *
 
4
 * Description : Machine dependent functions for SunOS-4.1.3 on sparc
 
5
 *
 
6
 *      1.00 93/08/04 proven
 
7
 *      -Started coding this file.
 
8
 *
 
9
 *      98/10/22 bad
 
10
 *      -update for fat sigset_t in NetBSD 1.3H
 
11
 */
 
12
 
 
13
#ifndef lint
 
14
static const char rcsid[] = "$Id$";
 
15
#endif
 
16
 
 
17
#include "config.h"
 
18
#include <pthread.h>
 
19
#include <stdlib.h>
 
20
#include <errno.h>
 
21
 
 
22
/* ==========================================================================
 
23
 * machdep_save_state()
 
24
 */
 
25
int machdep_save_state(void)
 
26
{
 
27
        /* Save register windows onto stackframe */
 
28
        __asm__ ("ta 3");
 
29
 
 
30
    return(setjmp(pthread_run->machdep_data.machdep_state));
 
31
}
 
32
 
 
33
/* ==========================================================================
 
34
 * machdep_restore_state()
 
35
 */
 
36
void machdep_restore_state(void)
 
37
{
 
38
    longjmp(pthread_run->machdep_data.machdep_state, 1);
 
39
}
 
40
/* ==========================================================================
 
41
 * machdep_save_float_state()
 
42
 */
 
43
void machdep_save_float_state(struct pthread * pthread)
 
44
{
 
45
        return;
 
46
}
 
47
 
 
48
/* ==========================================================================
 
49
 * machdep_restore_float_state()
 
50
 */
 
51
void machdep_restore_float_state(void)
 
52
{
 
53
        return;
 
54
}
 
55
 
 
56
/* ==========================================================================
 
57
 * machdep_set_thread_timer()
 
58
 */
 
59
void machdep_set_thread_timer(struct machdep_pthread *machdep_pthread)
 
60
{
 
61
    if (setitimer(ITIMER_VIRTUAL, &(machdep_pthread->machdep_timer), NULL)) {
 
62
        PANIC();
 
63
    }
 
64
}
 
65
 
 
66
/* ==========================================================================
 
67
 * machdep_unset_thread_timer()
 
68
 */
 
69
void machdep_unset_thread_timer(struct machdep_pthread *machdep_pthread)
 
70
{
 
71
    struct itimerval zeroval = { { 0, 0 }, { 0, 0} };
 
72
 
 
73
    if (setitimer(ITIMER_VIRTUAL, &zeroval, NULL)) {
 
74
        PANIC();
 
75
    }
 
76
}
 
77
 
 
78
/* ==========================================================================
 
79
 * machdep_pthread_cleanup()
 
80
 */
 
81
void *machdep_pthread_cleanup(struct machdep_pthread *machdep_pthread)
 
82
{
 
83
    return(machdep_pthread->machdep_stack);
 
84
}
 
85
 
 
86
/* ==========================================================================
 
87
 * machdep_pthread_start()
 
88
 */
 
89
void machdep_pthread_start(void)
 
90
{
 
91
        context_switch_done();
 
92
        pthread_sched_resume ();
 
93
 
 
94
    /* Run current threads start routine with argument */
 
95
    pthread_exit(pthread_run->machdep_data.start_routine
 
96
      (pthread_run->machdep_data.start_argument));
 
97
 
 
98
    /* should never reach here */
 
99
    PANIC();
 
100
}
 
101
 
 
102
/* ==========================================================================
 
103
 * __machdep_stack_free()
 
104
 */
 
105
void __machdep_stack_free(void * stack)
 
106
{       
 
107
    free(stack);
 
108
}
 
109
 
 
110
/* ==========================================================================
 
111
 * __machdep_stack_alloc()
 
112
 */ 
 
113
void * __machdep_stack_alloc(size_t size)
 
114
{   
 
115
    void * stack;
 
116
    
 
117
    return(malloc(size));
 
118
}     
 
119
    
 
120
/* ==========================================================================
 
121
 * __machdep_pthread_create()
 
122
 */
 
123
void __machdep_pthread_create(struct machdep_pthread *machdep_pthread,
 
124
  void *(* start_routine)(), void *start_argument, 
 
125
  long stack_size, long nsec, long flags)
 
126
{
 
127
    machdep_pthread->start_routine = start_routine;
 
128
    machdep_pthread->start_argument = start_argument;
 
129
 
 
130
    machdep_pthread->machdep_timer.it_value.tv_sec = 0;
 
131
    machdep_pthread->machdep_timer.it_interval.tv_sec = 0;
 
132
    machdep_pthread->machdep_timer.it_interval.tv_usec = 0;
 
133
    machdep_pthread->machdep_timer.it_value.tv_usec = nsec / 1000;
 
134
 
 
135
        /* Save register windows onto stackframe */
 
136
        __asm__ ("ta 3");
 
137
 
 
138
        setjmp(machdep_pthread->machdep_state);
 
139
    /*
 
140
     * Set up new stact frame so that it looks like it
 
141
     * returned from a longjmp() to the beginning of
 
142
     * machdep_pthread_start().
 
143
     */
 
144
    machdep_pthread->machdep_state[3] = (int)machdep_pthread_start;
 
145
    machdep_pthread->machdep_state[4] = (int)machdep_pthread_start;
 
146
 
 
147
        /* Sparc stack starts high and builds down. */
 
148
    machdep_pthread->machdep_state[2] =
 
149
          (int)machdep_pthread->machdep_stack + stack_size - 1024; 
 
150
        machdep_pthread->machdep_state[2] &= ~7;
 
151
 
 
152
}
 
153
 
 
154
#if defined(HAVE_SYSCALL_GETDENTS)
 
155
/* ==========================================================================
 
156
 * machdep_sys_getdirentries()
 
157
 *
 
158
 * Always use getdents in place of getdirentries if possible --proven
 
159
 */
 
160
int machdep_sys_getdirentries(int fd, char * buf, int len, int * seek)
 
161
{
 
162
        return(machdep_sys_getdents(fd, buf, len));
 
163
}
 
164
#endif
 
165
 
 
166
/* ==========================================================================
 
167
 * machdep_sys_wait3()
 
168
 */
 
169
machdep_sys_wait3(int * b, int c, int * d)
 
170
{
 
171
        return(machdep_sys_wait4(0, b, c, d));
 
172
}
 
173
 
 
174
/* ==========================================================================
 
175
 * machdep_sys_waitpid()
 
176
 */
 
177
machdep_sys_waitpid(int pid, int * statusp, int options)
 
178
{
 
179
        if (pid == -1)
 
180
                pid = 0;
 
181
        else if (pid == 0)
 
182
                pid = - getpgrp ();
 
183
        return machdep_sys_wait4 (pid, statusp, options, NULL);
 
184
}
 
185
 
 
186
#if !defined(HAVE_SYSCALL_SIGPROCMASK) 
 
187
#if 0
 
188
/* ==========================================================================
 
189
 * machdep_sys_sigprocmask()
 
190
 * This isn't a real implementation; we can make the assumption that the
 
191
 * pthreads library is not using oset, and that it is always blocking or
 
192
 * unblocking all signals at once.
 
193
 */
 
194
int machdep_sys_sigprocmask(int how, const sigset_t *set, sigset_t *oset)
 
195
{
 
196
    switch(how) {
 
197
      case SIG_BLOCK:
 
198
        sigblock(*set);
 
199
        break;
 
200
      case SIG_UNBLOCK:
 
201
        sigsetmask(~*set);
 
202
        break;
 
203
      case SIG_SETMASK:
 
204
        sigsetmask(*set);
 
205
        break;
 
206
      default:
 
207
        return -EINVAL;
 
208
    }
 
209
    return(OK);
 
210
}
 
211
 
 
212
/* ==========================================================================
 
213
 * sigaction()
 
214
 *
 
215
 * Temporary until I do machdep_sys_sigaction()
 
216
 */
 
217
int sigaction(int sig, const struct sigaction *act, struct sigaction *oldact)
 
218
{
 
219
        return(sigvec(sig, (struct sigvec *)act, (struct sigvec *)oldact));
 
220
}
 
221
#endif
 
222
#endif
 
223
 
 
224
#if !defined(HAVE_SYSCALL_GETDTABLESIZE) 
 
225
/* ==========================================================================
 
226
 * machdep_sys_getdtablesize()
 
227
 */
 
228
machdep_sys_getdtablesize()
 
229
{
 
230
        return(sysconf(_SC_OPEN_MAX));
 
231
 
232
#endif