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