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

MySQL数据库

开发平台:

Visual C++

  1. /* ==== machdep.c ============================================================
  2.  * Copyright (c) 1995 Chris Provenzano, proven@athena.mit.edu
  3.  *
  4.  * Description : Machine dependent functions for IRIX-5.2 on the IP22
  5.  *
  6.  * 1.00 95/04/26 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 <errno.h>
  15. #include <fcntl.h>
  16. #include <unistd.h>
  17. #include <stdlib.h>
  18. /* ==========================================================================
  19.  * machdep_save_state()
  20.  */
  21. int machdep_save_state(void)
  22. {
  23.     return(setjmp(pthread_run->machdep_data.machdep_state));
  24. }
  25. /* ==========================================================================
  26.  * machdep_restore_state()
  27.  */
  28. void machdep_restore_state(void)
  29. {
  30.     longjmp(pthread_run->machdep_data.machdep_state, 1);
  31. }
  32. /* ==========================================================================
  33.  * machdep_set_thread_timer()
  34.  */
  35. void machdep_set_thread_timer(struct machdep_pthread *machdep_pthread)
  36. {
  37.     if (setitimer(ITIMER_VIRTUAL, &(machdep_pthread->machdep_timer), NULL)) {
  38.         PANIC();
  39.     }
  40. }
  41. /* ==========================================================================
  42.  * machdep_unset_thread_timer()
  43.  */
  44. void machdep_unset_thread_timer(struct machdep_pthread *machdep_pthread)
  45. {
  46.     struct itimerval zeroval = { { 0, 0 }, { 0, 0} };
  47.     if (setitimer(ITIMER_VIRTUAL, &zeroval, NULL)) {
  48.         PANIC();
  49.     }
  50. }
  51. /* ==========================================================================
  52.  * machdep_pthread_cleanup()
  53.  */
  54. void *machdep_pthread_cleanup(struct machdep_pthread *machdep_pthread)
  55. {
  56.     return(machdep_pthread->machdep_stack);
  57. }
  58. /* ==========================================================================
  59.  * machdep_pthread_start()
  60.  */
  61. void machdep_pthread_start(void)
  62. {
  63. context_switch_done();
  64. pthread_sched_resume();
  65.     /* Run current threads start routine with argument */
  66.     pthread_exit(pthread_run->machdep_data.start_routine
  67.       (pthread_run->machdep_data.start_argument));
  68.     /* should never reach here */
  69.     PANIC();
  70. }
  71. /* ==========================================================================
  72.  * __machdep_stack_free()
  73.  */
  74. void __machdep_stack_free(void * stack)
  75. {
  76.     free(stack);
  77. }
  78. /* ==========================================================================
  79.  * __machdep_stack_alloc()
  80.  */
  81. void * __machdep_stack_alloc(size_t size)
  82. {
  83.     void * stack;
  84.     return(malloc(size));
  85. }
  86. /* ==========================================================================
  87.  * __machdep_pthread_create()
  88.  */
  89. void __machdep_pthread_create(struct machdep_pthread *machdep_pthread,
  90.   void *(* start_routine)(), void *start_argument, 
  91.   long stack_size, long nsec, long flags)
  92. {
  93. int i;
  94.     machdep_pthread->start_routine = start_routine;
  95.     machdep_pthread->start_argument = start_argument;
  96.     machdep_pthread->machdep_timer.it_value.tv_sec = 0;
  97.     machdep_pthread->machdep_timer.it_interval.tv_sec = 0;
  98.     machdep_pthread->machdep_timer.it_interval.tv_usec = 0;
  99.     machdep_pthread->machdep_timer.it_value.tv_usec = nsec / 1000;
  100. if (setjmp(machdep_pthread->machdep_state)) {
  101. machdep_pthread_start();
  102. }
  103.     /*
  104.      * Set up new stact frame so that it looks like it
  105.      * returned from a longjmp() to the beginning of
  106.      * machdep_pthread_start().
  107.      */
  108.     /* IP22 stack starts high and builds down. */
  109.     machdep_pthread->machdep_state[JB_SP] =
  110.   (int)machdep_pthread->machdep_stack + stack_size - 1024; 
  111. machdep_pthread->machdep_state[JB_SP] &= ~7;
  112. memcpy((void *)machdep_pthread->machdep_state[JB_SP], 
  113.    (char *)(((int)&i) - 24), 32);
  114. }
  115. /* ==========================================================================
  116.  * machdep_sys_dup2()
  117.  */
  118. machdep_sys_dup2(int a, int b)
  119. {
  120.     machdep_sys_close(b);
  121.     machdep_sys_fcntl(a, F_DUPFD, b);
  122. }
  123. /* ==========================================================================
  124.  * machdep_sys_wait3()
  125.  */
  126. machdep_sys_wait3(int * b, int c, int * d)
  127. {
  128.         return(machdep_sys_waitsys(0, b, c, d));
  129. }
  130.  
  131. /* ==========================================================================
  132.  * machdep_sys_waitpid()
  133.  */
  134. machdep_sys_waitpid(int a, int * b, int c)
  135. {
  136.         return(machdep_sys_waitsys(a, b, c, NULL));
  137. }  
  138. struct stat;
  139. /* ==========================================================================
  140.  * _fxstat()
  141.  */
  142. int _fxstat(int __ver, int fd, struct stat *buf)
  143. {
  144.     int ret;
  145.     if ((ret = fd_lock(fd, FD_READ, NULL)) == OK) {
  146.         if ((ret = machdep_sys_fstat(fd_table[fd]->fd.i, buf)) < OK) {
  147.          SET_ERRNO(-ret);
  148.      }
  149.         fd_unlock(fd, FD_READ);
  150.     }
  151.     return(ret);
  152. }
  153. /* ==========================================================================
  154.  * _lxstat()
  155.  */
  156. int _lxstat(int __ver, const char * path, struct stat * buf)
  157. {
  158.     int ret;
  159.     if ((ret = machdep_sys_lstat(path, buf)) < OK) {
  160.         SET_ERRNO(-ret);
  161.     }
  162.     return(ret);
  163. }
  164. /* ==========================================================================
  165.  * _xstat()
  166.  */
  167. int _xstat(int __ver, const char * path, struct stat * buf)
  168. {
  169.     int ret;
  170.     if ((ret = machdep_sys_stat(path, buf)) < OK) {
  171.         SET_ERRNO(-ret);
  172.     }
  173.     return(ret);
  174. }
  175. /* ==========================================================================
  176.  * getdtablesize()
  177.  */
  178. machdep_sys_getdtablesize()
  179. {
  180.     return(sysconf(_SC_OPEN_MAX));
  181. }
  182. /* ==========================================================================
  183.  * machdep_sys_getdirentries()
  184.  */
  185. int machdep_sys_getdirentries(int fd, char * buf, int len, int * seek)
  186. {  
  187. int i;
  188. i = machdep_sys_getdents(fd, buf, len);
  189. return i;
  190. }