home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / md / _aix.h < prev    next >
C/C++ Source or Header  |  1998-11-02  |  6KB  |  222 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_aix_defs_h___
  20. #define nspr_aix_defs_h___
  21.  
  22. #include <sys/types.h>
  23. #if defined(_PR_PTHREADS) || defined(PTHREADS_USER)
  24. #include <pthread.h>
  25. #endif
  26.  
  27. /*
  28.  * To pick up fd_set and the poll events.
  29.  */
  30. #include <sys/select.h>
  31. #include <sys/poll.h>
  32.  
  33. /*
  34.  * Internal configuration macros
  35.  */
  36.  
  37. #define PR_LINKER_ARCH          "aix"
  38. #define _PR_SI_SYSNAME            "AIX"
  39. #define _PR_SI_ARCHITECTURE        "rs6000"
  40. #define PR_DLL_SUFFIX            ".so"
  41.  
  42. #define _PR_VMBASE                 0x30000000
  43. #define _PR_STACK_VMBASE        0x50000000
  44. #define _MD_DEFAULT_STACK_SIZE    65536L
  45. #define _MD_MMAP_FLAGS            MAP_PRIVATE
  46.  
  47. #define NEED_TIME_R
  48. #undef  HAVE_STACK_GROWING_UP
  49. #undef    HAVE_WEAK_IO_SYMBOLS
  50. #undef    HAVE_WEAK_MALLOC_SYMBOLS
  51. #define    HAVE_DLL
  52. #define    USE_DLFCN
  53. #define _PR_HAVE_SOCKADDR_LEN
  54. #define _PR_POLL_AVAILABLE
  55. #define _PR_USE_POLL
  56. #define _PR_STAT_HAS_ONLY_ST_ATIME
  57.  
  58. /* Timer operations */
  59. #define AIX_TIMERS
  60. #if defined(AIX_TIMERS)
  61. extern PRIntervalTime _MD_AixGetInterval(void);
  62. #define _MD_GET_INTERVAL _MD_AixGetInterval
  63.  
  64. extern PRIntervalTime _MD_AixIntervalPerSec(void);
  65. #define _MD_INTERVAL_PER_SEC _MD_AixIntervalPerSec
  66.  
  67. #else  /* defined(AIX_TIMERS) */
  68. #define _MD_GET_INTERVAL        _PR_UNIX_GetInterval
  69. #define _MD_INTERVAL_PER_SEC    _PR_UNIX_TicksPerSecond
  70. #endif  /* defined(AIX_TIMERS) */
  71.  
  72. /* The atomic operations */
  73. #include <sys/atomic_op.h>
  74. #define _PR_HAVE_ATOMIC_OPS
  75. #define _PR_HAVE_ATOMIC_CAS
  76. #define _MD_INIT_ATOMIC()
  77. #define _MD_ATOMIC_INCREMENT(val)   ((PRInt32)fetch_and_add((atomic_p)val, 1) + 1)
  78. #define _MD_ATOMIC_ADD(ptr, val)   ((PRInt32)fetch_and_add((atomic_p)ptr, val) + val)
  79. #define _MD_ATOMIC_DECREMENT(val)   ((PRInt32)fetch_and_add((atomic_p)val, -1) - 1)
  80. #define _MD_ATOMIC_SET(val, newval) _AIX_AtomicSet(val, newval)
  81.  
  82. #define USE_SETJMP
  83.  
  84. #include <setjmp.h>
  85.  
  86. #define _MD_GET_SP(_t)                (_t)->md.jb[3]
  87. #define _MD_SET_THR_SP(_t, _sp)        ((_t)->md.jb[3] = (int) (_sp - 2 * 64))
  88. #define PR_NUM_GCREGS                _JBLEN
  89.  
  90. #define CONTEXT(_th)                 ((_th)->md.jb)
  91. #define SAVE_CONTEXT(_th)            _setjmp(CONTEXT(_th))
  92. #define GOTO_CONTEXT(_th)            _longjmp(CONTEXT(_th), 1)
  93.  
  94. #ifdef PTHREADS_USER
  95. #include "_nspr_pthread.h"
  96. #else
  97.  
  98. /*
  99. ** Initialize the thread context preparing it to execute _main.
  100. */
  101. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)          \
  102.     PR_BEGIN_MACRO                      \
  103.         *status = PR_TRUE;              \
  104.     if (setjmp(CONTEXT(_thread))) {    \
  105.         (*_main)();            \
  106.     }                \
  107.     _MD_GET_SP(_thread) = (int) (_sp - 2 * 64);        \
  108.     PR_END_MACRO
  109.  
  110. #define _MD_SWITCH_CONTEXT(_thread)  \
  111.     if (!setjmp(CONTEXT(_thread))) { \
  112.     (_thread)->md.errcode = errno;  \
  113.     _PR_Schedule();             \
  114.     }
  115.  
  116. /*
  117. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  118. */
  119. #define _MD_RESTORE_CONTEXT(_thread) \
  120. {                     \
  121.     errno = (_thread)->md.errcode; \
  122.     _MD_SET_CURRENT_THREAD(_thread); \
  123.     longjmp(CONTEXT(_thread), 1); \
  124. }
  125.  
  126. /* Machine-dependent (MD) data structures */
  127.  
  128. struct _MDThread {
  129.     jmp_buf jb;
  130.     int id;
  131.     int errcode;
  132. };
  133.  
  134. struct _MDThreadStack {
  135.     PRInt8 notused;
  136. };
  137.  
  138. struct _MDLock {
  139.     PRInt8 notused;
  140. };
  141.  
  142. struct _MDSemaphore {
  143.     PRInt8 notused;
  144. };
  145.  
  146. struct _MDCVar {
  147.     PRInt8 notused;
  148. };
  149.  
  150. struct _MDSegment {
  151.     PRInt8 notused;
  152. };
  153.  
  154. /*
  155.  * md-specific cpu structure field
  156.  */
  157. #define _PR_MD_MAX_OSFD FD_SETSIZE
  158.  
  159. struct _MDCPU_Unix {
  160.     PRCList ioQ;
  161.     PRUint32 ioq_timeout;
  162.     PRInt32 ioq_max_osfd;
  163.     PRInt32 ioq_osfd_cnt;
  164. #ifndef _PR_USE_POLL
  165.     fd_set fd_read_set, fd_write_set, fd_exception_set;
  166.     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  167.                 fd_exception_cnt[_PR_MD_MAX_OSFD];
  168. #else
  169.     struct pollfd *ioq_pollfds;
  170.     int ioq_pollfds_size;
  171. #endif    /* _PR_USE_POLL */
  172. };
  173.  
  174. #define _PR_IOQ(_cpu)            ((_cpu)->md.md_unix.ioQ)
  175. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  176. #define _PR_FD_READ_SET(_cpu)        ((_cpu)->md.md_unix.fd_read_set)
  177. #define _PR_FD_READ_CNT(_cpu)        ((_cpu)->md.md_unix.fd_read_cnt)
  178. #define _PR_FD_WRITE_SET(_cpu)        ((_cpu)->md.md_unix.fd_write_set)
  179. #define _PR_FD_WRITE_CNT(_cpu)        ((_cpu)->md.md_unix.fd_write_cnt)
  180. #define _PR_FD_EXCEPTION_SET(_cpu)    ((_cpu)->md.md_unix.fd_exception_set)
  181. #define _PR_FD_EXCEPTION_CNT(_cpu)    ((_cpu)->md.md_unix.fd_exception_cnt)
  182. #define _PR_IOQ_TIMEOUT(_cpu)        ((_cpu)->md.md_unix.ioq_timeout)
  183. #define _PR_IOQ_MAX_OSFD(_cpu)        ((_cpu)->md.md_unix.ioq_max_osfd)
  184. #define _PR_IOQ_OSFD_CNT(_cpu)        ((_cpu)->md.md_unix.ioq_osfd_cnt)
  185. #define _PR_IOQ_POLLFDS(_cpu)        ((_cpu)->md.md_unix.ioq_pollfds)
  186. #define _PR_IOQ_POLLFDS_SIZE(_cpu)    ((_cpu)->md.md_unix.ioq_pollfds_size)
  187.  
  188. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
  189.  
  190. struct _MDCPU {
  191.     struct _MDCPU_Unix md_unix;
  192. };
  193.  
  194. #if !defined(_PR_PTHREADS)
  195. #define _MD_INIT_LOCKS()
  196. #endif
  197.  
  198. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  199. #define _MD_FREE_LOCK(lock)
  200. #define _MD_LOCK(lock)
  201. #define _MD_UNLOCK(lock)
  202. #define _MD_INIT_IO()
  203. #define _MD_IOQ_LOCK()
  204. #define _MD_IOQ_UNLOCK()
  205.  
  206. #define _MD_EARLY_INIT              _MD_EarlyInit
  207. #define _MD_FINAL_INIT            _PR_UnixInit
  208. #define _MD_INIT_RUNNING_CPU(cpu)    _MD_unix_init_running_cpu(cpu)
  209. #define _MD_INIT_THREAD            _MD_InitializeThread
  210. #define _MD_EXIT_THREAD(thread)
  211. #define    _MD_SUSPEND_THREAD(thread)
  212. #define    _MD_RESUME_THREAD(thread)
  213. #define _MD_CLEAN_THREAD(_thread)
  214. #endif /* PTHREADS_USER */
  215.  
  216. #ifdef AIX4_1
  217. #define _MD_SELECT    select
  218. #define _MD_POLL    poll
  219. #endif
  220.  
  221. #endif /* nspr_aix_defs_h___ */
  222.