| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 |
|
| 6 |
#include "primpl.h" |
| 7 |
|
| 8 |
#include <mach/mach_time.h> |
| 9 |
|
| 10 |
void _MD_EarlyInit(void) {} |
| 11 |
|
| 12 |
/* |
| 13 |
* The multiplier (as a fraction) for converting the Mach absolute time |
| 14 |
* unit to nanoseconds. |
| 15 |
*/ |
| 16 |
static mach_timebase_info_data_t machTimebaseInfo; |
| 17 |
|
| 18 |
void _PR_Mach_IntervalInit(void) { |
| 19 |
kern_return_t rv; |
| 20 |
|
| 21 |
rv = mach_timebase_info(&machTimebaseInfo); |
| 22 |
PR_ASSERT(rv == KERN_SUCCESS); |
| 23 |
} |
| 24 |
|
| 25 |
PRIntervalTime _PR_Mach_GetInterval(void) { |
| 26 |
uint64_t time; |
| 27 |
|
| 28 |
/* |
| 29 |
* mach_absolute_time returns the time in the Mach absolute time unit. |
| 30 |
* Convert it to milliseconds. See Mac Technical Q&A QA1398. |
| 31 |
*/ |
| 32 |
time = mach_absolute_time(); |
| 33 |
time = |
| 34 |
time * machTimebaseInfo.numer / machTimebaseInfo.denom / PR_NSEC_PER_MSEC; |
| 35 |
return (PRIntervalTime)time; |
| 36 |
} /* _PR_Mach_GetInterval */ |
| 37 |
|
| 38 |
PRIntervalTime _PR_Mach_TicksPerSecond(void) { return 1000; } |
| 39 |
|
| 40 |
PRWord* _MD_HomeGCRegisters(PRThread* t, int isCurrent, int* np) { |
| 41 |
#if !defined(_PR_PTHREADS) |
| 42 |
if (isCurrent) { |
| 43 |
(void)setjmp(CONTEXT(t)); |
| 44 |
} |
| 45 |
*np = sizeof(CONTEXT(t)) / sizeof(PRWord); |
| 46 |
return (PRWord*)CONTEXT(t); |
| 47 |
#else |
| 48 |
*np = 0; |
| 49 |
return NULL; |
| 50 |
#endif |
| 51 |
} |
| 52 |
|
| 53 |
#if !defined(_PR_PTHREADS) |
| 54 |
void _MD_SET_PRIORITY(_MDThread* thread, PRUintn newPri) { return; } |
| 55 |
|
| 56 |
PRStatus _MD_InitializeThread(PRThread* thread) { return PR_SUCCESS; } |
| 57 |
|
| 58 |
PRStatus _MD_WAIT(PRThread* thread, PRIntervalTime ticks) { |
| 59 |
PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); |
| 60 |
_PR_MD_SWITCH_CONTEXT(thread); |
| 61 |
return PR_SUCCESS; |
| 62 |
} |
| 63 |
|
| 64 |
PRStatus _MD_WAKEUP_WAITER(PRThread* thread) { |
| 65 |
if (thread) { |
| 66 |
PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); |
| 67 |
} |
| 68 |
return PR_SUCCESS; |
| 69 |
} |
| 70 |
|
| 71 |
/* These functions should not be called for Darwin */ |
| 72 |
void _MD_YIELD(void) { |
| 73 |
PR_NOT_REACHED("_MD_YIELD should not be called for Darwin."); |
| 74 |
} |
| 75 |
|
| 76 |
PRStatus _MD_CREATE_THREAD(PRThread* thread, void (*start)(void*), |
| 77 |
PRThreadPriority priority, PRThreadScope scope, |
| 78 |
PRThreadState state, PRUint32 stackSize) { |
| 79 |
PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Darwin."); |
| 80 |
return PR_FAILURE; |
| 81 |
} |
| 82 |
#endif /* ! _PR_PTHREADS */ |
| 83 |
|
| 84 |
/* darwin.c */ |