📄 _macos.h
字号:
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU General Public License Version 2 or later (the
* "GPL"), in which case the provisions of the GPL are applicable
* instead of those above. If you wish to allow use of your
* version of this file only under the terms of the GPL and not to
* allow others to use your version of this file under the MPL,
* indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by
* the GPL. If you do not delete the provisions above, a recipient
* may use your version of this file under either the MPL or the
* GPL.
*/
#ifndef prmacos_h___
#define prmacos_h___
//
// This file contains all changes and additions which need to be made to the NSPR runtime
// for the Macintosh platform (specifically the Metrowerks environment). This file should
// only be incluced in Macintosh builds.
//
#define PR_DLL_SUFFIX ""
#define _PR_LOCAL_THREADS_ONLY
#define _PR_NO_PREEMPT 1
#define _PR_HAVE_ATOMIC_OPS 1
#include "prinit.h"
#include "prio.h"
#include "prlong.h"
#include "prlock.h"
#include "prcvar.h"
#include "prsem.h"
#include "prthread.h"
#include "prtime.h"
#include "prproces.h"
#if !defined(MAC_NSPR_STANDALONE)
#include "macstdlibextras.h"
#endif
#include <stddef.h>
#include <setjmp.h>
#include <Errors.h>
#include <OpenTransport.h>
#include <DriverServices.h>
#define _PR_HAVE_PEEK_BUFFER
#define _PR_PEEK_BUFFER_MAX (16 * 1024)
#define _PR_FD_NEED_EMULATE_MSG_PEEK(fd) 1
struct _MDProcess {
PRInt8 notused;
};
struct _MDThread {
jmp_buf jb;
int osErrCode;
PRLock * asyncIOLock;
PRCondVar * asyncIOCVar;
PRBool missedIONotify;
PRBool missedAsyncNotify;
PRBool asyncNotifyPending;
};
struct _MDThreadStack {
PRInt8 notused;
};
struct _MDLock {
PRInt8 notused;
};
struct _MDCVar {
PRInt8 notused;
};
struct _MDSemaphore {
PRInt8 notused;
};
struct _MDSegment {
PRInt8 notused;
};
struct _MDCPU {
AbsoluteTime lastThreadSwitch;
AbsoluteTime lastWakeUpProcess;
PRBool trackScheduling;
};
typedef struct _MDSocketCallerInfo {
PRThread * thread;
void * cookie;
} _MDSocketCallerInfo;
struct _MDFileDesc {
PRInt32 osfd;
PRPackedBool orderlyDisconnect;
PRPackedBool readReady;
PRPackedBool writeReady;
PRPackedBool exceptReady;
PRLock * miscLock;
/* Server sockets: listen bit tells the notifier func what to do */
PRBool doListen;
/* stored error for non-blocking connects, as a Unix-style error code */
OTReason disconnectError;
_MDSocketCallerInfo misc;
_MDSocketCallerInfo read;
_MDSocketCallerInfo write;
};
/*
** Iinitialization Related definitions
*/
#define _MD_EARLY_INIT _MD_EarlyInit
#define _MD_FINAL_INIT _MD_FinalInit
/*
** Interrupts Related definitions
*/
#define _MD_GET_INTSOFF() (_pr_intsOff)
#define _MD_INTSOFF(_is) \
PR_BEGIN_MACRO \
ENTER_CRITICAL_REGION(); \
(_is) = _PR_MD_GET_INTSOFF(); \
_PR_MD_SET_INTSOFF(1); \
LEAVE_CRITICAL_REGION(); \
PR_END_MACRO
#if TARGET_CARBON
extern void _MD_SetIntsOff(PRInt32 ints);
#define _MD_SET_INTSOFF(_val) _MD_SetIntsOff(_val)
#else /* not TARGET_CARBON */
#define _MD_SET_INTSOFF(_val) (_pr_intsOff = _val)
#endif /* TARGET_CARBON */
#define _MD_START_INTERRUPTS _MD_StartInterrupts
#define _MD_STOP_INTERRUPTS _MD_StopInterrupts
#define _MD_BLOCK_CLOCK_INTERRUPTS()
#define _MD_UNBLOCK_CLOCK_INTERRUPTS()
#define _MD_DISABLE_CLOCK_INTERRUPTS()
#define _MD_ENABLE_CLOCK_INTERRUPTS()
/*
** CPU Related definitions
*/
#define _MD_PAUSE_CPU _MD_PauseCPU
#define _MD_CLEANUP_BEFORE_EXIT()
#define _MD_EXIT(status) exit(status)
#define _MD_INIT_CPUS()
#define _MD_INIT_RUNNING_CPU(cpu) _MD_InitRunningCPU(cpu)
/*
** Process Related definitions
*/
extern struct PRProcess * _MD_CreateProcess(
const char *path,
char *const *argv,
char *const *envp,
const PRProcessAttr *attr);
#define _MD_CREATE_PROCESS _MD_CreateProcess
extern PRStatus _MD_DetachProcess(PRProcess *process);
#define _MD_DETACH_PROCESS _MD_DetachProcess
extern PRStatus _MD_WaitProcess(PRProcess *process, PRInt32 *exitCode);
#define _MD_WAIT_PROCESS _MD_WaitProcess
extern PRStatus _MD_KillProcess(PRProcess *process);
#define _MD_KILL_PROCESS _MD_KillProcess
/*
** Memory Segments Related definitions
*/
#define _MD_INIT_SEGS()
/*
** Thread Stacks Debugging Related definitions
*/
#define _MD_INIT_STACK _MD_InitStack
#define _MD_CLEAR_STACK _MD_ClearStack
/*
** Locks Related definitions
*/
#define _MD_INIT_LOCKS()
#define _MD_NEW_LOCK(lock) (PR_SUCCESS)
#define _MD_FREE_LOCK(lock)
#define _MD_LOCK(lock)
#define _MD_UNLOCK(lock)
/*
** Thread Related definitions
*/
NSPR_API(PRThread *) PR_GetPrimaryThread();
#if defined(powerc) || defined(__powerc)
#define _MD_GET_PC(_t) (*((PRUint32 *)((_t)->md.jb)))
#define _MD_GET_SP(_t) (*((PRUint32 *)((_t)->md.jb) + 2))
#define _MD_GET_TOC(_t) (*((PRUint32 *)((_t)->md.jb) + 3))
#define INIT_STACKPTR(stackTop) ((unsigned char*)stackTop - 128)
#define PR_NUM_GCREGS 70
#else
#define _MD_GET_PC(_t) (*((PRUint32 *)((_t)->md.jb) + 6))
#define _MD_GET_SP(_t) (*((PRUint32 *)((_t)->md.jb) + 12))
#define INIT_STACKPTR(stackTop) ((unsigned char*)stackTop - 4)
#define PR_NUM_GCREGS 13
#endif
#define _MD_DEFAULT_STACK_SIZE (58 * 1024)
#define _MD_MINIMUM_STACK_SIZE (58 * 1024)
/*
** Initialize the thread machine dependent data structure
*/
extern PRStatus _MD_InitThread(PRThread *thread);
#define _MD_INIT_THREAD _MD_InitThread
/*
** Clean-up the thread machine dependent data structure
*/
#define _MD_CLEAN_THREAD(_thread) \
PR_BEGIN_MACRO \
PR_DestroyCondVar(_thread->md.asyncIOCVar); \
PR_DestroyLock(_thread->md.asyncIOLock); \
PR_END_MACRO
/*
** Initialize the thread context preparing it to execute _main.
** *sp = 0 zeros out the sp for the first stack frame so that
** stack walking code can find the top of the stack.
*/
#if defined(powerc) || defined(__powerc)
#define _MD_INIT_CONTEXT(_thread, _sp, _main, _status) \
PR_BEGIN_MACRO \
unsigned char *sp; \
unsigned long *tvect; \
long **jb = (_thread)->md.jb; \
*((PRBool *)_status) = PR_TRUE; \
(void) setjmp(jb); \
sp = INIT_STACKPTR(_sp); \
*sp = 0; \
(_MD_GET_SP(_thread)) = (long) sp; \
tvect = (unsigned long *)_main; \
(_MD_GET_PC(_thread)) = (int) *tvect; \
(_MD_GET_TOC(_thread)) = (int) *(tvect+1); \
_thread->no_sched = 0; \
PR_END_MACRO
#else
#define _MD_INIT_CONTEXT(_thread, _sp, _main, _status) \
PR_BEGIN_MACRO \
unsigned char *sp; \
long **jb = (_thread)->md.jb; \
*((PRBool *)_status) = PR_TRUE; \
(void) setjmp(jb); \
sp = INIT_STACKPTR(_sp); \
(_MD_GET_SP(_thread)) = (long) sp; \
(_MD_GET_PC(_thread)) = (int) _main; \
_thread->no_sched = 0; \
PR_END_MACRO
#endif
/*
** Switch away from the current thread context by saving its state and
** calling the thread scheduler. Reload cpu when we come back from the
** context switch because it might have changed.
*/
/* ResetTimer(); before _PR_Schedule() */
#define _MD_SWITCH_CONTEXT(_thread) \
PR_BEGIN_MACRO \
PR_ASSERT(_thread->no_sched); \
if (!setjmp(_thread->md.jb)) { \
_MD_SET_LAST_THREAD(_thread); \
if (_PR_MD_CURRENT_CPU()->md.trackScheduling) \
_PR_MD_CURRENT_CPU()->md.lastThreadSwitch = UpTime(); \
_PR_Schedule(); \
} else { \
PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \
_MD_LAST_THREAD()->no_sched = 0; \
} \
PR_END_MACRO
/*
** Restore a thread context that was saved by _MD_SWITCH_CONTEXT or
** initialized by _MD_INIT_CONTEXT.
*/
#define _MD_RESTORE_CONTEXT(_newThread) \
PR_BEGIN_MACRO \
long **jb = (_newThread)->md.jb; \
_MD_SET_CURRENT_THREAD(_newThread); \
_newThread->no_sched = 1; \
longjmp(jb, 1); \
PR_END_MACRO
#define _MD_ERRNO() _MD_CURRENT_THREAD()->md.osErrCode
extern PRStatus _MD_wait(PRThread *thread, PRIntervalTime timeout);
#define _MD_WAIT _MD_wait
/*
** Combined thread model related definitions
*/
#define _MD_CREATE_THREAD(a,b,c,d,e,f) (PR_SUCCESS)
#define _MD_WAKEUP_WAITER(a)
#define _MD_SET_PRIORITY(a,b)
/*
** File I/O Related definitions
*/
extern PRInt32 _PR_MD_WRITE_SYNC(PRFileDesc *fd, void *buf, PRInt32 amount);
#define _PR_MD_WRITE_SYNC _MD_WRITE_SYNC
struct _MDDir {
short ioVRefNum;
long ioDirID;
short ioFDirIndex;
char *currentEntryName;
};
#define PR_DIRECTORY_SEPARATOR '/'
#define PR_DIRECTORY_SEPARATOR_STR "/"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -