1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/src/md/unix/darwin.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,113 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "primpl.h" 1.10 + 1.11 +#include <mach/mach_time.h> 1.12 + 1.13 +void _MD_EarlyInit(void) 1.14 +{ 1.15 +} 1.16 + 1.17 +/* 1.18 + * The multiplier (as a fraction) for converting the Mach absolute time 1.19 + * unit to nanoseconds. 1.20 + */ 1.21 +static mach_timebase_info_data_t machTimebaseInfo; 1.22 + 1.23 +void _PR_Mach_IntervalInit(void) 1.24 +{ 1.25 + kern_return_t rv; 1.26 + 1.27 + rv = mach_timebase_info(&machTimebaseInfo); 1.28 + PR_ASSERT(rv == KERN_SUCCESS); 1.29 +} 1.30 + 1.31 +PRIntervalTime _PR_Mach_GetInterval(void) 1.32 +{ 1.33 + uint64_t time; 1.34 + 1.35 + /* 1.36 + * mach_absolute_time returns the time in the Mach absolute time unit. 1.37 + * Convert it to milliseconds. See Mac Technical Q&A QA1398. 1.38 + */ 1.39 + time = mach_absolute_time(); 1.40 + time = time * machTimebaseInfo.numer / machTimebaseInfo.denom / 1.41 + PR_NSEC_PER_MSEC; 1.42 + return (PRIntervalTime)time; 1.43 +} /* _PR_Mach_GetInterval */ 1.44 + 1.45 +PRIntervalTime _PR_Mach_TicksPerSecond(void) 1.46 +{ 1.47 + return 1000; 1.48 +} 1.49 + 1.50 +PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) 1.51 +{ 1.52 +#if !defined(_PR_PTHREADS) 1.53 + if (isCurrent) { 1.54 + (void) setjmp(CONTEXT(t)); 1.55 + } 1.56 + *np = sizeof(CONTEXT(t)) / sizeof(PRWord); 1.57 + return (PRWord *) CONTEXT(t); 1.58 +#else 1.59 + *np = 0; 1.60 + return NULL; 1.61 +#endif 1.62 +} 1.63 + 1.64 +#if !defined(_PR_PTHREADS) 1.65 +void 1.66 +_MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri) 1.67 +{ 1.68 + return; 1.69 +} 1.70 + 1.71 +PRStatus 1.72 +_MD_InitializeThread(PRThread *thread) 1.73 +{ 1.74 + return PR_SUCCESS; 1.75 +} 1.76 + 1.77 +PRStatus 1.78 +_MD_WAIT(PRThread *thread, PRIntervalTime ticks) 1.79 +{ 1.80 + PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); 1.81 + _PR_MD_SWITCH_CONTEXT(thread); 1.82 + return PR_SUCCESS; 1.83 +} 1.84 + 1.85 +PRStatus 1.86 +_MD_WAKEUP_WAITER(PRThread *thread) 1.87 +{ 1.88 + if (thread) { 1.89 + PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); 1.90 + } 1.91 + return PR_SUCCESS; 1.92 +} 1.93 + 1.94 +/* These functions should not be called for Darwin */ 1.95 +void 1.96 +_MD_YIELD(void) 1.97 +{ 1.98 + PR_NOT_REACHED("_MD_YIELD should not be called for Darwin."); 1.99 +} 1.100 + 1.101 +PRStatus 1.102 +_MD_CREATE_THREAD( 1.103 + PRThread *thread, 1.104 + void (*start) (void *), 1.105 + PRThreadPriority priority, 1.106 + PRThreadScope scope, 1.107 + PRThreadState state, 1.108 + PRUint32 stackSize) 1.109 +{ 1.110 + PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Darwin."); 1.111 + return PR_FAILURE; 1.112 +} 1.113 +#endif /* ! _PR_PTHREADS */ 1.114 + 1.115 +/* darwin.c */ 1.116 +