Back to index

lightning-sunbird  0.9+nobinonly
_irix.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nspr_irix_defs_h___
00039 #define nspr_irix_defs_h___
00040 
00041 #define _PR_HAVE_ATOMIC_CAS
00042 
00043 /*
00044  * MipsPro assembler defines _LANGUAGE_ASSEMBLY
00045  */
00046 #ifndef _LANGUAGE_ASSEMBLY
00047 
00048 #include "prclist.h"
00049 #include "prthread.h"
00050 #include <sys/ucontext.h>
00051 
00052 /*
00053  * Internal configuration macros
00054  */
00055 
00056 #define PR_LINKER_ARCH          "irix"
00057 #define _PR_SI_SYSNAME          "IRIX"
00058 #define _PR_SI_ARCHITECTURE     "mips"
00059 #define PR_DLL_SUFFIX              ".so"
00060 
00061 #define _PR_VMBASE              0x30000000
00062 #define _PR_STACK_VMBASE        0x50000000
00063 #define _PR_NUM_GCREGS          9
00064 #define _MD_MMAP_FLAGS          MAP_PRIVATE
00065 
00066 #define _MD_DEFAULT_STACK_SIZE  65536L
00067 #define _MD_MIN_STACK_SIZE      16384L
00068 
00069 #undef  HAVE_STACK_GROWING_UP
00070 #define HAVE_WEAK_IO_SYMBOLS
00071 #define HAVE_WEAK_MALLOC_SYMBOLS
00072 #define HAVE_DLL
00073 #define USE_DLFCN
00074 #define _PR_HAVE_ATOMIC_OPS
00075 #define _PR_POLL_AVAILABLE
00076 #define _PR_USE_POLL
00077 #define _PR_STAT_HAS_ST_ATIM
00078 #define _PR_HAVE_OFF64_T
00079 #define HAVE_POINTER_LOCALTIME_R
00080 #define _PR_HAVE_POSIX_SEMAPHORES
00081 #define PR_HAVE_POSIX_NAMED_SHARED_MEMORY
00082 #define _PR_ACCEPT_INHERIT_NONBLOCK
00083 
00084 #ifdef _PR_INET6
00085 #define _PR_HAVE_INET_NTOP
00086 #define _PR_HAVE_GETIPNODEBYNAME
00087 #define _PR_HAVE_GETIPNODEBYADDR
00088 #define _PR_HAVE_GETADDRINFO
00089 #endif
00090 
00091 /* Initialization entry points */
00092 NSPR_API(void) _MD_EarlyInit(void);
00093 #define _MD_EARLY_INIT _MD_EarlyInit
00094 
00095 NSPR_API(void) _MD_IrixInit(void);
00096 #define _MD_FINAL_INIT _MD_IrixInit
00097 
00098 #define _MD_INIT_IO()
00099 
00100 /* Timer operations */
00101 NSPR_API(PRIntervalTime) _MD_IrixGetInterval(void);
00102 #define _MD_GET_INTERVAL _MD_IrixGetInterval
00103 
00104 NSPR_API(PRIntervalTime) _MD_IrixIntervalPerSec(void);
00105 #define _MD_INTERVAL_PER_SEC _MD_IrixIntervalPerSec
00106 
00107 /* GC operations */
00108 NSPR_API(void *) _MD_GetSP(PRThread *thread);
00109 #define    _MD_GET_SP _MD_GetSP
00110 
00111 /* The atomic operations */
00112 #include <mutex.h>
00113 #define _MD_INIT_ATOMIC()
00114 #define _MD_ATOMIC_INCREMENT(val) add_then_test((unsigned long*)val, 1)
00115 #define _MD_ATOMIC_ADD(ptr, val) add_then_test((unsigned long*)ptr, (unsigned long)val)
00116 #define _MD_ATOMIC_DECREMENT(val) add_then_test((unsigned long*)val, 0xffffffff)
00117 #define _MD_ATOMIC_SET(val, newval) test_and_set((unsigned long*)val, newval)
00118 
00119 #if defined(_PR_PTHREADS)
00120 #else /* defined(_PR_PTHREADS) */
00121 
00122 /************************************************************************/
00123 
00124 #include <setjmp.h>
00125 #include <errno.h>
00126 #include <unistd.h>
00127 #include <bstring.h>
00128 #include <sys/time.h>
00129 #include <ulocks.h>
00130 #include <sys/prctl.h>
00131 
00132 
00133 /*
00134  * Data region private to each sproc. This region is setup by calling
00135  * mmap(...,MAP_LOCAL,...). The private data is mapped at the same
00136  * address in every sproc, but every sproc gets a private mapping.
00137  *
00138  * Just make sure that this structure fits in a page, as only one page
00139  * is allocated for the private region.
00140  */
00141 struct sproc_private_data {
00142     struct PRThread *me;
00143     struct _PRCPU *cpu;
00144     struct PRThread *last;
00145     PRUintn intsOff;
00146        int           sproc_pid;
00147 };
00148 
00149 extern char *_nspr_sproc_private;
00150 
00151 #define _PR_PRDA() ((struct sproc_private_data *) _nspr_sproc_private)
00152 #define _MD_SET_CURRENT_THREAD(_thread) _PR_PRDA()->me = (_thread)
00153 #define _MD_THIS_THREAD() (_PR_PRDA()->me)
00154 #define _MD_LAST_THREAD() (_PR_PRDA()->last)
00155 #define _MD_SET_LAST_THREAD(_thread) _PR_PRDA()->last = (_thread)
00156 #define _MD_CURRENT_CPU() (_PR_PRDA()->cpu)
00157 #define _MD_SET_CURRENT_CPU(_cpu) _PR_PRDA()->cpu = (_cpu)
00158 #define _MD_SET_INTSOFF(_val) (_PR_PRDA()->intsOff = _val)
00159 #define _MD_GET_INTSOFF() (_PR_PRDA()->intsOff)
00160 
00161 #define _MD_SET_SPROC_PID(_val) (_PR_PRDA()->sproc_pid = _val)
00162 #define _MD_GET_SPROC_PID() (_PR_PRDA()->sproc_pid)
00163 
00164 NSPR_API(struct PRThread*) _MD_get_attached_thread(void);
00165 NSPR_API(struct PRThread*) _MD_get_current_thread(void);
00166 #define _MD_GET_ATTACHED_THREAD()  _MD_get_attached_thread()
00167 #define _MD_CURRENT_THREAD()       _MD_get_current_thread()
00168 
00169 #define _MD_CHECK_FOR_EXIT() {                                 \
00170               if (_pr_irix_exit_now) {                         \
00171                      _PR_POST_SEM(_pr_irix_exit_sem);   \
00172                      _MD_Wakeup_CPUs();                               \
00173                      _exit(0);                                               \
00174               }                                                                     \
00175        }
00176               
00177 #define _MD_ATTACH_THREAD(threadp)
00178 
00179 #define _MD_SAVE_ERRNO(_thread)                  (_thread)->md.errcode = errno;
00180 #define _MD_RESTORE_ERRNO(_thread)        errno = (_thread)->md.errcode;
00181 
00182 extern struct _PRCPU  *_pr_primordialCPU;
00183 extern usema_t *_pr_irix_exit_sem;
00184 extern PRInt32 _pr_irix_exit_now;
00185 extern int _pr_irix_primoridal_cpu_fd[];
00186 extern PRInt32 _pr_irix_process_exit;
00187 extern PRInt32 _pr_irix_process_exit_code;
00188 
00189 /* Thread operations */
00190 #define _PR_LOCK_HEAP()     {                                         \
00191                      PRIntn _is;                               \
00192                             if (_pr_primordialCPU) {           \
00193                             if (_MD_GET_ATTACHED_THREAD() &&          \
00194                                    !_PR_IS_NATIVE_THREAD(             \
00195                                    _MD_GET_ATTACHED_THREAD())) \
00196                                           _PR_INTSOFF(_is);    \
00197                                    _PR_LOCK(_pr_heapLock);            \
00198                             }
00199 
00200 #define _PR_UNLOCK_HEAP()   if (_pr_primordialCPU)      {             \
00201                                    _PR_UNLOCK(_pr_heapLock);   \
00202                             if (_MD_GET_ATTACHED_THREAD() &&          \
00203                                    !_PR_IS_NATIVE_THREAD(             \
00204                                    _MD_GET_ATTACHED_THREAD())) \
00205                                           _PR_INTSON(_is);     \
00206                             }                                  \
00207                        }
00208 
00209 #define _PR_OPEN_POLL_SEM(_sem)  usopenpollsema(_sem, 0666)
00210 #define _PR_WAIT_SEM(_sem) uspsema(_sem)
00211 #define _PR_POST_SEM(_sem) usvsema(_sem)
00212 
00213 #define _MD_CVAR_POST_SEM(threadp) usvsema((threadp)->md.cvar_pollsem)
00214 
00215 #define _MD_IOQ_LOCK()
00216 #define _MD_IOQ_UNLOCK()
00217 
00218 struct _MDLock {
00219     ulock_t lock;
00220        usptr_t *arena;
00221 };
00222 
00223 /*
00224  * disable pre-emption for the LOCAL threads when calling the arena lock
00225  * routines
00226  */
00227 
00228 #define _PR_LOCK(lock) {                                       \
00229               PRIntn _is;                                      \
00230               PRThread *me = _MD_GET_ATTACHED_THREAD();               \
00231               if (me && !_PR_IS_NATIVE_THREAD(me))                    \
00232                      _PR_INTSOFF(_is);                         \
00233               ussetlock(lock);                                 \
00234               if (me && !_PR_IS_NATIVE_THREAD(me))                    \
00235                      _PR_FAST_INTSON(_is);                            \
00236        }
00237 
00238 #define _PR_UNLOCK(lock) {                                     \
00239               PRIntn _is;                                      \
00240               PRThread *me = _MD_GET_ATTACHED_THREAD();               \
00241               if (me && !_PR_IS_NATIVE_THREAD(me))                    \
00242                      _PR_INTSOFF(_is);                         \
00243               usunsetlock(lock);                               \
00244               if (me && !_PR_IS_NATIVE_THREAD(me))                    \
00245                      _PR_FAST_INTSON(_is);                            \
00246        }
00247 
00248 NSPR_API(PRStatus) _MD_NEW_LOCK(struct _MDLock *md);
00249 NSPR_API(void) _MD_FREE_LOCK(struct _MDLock *lockp);
00250 
00251 #define _MD_LOCK(_lockp) _PR_LOCK((_lockp)->lock)
00252 #define _MD_UNLOCK(_lockp) _PR_UNLOCK((_lockp)->lock)
00253 #define _MD_TEST_AND_LOCK(_lockp) (uscsetlock((_lockp)->lock, 1) == 0)
00254 
00255 extern ulock_t _pr_heapLock;
00256 
00257 struct _MDThread {
00258     jmp_buf jb;
00259     usptr_t     *pollsem_arena;
00260     usema_t     *cvar_pollsem;
00261     PRInt32     cvar_pollsemfd;
00262     PRInt32     cvar_pollsem_select;    /* acquire sem by calling select */
00263     PRInt32     cvar_wait;              /* if 1, thread is waiting on cvar Q */
00264     PRInt32   id;
00265     PRInt32   suspending_id;
00266     int errcode;
00267 };
00268 
00269 struct _MDThreadStack {
00270     PRInt8 notused;
00271 };
00272 
00273 struct _MDSemaphore {
00274     usema_t *sem;
00275 };
00276 
00277 struct _MDCVar {
00278     ulock_t mdcvar_lock;
00279 };
00280 
00281 struct _MDSegment {
00282     PRInt8 notused;
00283 };
00284 
00285 /*
00286  * md-specific cpu structure field
00287  */
00288 #define _PR_MD_MAX_OSFD FD_SETSIZE
00289 
00290 struct _MDCPU_Unix {
00291     PRCList ioQ;
00292     PRUint32 ioq_timeout;
00293     PRInt32 ioq_max_osfd;
00294     PRInt32 ioq_osfd_cnt;
00295 #ifndef _PR_USE_POLL
00296     fd_set fd_read_set, fd_write_set, fd_exception_set;
00297     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
00298                             fd_exception_cnt[_PR_MD_MAX_OSFD];
00299 #else
00300        struct pollfd *ioq_pollfds;
00301        int ioq_pollfds_size;
00302 #endif /* _PR_USE_POLL */
00303 };
00304 
00305 #define _PR_IOQ(_cpu)                     ((_cpu)->md.md_unix.ioQ)
00306 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
00307 #define _PR_FD_READ_SET(_cpu)             ((_cpu)->md.md_unix.fd_read_set)
00308 #define _PR_FD_READ_CNT(_cpu)             ((_cpu)->md.md_unix.fd_read_cnt)
00309 #define _PR_FD_WRITE_SET(_cpu)            ((_cpu)->md.md_unix.fd_write_set)
00310 #define _PR_FD_WRITE_CNT(_cpu)            ((_cpu)->md.md_unix.fd_write_cnt)
00311 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
00312 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
00313 #define _PR_IOQ_TIMEOUT(_cpu)             ((_cpu)->md.md_unix.ioq_timeout)
00314 #define _PR_IOQ_MAX_OSFD(_cpu)            ((_cpu)->md.md_unix.ioq_max_osfd)
00315 #define _PR_IOQ_OSFD_CNT(_cpu)            ((_cpu)->md.md_unix.ioq_osfd_cnt)
00316 #define _PR_IOQ_POLLFDS(_cpu)             ((_cpu)->md.md_unix.ioq_pollfds)
00317 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
00318 
00319 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
00320 
00321 
00322 struct _MDCPU {
00323     PRInt32 id;
00324     PRInt32 suspending_id;
00325     struct _MDCPU_Unix md_unix;
00326 };
00327 
00328 /*
00329 ** Initialize the thread context preparing it to execute _main.
00330 */
00331 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)         \
00332     PR_BEGIN_MACRO                              \
00333        int *jb = (_thread)->md.jb;              \
00334     *status = PR_TRUE;              \
00335        (void) setjmp(jb);                       \
00336        (_thread)->md.jb[JB_SP] = (int) ((_sp) - 64); \
00337        (_thread)->md.jb[JB_PC] = (int) _main;          \
00338        _thread->no_sched = 0; \
00339     PR_END_MACRO
00340 
00341 /*
00342 ** Switch away from the current thread context by saving its state and
00343 ** calling the thread scheduler. Reload cpu when we come back from the
00344 ** context switch because it might have changed.
00345 *
00346 *  XXX RUNQ lock needed before clearing _PR_NO_SCHED flag, because the
00347 *      thread may be unr RUNQ?
00348 */
00349 #define _MD_SWITCH_CONTEXT(_thread) \
00350     PR_BEGIN_MACRO    \
00351     PR_ASSERT(_thread->no_sched); \
00352     if (!setjmp(_thread->md.jb)) { \
00353         _MD_SAVE_ERRNO(_thread) \
00354         _MD_SET_LAST_THREAD(_thread); \
00355         _PR_Schedule(); \
00356     } else {      \
00357         PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \
00358             _MD_LAST_THREAD()->no_sched = 0;                   \
00359     }             \
00360     PR_END_MACRO
00361 
00362 /*
00363 ** Restore a thread context that was saved by _MD_SWITCH_CONTEXT or
00364 ** initialized by _MD_INIT_CONTEXT.
00365 */
00366 #define _MD_RESTORE_CONTEXT(_newThread) \
00367     PR_BEGIN_MACRO \
00368     int *jb = (_newThread)->md.jb; \
00369     _MD_RESTORE_ERRNO(_newThread) \
00370     _MD_SET_CURRENT_THREAD(_newThread); \
00371     _newThread->no_sched = 1;             \
00372     longjmp(jb, 1); \
00373     PR_END_MACRO
00374 
00375 NSPR_API(PRStatus) _MD_InitThread(struct PRThread *thread,
00376                                                         PRBool wakeup_parent);
00377 NSPR_API(PRStatus) _MD_InitAttachedThread(struct PRThread *thread,
00378                                                                PRBool wakeup_parent);
00379 #define _MD_INIT_THREAD(thread)                  _MD_InitThread(thread, PR_TRUE)
00380 #define _MD_INIT_ATTACHED_THREAD(thread)         \
00381                                           _MD_InitAttachedThread(thread, PR_FALSE)
00382 
00383 NSPR_API(void) _MD_ExitThread(struct PRThread *thread);
00384 #define _MD_EXIT_THREAD _MD_ExitThread
00385 
00386 NSPR_API(void) _MD_SuspendThread(struct PRThread *thread);
00387 #define _MD_SUSPEND_THREAD _MD_SuspendThread
00388 
00389 NSPR_API(void) _MD_ResumeThread(struct PRThread *thread);
00390 #define _MD_RESUME_THREAD _MD_ResumeThread
00391 
00392 NSPR_API(void) _MD_SuspendCPU(struct _PRCPU *thread);
00393 #define _MD_SUSPEND_CPU _MD_SuspendCPU
00394 
00395 NSPR_API(void) _MD_ResumeCPU(struct _PRCPU *thread);
00396 #define _MD_RESUME_CPU _MD_ResumeCPU
00397 
00398 #define _MD_BEGIN_SUSPEND_ALL()
00399 #define _MD_END_SUSPEND_ALL()
00400 #define _MD_BEGIN_RESUME_ALL()
00401 #define _MD_END_RESUME_ALL()
00402 
00403 NSPR_API(void) _MD_InitLocks(void);
00404 #define _MD_INIT_LOCKS _MD_InitLocks
00405 
00406 NSPR_API(void) _MD_CleanThread(struct PRThread *thread);
00407 #define _MD_CLEAN_THREAD _MD_CleanThread
00408 
00409 #define _MD_YIELD()    sginap(0)
00410 
00411 /* The _PR_MD_WAIT_LOCK and _PR_MD_WAKEUP_WAITER functions put to sleep and
00412  * awaken a thread which is waiting on a lock or cvar.
00413  */
00414 NSPR_API(PRStatus) _MD_wait(struct PRThread *, PRIntervalTime timeout);
00415 #define _MD_WAIT _MD_wait
00416 
00417 NSPR_API(void) _PR_MD_primordial_cpu();
00418 NSPR_API(void) _PR_MD_WAKEUP_PRIMORDIAL_CPU();
00419 
00420 NSPR_API(PRStatus) _MD_WakeupWaiter(struct PRThread *);
00421 #define _MD_WAKEUP_WAITER _MD_WakeupWaiter
00422 
00423 NSPR_API(void ) _MD_exit(PRIntn status);
00424 #define _MD_EXIT     _MD_exit
00425 
00426 #include "prthread.h"
00427 
00428 NSPR_API(void) _MD_SetPriority(struct _MDThread *thread,
00429        PRThreadPriority newPri);
00430 #define _MD_SET_PRIORITY _MD_SetPriority
00431 
00432 NSPR_API(PRStatus) _MD_CreateThread(
00433                         struct PRThread *thread,
00434                         void (*start) (void *),
00435                         PRThreadPriority priority,
00436                         PRThreadScope scope,
00437                         PRThreadState state,
00438                         PRUint32 stackSize);
00439 #define _MD_CREATE_THREAD _MD_CreateThread
00440 
00441 extern void _MD_CleanupBeforeExit(void);
00442 #define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit
00443 
00444 NSPR_API(void) _PR_MD_PRE_CLEANUP(PRThread *me);
00445 
00446 
00447 /* The following defines the unwrapped versions of select() and poll(). */
00448 extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
00449        fd_set *exceptfds, struct timeval *timeout);
00450 #define _MD_SELECT   _select
00451 
00452 #include <stropts.h>
00453 #include <poll.h>
00454 #define _MD_POLL _poll
00455 extern int _poll(struct pollfd *fds, unsigned long nfds, int timeout);
00456 
00457 
00458 #define HAVE_THREAD_AFFINITY 1
00459 
00460 NSPR_API(PRInt32) _MD_GetThreadAffinityMask(PRThread *unused, PRUint32 *mask);
00461 #define _MD_GETTHREADAFFINITYMASK _MD_GetThreadAffinityMask
00462 
00463 NSPR_API(void) _MD_InitRunningCPU(struct _PRCPU *cpu);
00464 #define    _MD_INIT_RUNNING_CPU _MD_InitRunningCPU
00465 
00466 #endif  /* defined(_PR_PTHREADS) */
00467 
00468 #endif /* _LANGUAGE_ASSEMBLY */
00469 
00470 #endif /* nspr_irix_defs_h___ */