engine-alpha-osf1.c
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:5k
源码类别:

MySQL数据库

开发平台:

Visual C++

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