engine-sparc-sunos-4.1.3.c
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:6k
源码类别:

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