home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / md / _rhapsody.h < prev    next >
C/C++ Source or Header  |  1998-11-02  |  6KB  |  206 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef nspr_rhapsody_defs_h___
  20. #define nspr_rhapsody_defs_h___
  21.  
  22. #include "prthread.h"
  23.  
  24. #include <sys/syscall.h>
  25.  
  26. #define PR_LINKER_ARCH    "rhapsody"
  27. #define _PR_SI_SYSNAME  "RHAPSODY"
  28. #ifdef i386
  29. #define _PR_SI_ARCHITECTURE "x86"
  30. #else
  31. #define _PR_SI_ARCHITECTURE "ppc"
  32. #endif
  33. #define PR_DLL_SUFFIX        ".dylib"
  34.  
  35. #define _PR_VMBASE              0x30000000
  36. #define _PR_STACK_VMBASE    0x50000000
  37. #define _MD_DEFAULT_STACK_SIZE    65536L
  38. #define _MD_MMAP_FLAGS          MAP_PRIVATE
  39.  
  40. #undef  HAVE_STACK_GROWING_UP
  41. #define HAVE_DLL
  42. #define _PR_HAVE_SOCKADDR_LEN  
  43. #define _PR_STAT_HAS_ST_ATIMESPEC
  44. #define _PR_TIMESPEC_HAS_TS_SEC
  45. #define _PR_NO_LARGE_FILES
  46.  
  47. #define USE_SETJMP
  48.  
  49. #if !defined(_PR_PTHREADS)
  50.  
  51. #include <setjmp.h>
  52.  
  53. #define PR_CONTEXT_TYPE    jmp_buf
  54.  
  55. #define CONTEXT(_th)       ((_th)->md.context)
  56. #define _MD_GET_SP(_th)    (((struct sigcontext *) (_th)->md.context)->sc_onstack)
  57. #define PR_NUM_GCREGS        _JBLEN
  58.  
  59. /*
  60. ** Initialize a thread context to run "_main()" when started
  61. */
  62. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
  63. {  \
  64.     *status = PR_TRUE;  \
  65.     if (setjmp(CONTEXT(_thread))) {  \
  66.         _main();  \
  67.     }  \
  68.     _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
  69. }
  70.  
  71. #define _MD_SWITCH_CONTEXT(_thread)  \
  72.     if (!setjmp(CONTEXT(_thread))) {  \
  73.     (_thread)->md.errcode = errno;  \
  74.     _PR_Schedule();  \
  75.     }
  76.  
  77. /*
  78. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  79. */
  80. #define _MD_RESTORE_CONTEXT(_thread) \
  81. {   \
  82.     errno = (_thread)->md.errcode;  \
  83.     _MD_SET_CURRENT_THREAD(_thread);  \
  84.     longjmp(CONTEXT(_thread), 1);  \
  85. }
  86.  
  87. /* Machine-dependent (MD) data structures */
  88.  
  89. struct _MDThread {
  90.     PR_CONTEXT_TYPE context;
  91.     int id;
  92.     int errcode;
  93. };
  94.  
  95. struct _MDThreadStack {
  96.     PRInt8 notused;
  97. };
  98.  
  99. struct _MDLock {
  100.     PRInt8 notused;
  101. };
  102.  
  103. struct _MDSemaphore {
  104.     PRInt8 notused;
  105. };
  106.  
  107. struct _MDCVar {
  108.     PRInt8 notused;
  109. };
  110.  
  111. struct _MDSegment {
  112.     PRInt8 notused;
  113. };
  114.  
  115. /*
  116.  * md-specific cpu structure field
  117.  */
  118. #define _PR_MD_MAX_OSFD FD_SETSIZE
  119.  
  120. struct _MDCPU_Unix {
  121.     PRCList ioQ;
  122.     PRUint32 ioq_timeout;
  123.     PRInt32 ioq_max_osfd;
  124.     PRInt32 ioq_osfd_cnt;
  125. #ifndef _PR_USE_POLL
  126.     fd_set fd_read_set, fd_write_set, fd_exception_set;
  127.     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  128.                 fd_exception_cnt[_PR_MD_MAX_OSFD];
  129. #else
  130.     struct pollfd *ioq_pollfds;
  131.     int ioq_pollfds_size;
  132. #endif    /* _PR_USE_POLL */
  133. };
  134.  
  135. #define _PR_IOQ(_cpu)            ((_cpu)->md.md_unix.ioQ)
  136. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  137. #define _PR_FD_READ_SET(_cpu)        ((_cpu)->md.md_unix.fd_read_set)
  138. #define _PR_FD_READ_CNT(_cpu)        ((_cpu)->md.md_unix.fd_read_cnt)
  139. #define _PR_FD_WRITE_SET(_cpu)        ((_cpu)->md.md_unix.fd_write_set)
  140. #define _PR_FD_WRITE_CNT(_cpu)        ((_cpu)->md.md_unix.fd_write_cnt)
  141. #define _PR_FD_EXCEPTION_SET(_cpu)    ((_cpu)->md.md_unix.fd_exception_set)
  142. #define _PR_FD_EXCEPTION_CNT(_cpu)    ((_cpu)->md.md_unix.fd_exception_cnt)
  143. #define _PR_IOQ_TIMEOUT(_cpu)        ((_cpu)->md.md_unix.ioq_timeout)
  144. #define _PR_IOQ_MAX_OSFD(_cpu)        ((_cpu)->md.md_unix.ioq_max_osfd)
  145. #define _PR_IOQ_OSFD_CNT(_cpu)        ((_cpu)->md.md_unix.ioq_osfd_cnt)
  146. #define _PR_IOQ_POLLFDS(_cpu)        ((_cpu)->md.md_unix.ioq_pollfds)
  147. #define _PR_IOQ_POLLFDS_SIZE(_cpu)    ((_cpu)->md.md_unix.ioq_pollfds_size)
  148.  
  149. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
  150.  
  151. struct _MDCPU {
  152.     struct _MDCPU_Unix md_unix;
  153. };
  154.  
  155. #define _MD_INIT_LOCKS()
  156. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  157. #define _MD_FREE_LOCK(lock)
  158. #define _MD_LOCK(lock)
  159. #define _MD_UNLOCK(lock)
  160. #define _MD_INIT_IO()
  161. #define _MD_IOQ_LOCK()
  162. #define _MD_IOQ_UNLOCK()
  163.  
  164. extern PRStatus _MD_InitializeThread(PRThread *thread);
  165.  
  166. #define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
  167. #define _MD_INIT_THREAD                 _MD_InitializeThread
  168. #define _MD_EXIT_THREAD(thread)
  169. #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
  170. #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
  171. #define _MD_CLEAN_THREAD(_thread)
  172.  
  173. extern PRStatus _MD_CREATE_THREAD(
  174.     PRThread *thread,
  175.     void (*start) (void *),
  176.     PRThreadPriority priority,
  177.     PRThreadScope scope,
  178.     PRThreadState state,
  179.     PRUint32 stackSize);
  180. extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
  181. extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
  182. extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
  183. extern void _MD_YIELD(void);
  184.  
  185. #endif /* ! _PR_PTHREADS */
  186.  
  187. #define _MD_EARLY_INIT          _MD_EarlyInit
  188. #define _MD_FINAL_INIT            _PR_UnixInit
  189. #define _MD_GET_INTERVAL        _PR_UNIX_GetInterval
  190. #define _MD_INTERVAL_PER_SEC    _PR_UNIX_TicksPerSecond
  191.  
  192. extern void             _MD_EarlyInit(void);
  193. extern PRIntervalTime   _PR_UNIX_GetInterval(void);
  194. extern PRIntervalTime   _PR_UNIX_TicksPerSecond(void);
  195.  
  196. /*
  197.  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
  198.  * unwrapped version.
  199.  */
  200. #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
  201.  
  202. /* For writev() */
  203. #include <sys/uio.h>
  204.  
  205. #endif /* nspr_rhapsody_defs_h___ */
  206.