~mysql/mysql-server/mysql-6.0

« back to all changes in this revision

Viewing changes to mit-pthreads/machdep/engine-alpha-osf1.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
 
 
10
#ifndef lint
 
11
static const char rcsid[] = "$Id$";
 
12
#endif
 
13
 
 
14
#include <pthread.h>
 
15
#include <stdlib.h>
 
16
 
 
17
/* These would be defined in setjmp.h, if _POSIX_SOURCE and _XOPEN_SOURCE
 
18
   were both undefined.  But we've already included it, and lost the
 
19
   opportunity.  */
 
20
#define JB_PC    2
 
21
#define JB_RA   30
 
22
#define JB_PV   31
 
23
#define JB_SP   34
 
24
 
 
25
/* ==========================================================================
 
26
 * machdep_save_state()
 
27
 */
 
28
int machdep_save_state(void)
 
29
{
 
30
  return setjmp (pthread_run->machdep_data.machdep_state);
 
31
}
 
32
 
 
33
/* ==========================================================================
 
34
 * machdep_restore_state()
 
35
 */
 
36
extern void machdep_restore_from_setjmp (jmp_buf, long);
 
37
void machdep_restore_state(void)
 
38
{
 
39
  machdep_restore_from_setjmp (pthread_run->machdep_data.machdep_state, 1);
 
40
}
 
41
 
 
42
void machdep_save_float_state (void) { }
 
43
void machdep_restore_float_state (void) { }
 
44
 
 
45
/* ==========================================================================
 
46
 * machdep_set_thread_timer()
 
47
 */
 
48
void machdep_set_thread_timer(struct machdep_pthread *machdep_pthread)
 
49
{
 
50
    if (setitimer(ITIMER_VIRTUAL, &(machdep_pthread->machdep_timer), NULL)) {
 
51
        PANIC();
 
52
    }
 
53
}
 
54
 
 
55
/* ==========================================================================
 
56
 * machdep_unset_thread_timer()
 
57
 */
 
58
void machdep_unset_thread_timer(struct machdep_pthread *machdep_pthread)
 
59
{
 
60
    struct itimerval zeroval = { { 0, 0 }, { 0, 0} };
 
61
 
 
62
    if (setitimer(ITIMER_VIRTUAL, &zeroval, NULL)) {
 
63
        PANIC();
 
64
    }
 
65
}
 
66
 
 
67
/* ==========================================================================
 
68
 * machdep_pthread_cleanup()
 
69
 */
 
70
void *machdep_pthread_cleanup(struct machdep_pthread *machdep_pthread)
 
71
{
 
72
    return(machdep_pthread->machdep_stack);
 
73
}
 
74
 
 
75
/* ==========================================================================
 
76
 * machdep_pthread_start()
 
77
 */
 
78
void machdep_pthread_start(void)
 
79
{
 
80
        context_switch_done();
 
81
        pthread_sched_resume ();
 
82
 
 
83
    /* Run current threads start routine with argument */
 
84
    pthread_exit(pthread_run->machdep_data.start_routine
 
85
      (pthread_run->machdep_data.start_argument));
 
86
 
 
87
    /* should never reach here */
 
88
    PANIC();
 
89
}
 
90
 
 
91
/* ==========================================================================
 
92
 * __machdep_stack_free()
 
93
 */
 
94
void __machdep_stack_free(void * stack)
 
95
{
 
96
    free(stack);
 
97
}
 
98
 
 
99
/* ==========================================================================
 
100
 * __machdep_stack_alloc()
 
101
 */
 
102
void * __machdep_stack_alloc(size_t size)
 
103
{
 
104
    void * stack;
 
105
 
 
106
    return(malloc(size));
 
107
}
 
108
 
 
109
/* ==========================================================================
 
110
 * __machdep_pthread_create()
 
111
 */
 
112
void __machdep_pthread_create(struct machdep_pthread *machdep_pthread,
 
113
  void *(* start_routine)(), void *start_argument, 
 
114
  long stack_size, long nsec, long flags)
 
115
{
 
116
    machdep_pthread->start_routine = start_routine;
 
117
    machdep_pthread->start_argument = start_argument;
 
118
 
 
119
    machdep_pthread->machdep_timer.it_value.tv_sec = 0;
 
120
    machdep_pthread->machdep_timer.it_interval.tv_sec = 0;
 
121
    machdep_pthread->machdep_timer.it_interval.tv_usec = 0;
 
122
    machdep_pthread->machdep_timer.it_value.tv_usec = nsec / 1000;
 
123
 
 
124
    setjmp(machdep_pthread->machdep_state);
 
125
 
 
126
    /* Set up new stack frame so that it looks like it returned from a
 
127
       longjmp() to the beginning of machdep_pthread_start().  */
 
128
    machdep_pthread->machdep_state[JB_RA] = 0;
 
129
    machdep_pthread->machdep_state[JB_PC] = (long)machdep_pthread_start;
 
130
    machdep_pthread->machdep_state[JB_PV] = (long)machdep_pthread_start;
 
131
 
 
132
    /* Alpha stack starts high and builds down. */
 
133
    {
 
134
      long stk_addr = (long) machdep_pthread->machdep_stack;
 
135
      stk_addr += stack_size - 1024;
 
136
      stk_addr &= ~15;
 
137
      machdep_pthread->machdep_state[JB_SP] = stk_addr;
 
138
    }
 
139
}
 
140
 
 
141
/* ==========================================================================
 
142
 * machdep_sys_wait3()
 
143
 */
 
144
machdep_sys_wait3(int * b, int c, int * d)
 
145
{
 
146
  return(machdep_sys_wait4(0, b, c, d));
 
147
}
 
148
 
 
149
/* ==========================================================================
 
150
 * machdep_sys_waitpid()
 
151
 */
 
152
machdep_sys_waitpid(int pid, int * statusp, int options)
 
153
{
 
154
  return machdep_sys_wait4 (pid, statusp, options, NULL);
 
155
}
 
156
 
 
157
/* These are found in flsbuf.o in the Alpha libc.  I don't know what
 
158
   they're for, precisely.  */
 
159
static xxx;
 
160
_bufsync (p)
 
161
     char *p;
 
162
{
 
163
  long a1 = *(long *)(p+48);
 
164
  long t0 = *(long *)(p+8);
 
165
  long v0 = a1 - t0;
 
166
  long t1, t2;
 
167
 
 
168
  abort ();
 
169
 
 
170
  v0 += xxx;
 
171
  if (v0 < 0)
 
172
    {
 
173
      *(char**)(p + 8) = p;
 
174
      return v0;
 
175
    }
 
176
  t1 = *(int*)p;
 
177
  t2 = v0 - t1;
 
178
  if (t2 < 0)
 
179
    *(int*)p = (int) v0;
 
180
  return v0;
 
181
}
 
182
 
 
183
_findbuf () { abort (); }
 
184
_wrtchk () { abort (); }
 
185
_xflsbuf () { abort (); }
 
186
_flsbuf () { abort (); }
 
187
 
 
188
void __xxx_never_called () {
 
189
  /* Force other stuff to get dragged in.  */
 
190
  _cleanup ();
 
191
  fflush (NULL);
 
192
  fclose (NULL);
 
193
}
 
194
 
 
195
int safe_store (loc, new)
 
196
     int *loc;
 
197
     int new;
 
198
{
 
199
  int locked, old;
 
200
  asm ("mb" : : : "memory");
 
201
  do {
 
202
    asm ("ldl_l %0,%1" : "=r" (old) : "m" (*loc));
 
203
    asm ("stl_c %0,%1" : "=r" (locked), "=m" (*loc) : "0" (new));
 
204
  } while (!locked);
 
205
  asm ("mb" : : : "memory");
 
206
  return old;
 
207
}