home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / include / md / _irix.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  11.0 KB  |  376 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_irix_defs_h___
  20. #define nspr_irix_defs_h___
  21.  
  22. #include "prclist.h"
  23. #include "prthread.h"
  24. #include <sys/ucontext.h>
  25.  
  26. /*
  27.  * Internal configuration macros
  28.  */
  29.  
  30. #define PR_LINKER_ARCH          "irix"
  31. #define _PR_SI_SYSNAME          "IRIX"
  32. #define _PR_SI_ARCHITECTURE     "mips"
  33. #define PR_DLL_SUFFIX        ".so"
  34.  
  35. #define _PR_VMBASE              0x30000000
  36. #define _PR_STACK_VMBASE        0x50000000
  37. #define _PR_NUM_GCREGS          9
  38. #define _MD_MMAP_FLAGS          MAP_PRIVATE
  39.  
  40. #define _MD_DEFAULT_STACK_SIZE  65536L
  41. #define _MD_MIN_STACK_SIZE      16384L
  42.  
  43. #undef  HAVE_STACK_GROWING_UP
  44. #define HAVE_WEAK_IO_SYMBOLS
  45. #define HAVE_WEAK_MALLOC_SYMBOLS
  46. #define HAVE_DLL
  47. #define USE_DLFCN
  48. #define _PR_HAVE_ATOMIC_OPS
  49.  
  50. /* Initialization entry points */
  51. PR_EXTERN(void) _MD_EarlyInit(void);
  52. #define _MD_EARLY_INIT _MD_EarlyInit
  53.  
  54. PR_EXTERN(void) _MD_IrixInit(void);
  55. #define _MD_FINAL_INIT _MD_IrixInit
  56.  
  57. #define _MD_INIT_IO()
  58.  
  59. /* Timer operations */
  60. PR_EXTERN(PRIntervalTime) _MD_GetInterval(void);
  61. #define _MD_GET_INTERVAL _MD_GetInterval
  62.  
  63. PR_EXTERN(PRIntervalTime) _MD_IntervalPerSec(void);
  64. #define _MD_INTERVAL_PER_SEC _MD_IntervalPerSec
  65.  
  66. /* GC operations */
  67. PR_EXTERN(void *) _MD_GetSP(PRThread *thread);
  68. #define    _MD_GET_SP _MD_GetSP
  69.  
  70. /* The atomic operations */
  71. #include <mutex.h>
  72. #define _MD_INIT_ATOMIC()
  73. #define _MD_ATOMIC_INCREMENT(val) add_then_test((unsigned long*)val, 1)
  74. #define _MD_ATOMIC_DECREMENT(val) add_then_test((unsigned long*)val, 0xffffffff)
  75. #define _MD_ATOMIC_SET(val, newval) test_and_set((unsigned long*)val, newval)
  76.  
  77. #if defined(_PR_PTHREADS)
  78. #else /* defined(_PR_PTHREADS) */
  79.  
  80. /************************************************************************/
  81.  
  82. #include <setjmp.h>
  83. #include <errno.h>
  84. #include <unistd.h>
  85. #include <bstring.h>
  86. #include <sys/time.h>
  87. #include <ulocks.h>
  88. #include <sys/prctl.h>
  89.  
  90.  
  91. /*
  92.  * Data region private to each sproc. This region is setup by calling
  93.  * mmap(...,MAP_LOCAL,...). The private data is mapped at the same
  94.  * address in every sproc, but every sproc gets a private mapping.
  95.  *
  96.  * Just make sure that this structure fits in a page, as only one page
  97.  * is allocated for the private region.
  98.  */
  99. struct sproc_private_data {
  100.     struct PRThread *me;
  101.     struct _PRCPU *cpu;
  102.     struct PRThread *last;
  103.     PRUintn intsOff;
  104.     int        sproc_pid;
  105. };
  106.  
  107. extern char *_nspr_sproc_private;
  108.  
  109. #define _PR_PRDA() ((struct sproc_private_data *) _nspr_sproc_private)
  110. #define _MD_CURRENT_THREAD() (_PR_PRDA()->me)
  111. #define _MD_SET_CURRENT_THREAD(_thread) _PR_PRDA()->me = (_thread)
  112. #define _MD_LAST_THREAD() (_PR_PRDA()->last)
  113. #define _MD_SET_LAST_THREAD(_thread) _PR_PRDA()->last = (_thread)
  114. #define _MD_CURRENT_CPU() (_PR_PRDA()->cpu)
  115. #define _MD_SET_CURRENT_CPU(_cpu) _PR_PRDA()->cpu = (_cpu)
  116. #define _MD_SET_INTSOFF(_val) (_PR_PRDA()->intsOff = _val)
  117. #define _MD_GET_INTSOFF() (_PR_PRDA()->intsOff)
  118.  
  119. #define _MD_SET_SPROC_PID(_val) (_PR_PRDA()->sproc_pid = _val)
  120. #define _MD_GET_SPROC_PID() (_PR_PRDA()->sproc_pid)
  121.  
  122. PR_EXTERN(struct PRThread*) _MD_get_attached_thread(void);
  123. #define _MD_GET_ATTACHED_THREAD()    _MD_get_attached_thread()
  124.  
  125. #define _MD_CHECK_FOR_EXIT() {                    \
  126.         if (_pr_irix_exit_now) {            \
  127.             _PR_POST_SEM(_pr_irix_exit_sem);    \
  128.             exit(0);                \
  129.         }                        \
  130.     }
  131.         
  132. #define _MD_ATTACH_THREAD(threadp)
  133.  
  134. #define _MD_SAVE_ERRNO(_thread)
  135. #define _MD_RESTORE_ERRNO(_thread)
  136.  
  137. extern struct _PRCPU  *_pr_primordialCPU;
  138. extern usema_t *_pr_irix_exit_sem;
  139. extern PRInt32 _pr_irix_exit_now;
  140.  
  141. /* Thread operations */
  142. #define _PR_LOCK_HEAP()    {                        \
  143.             PRIntn _is;                    \
  144.                 if (_pr_primordialCPU) {        \
  145.                 if (_PR_MD_CURRENT_THREAD() &&         \
  146.                     !_PR_IS_NATIVE_THREAD(         \
  147.                     _PR_MD_CURRENT_THREAD()))    \
  148.                         _PR_INTSOFF(_is);     \
  149.                     _PR_LOCK(_pr_heapLock);        \
  150.                 }
  151.  
  152. #define _PR_UNLOCK_HEAP()     if (_pr_primordialCPU)    {        \
  153.                     _PR_UNLOCK(_pr_heapLock);    \
  154.                 if (_PR_MD_CURRENT_THREAD() &&         \
  155.                     !_PR_IS_NATIVE_THREAD(         \
  156.                     _PR_MD_CURRENT_THREAD()))    \
  157.                         _PR_INTSON(_is);    \
  158.                 }                    \
  159.               }
  160.  
  161. #define _PR_OPEN_POLL_SEM(_sem)  usopenpollsema(_sem, 0666)
  162. #define _PR_WAIT_SEM(_sem) uspsema(_sem)
  163. #define _PR_POST_SEM(_sem) usvsema(_sem)
  164.  
  165. #define _MD_CVAR_POST_SEM(threadp)    usvsema((threadp)->md.cvar_pollsem)
  166.  
  167. #define _MD_IOQ_LOCK()
  168. #define _MD_IOQ_UNLOCK()
  169.  
  170. struct _MDLock {
  171.     ulock_t lock;
  172.     usptr_t *arena;
  173. };
  174.  
  175. /*
  176.  * disable pre-emption for the LOCAL threads when calling the arena lock
  177.  * routines
  178.  */
  179.  
  180. #define _PR_LOCK(lock) {                        \
  181.         PRIntn _is;                        \
  182.         PRThread *me = _PR_MD_CURRENT_THREAD();            \
  183.         if (me && !_PR_IS_NATIVE_THREAD(me))            \
  184.             _PR_INTSOFF(_is);                 \
  185.         ussetlock(lock);                    \
  186.         if (me && !_PR_IS_NATIVE_THREAD(me))            \
  187.             _PR_FAST_INTSON(_is);                 \
  188.     }
  189.  
  190. #define _PR_UNLOCK(lock) {                        \
  191.         PRIntn _is;                        \
  192.         PRThread *me = _PR_MD_CURRENT_THREAD();            \
  193.         if (me && !_PR_IS_NATIVE_THREAD(me))            \
  194.             _PR_INTSOFF(_is);                 \
  195.         usunsetlock(lock);                    \
  196.         if (me && !_PR_IS_NATIVE_THREAD(me))            \
  197.             _PR_FAST_INTSON(_is);                 \
  198.     }
  199.  
  200. PR_EXTERN(PRStatus) _MD_NEW_LOCK(struct _MDLock *md);
  201. PR_EXTERN(void) _MD_FREE_LOCK(struct _MDLock *lockp);
  202.  
  203. #define _MD_LOCK(_lockp) _PR_LOCK((_lockp)->lock)
  204. #define _MD_UNLOCK(_lockp) _PR_UNLOCK((_lockp)->lock)
  205. #define _MD_TEST_AND_LOCK(_lockp) uscsetlock((_lockp)->lock, 1)
  206.  
  207. extern ulock_t _pr_heapLock;
  208.  
  209. struct _MDThread {
  210.     jmp_buf jb;
  211.     usptr_t     *pollsem_arena;
  212.     usema_t     *cvar_pollsem;
  213.     PRInt32     cvar_pollsemfd;
  214.     PRInt32     cvar_pollsem_select;    /* acquire sem by calling select */
  215.     PRInt32     cvar_wait;              /* if 1, thread is waiting on cvar Q */
  216.     PRInt32    id;
  217.     PRInt32    suspending_id;
  218.     int errcode;
  219. };
  220.  
  221. struct _MDThreadStack {
  222.     PRInt8 notused;
  223. };
  224.  
  225. struct _MDSemaphore {
  226.     usema_t *sem;
  227. };
  228.  
  229. struct _MDCVar {
  230.     ulock_t mdcvar_lock;
  231. };
  232.  
  233. struct _MDSegment {
  234.     PRInt8 notused;
  235. };
  236.  
  237. struct _MDCPU {
  238.     PRInt32 id;
  239.     PRInt32 suspending_id;
  240.     struct _MDCPU_Unix md_unix;
  241. };
  242.  
  243. /*
  244. ** Initialize the thread context preparing it to execute _main.
  245. */
  246. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)          \
  247.     PR_BEGIN_MACRO                      \
  248.     int *jb = (_thread)->md.jb;              \
  249.     *status = PR_TRUE;              \
  250.     (void) setjmp(jb);                  \
  251.     (_thread)->md.jb[JB_SP] = (int) ((_sp) - 64); \
  252.     (_thread)->md.jb[JB_PC] = (int) _main;          \
  253.     _thread->no_sched = 0; \
  254.     PR_END_MACRO
  255.  
  256. /*
  257. ** Switch away from the current thread context by saving its state and
  258. ** calling the thread scheduler. Reload cpu when we come back from the
  259. ** context switch because it might have changed.
  260. *
  261. *  XXX RUNQ lock needed before clearing _PR_NO_SCHED flag, because the
  262. *      thread may be unr RUNQ?
  263. */
  264. #define _MD_SWITCH_CONTEXT(_thread) \
  265.     PR_BEGIN_MACRO    \
  266.     PR_ASSERT(_thread->no_sched); \
  267.     if (!setjmp(_thread->md.jb)) { \
  268.         _MD_SAVE_ERRNO(_thread) \
  269.         _MD_SET_LAST_THREAD(_thread); \
  270.         _PR_Schedule(); \
  271.     } else {      \
  272.         PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \
  273.             _MD_LAST_THREAD()->no_sched = 0;            \
  274.     }             \
  275.     PR_END_MACRO
  276.  
  277. /*
  278. ** Restore a thread context that was saved by _MD_SWITCH_CONTEXT or
  279. ** initialized by _MD_INIT_CONTEXT.
  280. */
  281. #define _MD_RESTORE_CONTEXT(_newThread) \
  282.     PR_BEGIN_MACRO \
  283.     int *jb = (_newThread)->md.jb; \
  284.     _MD_RESTORE_ERRNO(_newThread) \
  285.     _MD_SET_CURRENT_THREAD(_newThread); \
  286.     _newThread->no_sched = 1;        \
  287.     longjmp(jb, 1); \
  288.     PR_END_MACRO
  289.  
  290. PR_EXTERN(PRStatus) _MD_InitThread(struct PRThread *thread, PRBool wakeup_parent);
  291. #define _MD_INIT_THREAD(thread)             _MD_InitThread(thread, PR_TRUE)
  292. #define _MD_INIT_ATTACHED_THREAD(thread)    _MD_InitThread(thread, PR_FALSE)
  293.  
  294. PR_EXTERN(void) _MD_ExitThread(struct PRThread *thread);
  295. #define _MD_EXIT_THREAD _MD_ExitThread
  296.  
  297. PR_EXTERN(void) _MD_SuspendThread(struct PRThread *thread);
  298. #define _MD_SUSPEND_THREAD _MD_SuspendThread
  299.  
  300. PR_EXTERN(void) _MD_ResumeThread(struct PRThread *thread);
  301. #define _MD_RESUME_THREAD _MD_ResumeThread
  302.  
  303. PR_EXTERN(void) _MD_SuspendCPU(struct _PRCPU *thread);
  304. #define _MD_SUSPEND_CPU _MD_SuspendCPU
  305.  
  306. PR_EXTERN(void) _MD_ResumeCPU(struct _PRCPU *thread);
  307. #define _MD_RESUME_CPU _MD_ResumeCPU
  308.  
  309. #define _MD_BEGIN_SUSPEND_ALL()
  310. #define _MD_END_SUSPEND_ALL()
  311. #define _MD_BEGIN_RESUME_ALL()
  312. #define _MD_END_RESUME_ALL()
  313.  
  314. PR_EXTERN(void) _MD_InitLocks(void);
  315. #define _MD_INIT_LOCKS _MD_InitLocks
  316.  
  317. PR_EXTERN(void) _MD_CleanThread(struct PRThread *thread);
  318. #define _MD_CLEAN_THREAD _MD_CleanThread
  319.  
  320. #define _MD_INIT_PRIMORDIAL_THREAD(threadp)
  321. #define _MD_YIELD()    sginap(0)
  322.  
  323. /* The _PR_MD_WAIT_LOCK and _PR_MD_WAKEUP_WAITER functions put to sleep and
  324.  * awaken a thread which is waiting on a lock or cvar.
  325.  */
  326. PR_EXTERN(PRStatus) _MD_wait(struct PRThread *, PRIntervalTime timeout);
  327. #define _MD_WAIT _MD_wait
  328.  
  329. PR_EXTERN(PRStatus) _MD_WakeupWaiter(struct PRThread *);
  330. #define _MD_WAKEUP_WAITER _MD_WakeupWaiter
  331.  
  332. PR_EXTERN(void ) _MD_exit(PRIntn status);
  333. #define _MD_EXIT    _MD_exit
  334.  
  335. #include "prthread.h"
  336.  
  337. PR_EXTERN(void) _MD_SetPriority(struct _MDThread *thread,
  338.     PRThreadPriority newPri);
  339. #define _MD_SET_PRIORITY _MD_SetPriority
  340.  
  341. PR_EXTERN(PRStatus) _MD_CreateThread(
  342.                         struct PRThread *thread,
  343.                         void (*start) (void *),
  344.                         PRThreadPriority priority,
  345.                         PRThreadScope scope,
  346.                         PRThreadState state,
  347.                         PRUint32 stackSize);
  348. #define _MD_CREATE_THREAD _MD_CreateThread
  349.  
  350. extern void _MD_CleanupBeforeExit(void);
  351. #define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit
  352.  
  353.  
  354. /* The following defines the unwrapped versions of select() and poll(). */
  355. extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
  356.     fd_set *exceptfds, struct timeval *timeout);
  357. #define _MD_SELECT    _select
  358.  
  359. #include <stropts.h>
  360. #include <poll.h>
  361. #define _MD_POLL _poll
  362. extern int _poll(struct pollfd *fds, unsigned long nfds, int timeout);
  363.  
  364.  
  365. #define HAVE_THREAD_AFFINITY 1
  366.  
  367. PR_EXTERN(PRInt32) _MD_GetThreadAffinityMask(PRThread *unused, PRUint32 *mask);
  368. #define _MD_GETTHREADAFFINITYMASK _MD_GetThreadAffinityMask
  369.  
  370. PR_EXTERN(void) _MD_InitRunningCPU(struct _PRCPU *cpu);
  371. #define    _MD_INIT_RUNNING_CPU _MD_InitRunningCPU
  372.  
  373. #endif  /* defined(_PR_PTHREADS) */
  374.  
  375. #endif /* nspr_irix_defs_h___ */
  376.