~mysql/mysql-server/mysql-6.0

« back to all changes in this revision

Viewing changes to mit-pthreads/machdep/engine-alpha-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 NetBSD/Alpha 1.1(+)
 
5
 *
 
6
 *      1.00 93/08/04 proven
 
7
 *      -Started coding this file.
 
8
 *
 
9
 *      95/04/22 cgd
 
10
 *      -Modified to make it go with NetBSD/Alpha
 
11
 */
 
12
 
 
13
#ifndef lint
 
14
static const char rcsid[] = "engine-alpha-osf1.c,v 1.4.4.1 1995/12/13 05:41:37 proven Exp";
 
15
#endif
 
16
 
 
17
#include <pthread.h>
 
18
#include <sys/types.h>
 
19
#include <sys/socket.h>
 
20
#include <sys/syscall.h>
 
21
#include <stdlib.h>
 
22
#include <fcntl.h>
 
23
#include <stdio.h>
 
24
 
 
25
/* ==========================================================================
 
26
 * machdep_save_state()
 
27
 */
 
28
int machdep_save_state(void)
 
29
{
 
30
  return __machdep_save_int_state(pthread_run->machdep_data.machdep_istate);
 
31
}
 
32
 
 
33
void machdep_restore_state(void)
 
34
{
 
35
  __machdep_restore_int_state(pthread_run->machdep_data.machdep_istate);
 
36
}
 
37
 
 
38
void machdep_save_float_state (void)
 
39
{
 
40
  __machdep_save_fp_state(pthread_run->machdep_data.machdep_fstate);
 
41
}
 
42
 
 
43
void machdep_restore_float_state (void)
 
44
{
 
45
  __machdep_restore_fp_state(pthread_run->machdep_data.machdep_fstate);
 
46
}
 
47
 
 
48
/* ==========================================================================
 
49
 * machdep_set_thread_timer()
 
50
 */
 
51
void machdep_set_thread_timer(struct machdep_pthread *machdep_pthread)
 
52
{
 
53
    if (setitimer(ITIMER_VIRTUAL, &(machdep_pthread->machdep_timer), NULL)) {
 
54
        PANIC();
 
55
    }
 
56
}
 
57
 
 
58
/* ==========================================================================
 
59
 * machdep_unset_thread_timer()
 
60
 */
 
61
void machdep_unset_thread_timer(struct machdep_pthread *machdep_pthread)
 
62
{
 
63
    struct itimerval zeroval = { { 0, 0 }, { 0, 0} };
 
64
 
 
65
    if (setitimer(ITIMER_VIRTUAL, &zeroval, NULL)) {
 
66
        PANIC();
 
67
    }
 
68
}
 
69
 
 
70
/* ==========================================================================
 
71
 * machdep_pthread_cleanup()
 
72
 */
 
73
void *machdep_pthread_cleanup(struct machdep_pthread *machdep_pthread)
 
74
{
 
75
    return(machdep_pthread->machdep_stack);
 
76
}
 
77
 
 
78
/* ==========================================================================
 
79
 * machdep_pthread_start()
 
80
 */
 
81
void machdep_pthread_start(void)
 
82
{
 
83
        context_switch_done();
 
84
        pthread_sched_resume ();
 
85
 
 
86
    /* Run current threads start routine with argument */
 
87
    pthread_exit(pthread_run->machdep_data.start_routine
 
88
      (pthread_run->machdep_data.start_argument));
 
89
 
 
90
    /* should never reach here */
 
91
    PANIC();
 
92
}
 
93
 
 
94
/* ==========================================================================
 
95
 * __machdep_stack_free()
 
96
 */
 
97
void __machdep_stack_free(void * stack)
 
98
{
 
99
    free(stack);
 
100
}
 
101
 
 
102
/* ==========================================================================
 
103
 * __machdep_stack_alloc()
 
104
 */
 
105
void * __machdep_stack_alloc(size_t size)
 
106
{
 
107
    void * stack;
 
108
 
 
109
    return(malloc(size));
 
110
}
 
111
 
 
112
/* ==========================================================================
 
113
 * __machdep_pthread_create()
 
114
 */
 
115
void __machdep_pthread_create(struct machdep_pthread *machdep_pthread,
 
116
  void *(* start_routine)(), void *start_argument, 
 
117
  long stack_size, long nsec, long flags)
 
118
{
 
119
    machdep_pthread->start_routine = start_routine;
 
120
    machdep_pthread->start_argument = start_argument;
 
121
 
 
122
    machdep_pthread->machdep_timer.it_value.tv_sec = 0;
 
123
    machdep_pthread->machdep_timer.it_interval.tv_sec = 0;
 
124
    machdep_pthread->machdep_timer.it_interval.tv_usec = 0;
 
125
    machdep_pthread->machdep_timer.it_value.tv_usec = nsec / 1000;
 
126
 
 
127
    /* Set up new stack frame so that it looks like it returned from a
 
128
       longjmp() to the beginning of machdep_pthread_start().  */
 
129
    machdep_pthread->machdep_istate[8/*ISTATE_RA*/] = 0;
 
130
    machdep_pthread->machdep_istate[0/*ISTATE_PC*/] = (long)machdep_pthread_start;
 
131
    machdep_pthread->machdep_istate[10/*ISTATE_PV*/] = (long)machdep_pthread_start;
 
132
 
 
133
    /* Alpha stack starts high and builds down. */
 
134
    {
 
135
      long stk_addr = (long) machdep_pthread->machdep_stack;
 
136
      stk_addr += stack_size - 1024;
 
137
      stk_addr &= ~15;
 
138
      machdep_pthread->machdep_istate[9/*ISTATE_SP*/] = stk_addr;
 
139
    }
 
140
}
 
141
 
 
142
int safe_store (loc, new)
 
143
     int *loc;
 
144
     int new;
 
145
{
 
146
  int locked, old;
 
147
  asm ("mb" : : : "memory");
 
148
  do {
 
149
    asm ("ldl_l %0,%1" : "=r" (old) : "m" (*loc));
 
150
    asm ("stl_c %0,%1" : "=r" (locked), "=m" (*loc) : "0" (new));
 
151
  } while (!locked);
 
152
  asm ("mb" : : : "memory");
 
153
  return old;
 
154
}
 
155
 
 
156
/* ==========================================================================
 
157
 * machdep_sys_creat()
 
158
 */
 
159
machdep_sys_creat(char * path, int mode)
 
160
{   
 
161
        return(machdep_sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode));
 
162
}   
 
163
 
 
164
/* ==========================================================================
 
165
 * machdep_sys_wait3()
 
166
 */  
 
167
machdep_sys_wait3(int * b, int c, int * d)
 
168
{    
 
169
        return(machdep_sys_wait4(0, b, c, d));
 
170
}   
 
171
 
 
172
/* ==========================================================================
 
173
 * machdep_sys_waitpid()
 
174
 */   
 
175
machdep_sys_waitpid(int a, int * b, int c)
 
176
{
 
177
        return(machdep_sys_wait4(a, b, c, NULL));
 
178
}
 
179
 
 
180
/* ==========================================================================
 
181
 * machdep_sys_getdtablesize()
 
182
 */
 
183
machdep_sys_getdtablesize()
 
184
{
 
185
        return(sysconf(_SC_OPEN_MAX));
 
186
}
 
187
 
 
188
/* ==========================================================================
 
189
 * machdep_sys_lseek()
 
190
 */
 
191
off_t machdep_sys_lseek(int fd, off_t offset, int whence)
 
192
{
 
193
        extern off_t __syscall();
 
194
 
 
195
        return(__syscall((quad_t)SYS_lseek, fd, 0, offset, whence));
 
196
}
 
197
 
 
198
/* ==========================================================================
 
199
 * machdep_sys_getdirentries()
 
200
 */
 
201
machdep_sys_getdirentries(int fd, char * buf, int len, int * seek)
 
202
{
 
203
        return(machdep_sys_getdents(fd, buf, len));
 
204
}