diff options
Diffstat (limited to 'dep/src/zthread/macos')
-rw-r--r-- | dep/src/zthread/macos/FastLock.h | 140 | ||||
-rw-r--r-- | dep/src/zthread/macos/Monitor.cxx | 280 | ||||
-rw-r--r-- | dep/src/zthread/macos/Monitor.h | 157 | ||||
-rw-r--r-- | dep/src/zthread/macos/TSS.h | 121 | ||||
-rw-r--r-- | dep/src/zthread/macos/ThreadOps.cxx | 103 | ||||
-rw-r--r-- | dep/src/zthread/macos/ThreadOps.h | 168 | ||||
-rw-r--r-- | dep/src/zthread/macos/UpTimeStrategy.h | 87 |
7 files changed, 0 insertions, 1056 deletions
diff --git a/dep/src/zthread/macos/FastLock.h b/dep/src/zthread/macos/FastLock.h deleted file mode 100644 index 012843f2e3e..00000000000 --- a/dep/src/zthread/macos/FastLock.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2005, Eric Crahen - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifndef __ZTFASTLOCK_H__ -#define __ZTFASTLOCK_H__ - -#include "zthread/NonCopyable.h" -#include "zthread/Exceptions.h" - -#include <assert.h> -#include <CoreServices/CoreServices.h> -//#include <Multiprocessing.h> - -namespace ZThread { - -/** - * @class FastLock - * - * @author Eric Crahen <http://www.code-foo.com> - * @date <2003-07-16T23:25:31-0400> - * @version 2.1.6 - * - */ -class FastLock : private NonCopyable { - - MPCriticalRegionID _mtx; - - public: - - /** - * Create a new FastLock. No safety or state checks are performed. - * - * @exception Initialization_Exception - not thrown - */ - inline FastLock() { - - // Apple TN1071 - static bool init = MPLibraryIsLoaded(); - - if(!init || MPCreateCriticalRegion(&_mtx) != noErr) { - assert(0); - throw Initialization_Exception(); - } - - } - - /** - * Destroy a FastLock. No safety or state checks are performed. - */ - inline ~FastLock() throw () { - - OSStatus status = MPDeleteCriticalRegion(_mtx); - if(status != noErr) - assert(false); - - } - - /** - * Acquire an exclusive lock. No safety or state checks are performed. - * - * @exception Synchronization_Exception - not thrown - */ - inline void acquire() { - - if(MPEnterCriticalRegion(_mtx, kDurationForever) != noErr) - throw Synchronization_Exception(); - - } - - /** - * Try to acquire an exclusive lock. No safety or state checks are performed. - * This function returns immediately regardless of the value of the timeout - * - * @param timeout Unused - * @return bool - * @exception Synchronization_Exception - not thrown - */ - inline bool tryAcquire(unsigned long timeout=0) { - - OSStatus status = - MPEnterCriticalRegion(_mtx, kDurationMillisecond * timeout); - - switch(status) { - case kMPTimeoutErr: - return false; - - case noErr: - return true; - - } - - assert(0); - throw Synchronization_Exception(); - - } - - /** - * Release an exclusive lock. No safety or state checks are performed. - * The caller should have already acquired the lock, and release it - * only once. - * - * @exception Synchronization_Exception - not thrown - */ - inline void release() { - - if(MPExitCriticalRegion(_mtx) != noErr) - throw Synchronization_Exception(); - - } - - -}; /* FastLock */ - - -}; - -#endif - - - - diff --git a/dep/src/zthread/macos/Monitor.cxx b/dep/src/zthread/macos/Monitor.cxx deleted file mode 100644 index a6a2f58cb37..00000000000 --- a/dep/src/zthread/macos/Monitor.cxx +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright (c) 2005, Eric Crahen - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#include "Monitor.h" - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -using namespace ZThread; - -Monitor::Monitor() : _owner(0), _waiting(false), _pending(false) { - - if(MPCreateSemaphore(1, 0, &_sema) != noErr) { - assert(0); - throw Initialization_Exception(); - } - -} - -Monitor::~Monitor() throw() { - - assert(!_waiting); - - OSStatus status = MPDeleteSemaphore(_sema); - if(status != noErr) - assert(false); - -} - -Monitor::STATE Monitor::wait(unsigned long timeout) { - - // Calcuate the time, taking into account Intertask Signaling Time - // http://developer.apple.com/techpubs/macosx/Carbon/oss/MultiPServices/Multiprocessing_Services/index.html?http://developer.apple.com/techpubs/macosx/Carbon/oss/MultiPServices/Multiprocessing_Services/Functions/Creating_and_ssage_Queues.html - - AbsoluteTime tTarget; - Duration waitDuration = - (timeout == 0) ? kDurationForever : (kDurationMillisecond * timeout); - - if(waitDuration != kDurationForever) - tTarget = AddDurationToAbsolute(waitDuration, UpTime()); - - // Update the owner on first use. The owner will not change, each - // thread waits only on a single Monitor and a Monitor is never - // shared - if(_owner == 0) - _owner = MPCurrentTaskID(); - - STATE state(INVALID); - - // Serialize access to the state of the Monitor - // and test the state to determine if a wait is needed. - _waitLock.acquire(); - - if(pending(ANYTHING)) { - - // Return without waiting when possible - state = next(); - - _waitLock.release(); - return state; - - } - // Unlock the external lock if a wait() is probably needed. - // Access to the state is still serial. - _lock.release(); - - // Wait for a transition in the state that is of interest, this - // allows waits to exclude certain flags (e.g. INTERRUPTED) - // for a single wait() w/o actually discarding those flags - - // they will remain set until a wait interested in those flags - // occurs. - - // Wait, ignoring signals - _waiting = true; - - _waitLock.release(); - - // Update the wait time - if(waitDuration != kDurationForever) - waitDuration = AbsoluteDeltaToDuration(tTarget, UpTime()); - - // Sleep until a signal arrives or a timeout occurs - OSStatus status = MPWaitOnSemaphore(_sema, waitDuration); - - // Reacquire serialized access to the state - _waitLock.acquire(); - - // Awaken only when the event is set or the timeout expired - assert(status == kMPTimeoutErr || status == noErr); - - if(status == kMPTimeoutErr) - push(TIMEDOUT); - - // Get the next available STATE - state = next(); - - _waiting = false; - - // Its possible that a timeout will wake the thread before a signal is - // delivered. Absorb that leftover so the next wait isn't aborted right away - if(status == kMPTimeoutErr && _pending) { - - status = MPWaitOnSemaphore(_sema, kDurationForever); - assert(status == noErr); - - } - - _pending = false; - - // Acquire the internal lock & release the external lock - _waitLock.release(); - - // Reaquire the external lock, keep from deadlocking threads calling - // notify(), interrupt(), etc. - _lock.acquire(); - - return state; - -} - - -bool Monitor::interrupt() { - - // Serialize access to the state - _waitLock.acquire(); - - bool wasInterruptable = !pending(INTERRUPTED); - bool hasWaiter = false; - - // Update the state & wake the waiter if there is one - if(wasInterruptable) { - - push(INTERRUPTED); - - wasInterruptable = false; - - if(_waiting && !_pending) { - - _pending = true; - hasWaiter = true; - - } else - wasInterruptable = !(_owner == MPCurrentTaskID()); - - } - - _waitLock.release(); - - if(hasWaiter && !masked(Monitor::INTERRUPTED)) - MPSignalSemaphore(_sema); - - return wasInterruptable; - -} - -bool Monitor::isInterrupted() { - - // Serialize access to the state - _waitLock.acquire(); - - bool wasInterrupted = pending(INTERRUPTED); - clear(INTERRUPTED); - - _waitLock.release(); - - return wasInterrupted; - -} - - -bool Monitor::notify() { - - // Serialize access to the state - _waitLock.acquire(); - - bool wasNotifyable = !pending(INTERRUPTED); - bool hasWaiter = false; - - // Set the flag if theres a waiter - if(wasNotifyable) { - - push(SIGNALED); - - if(_waiting && !_pending) { - - _pending = true; - hasWaiter = true; - - } - - } - - _waitLock.release(); - - if(hasWaiter) - MPSignalSemaphore(_sema); - - return wasNotifyable; - -} - - -bool Monitor::cancel() { - - // Serialize access to the state - _waitLock.acquire(); - - bool wasInterrupted = !pending(INTERRUPTED); - bool hasWaiter = false; - - push(CANCELED); - - // Update the state if theres a waiter - if(wasInterrupted) { - - push(INTERRUPTED); - - if(_waiting && !_pending) { - - _pending = true; - hasWaiter = true; - - } - - } - - _waitLock.release(); - - if(hasWaiter && !masked(Monitor::INTERRUPTED)) - MPSignalSemaphore(_sema); - - return wasInterrupted; - -} - -bool Monitor::isCanceled() { - - // Serialize access to the state - _waitLock.acquire(); - - bool wasCanceled = Status::examine(CANCELED); - - if(_owner == MPCurrentTaskID()) - clear(INTERRUPTED); - - _waitLock.release(); - - return wasCanceled; - -} - - - - - - - - - - diff --git a/dep/src/zthread/macos/Monitor.h b/dep/src/zthread/macos/Monitor.h deleted file mode 100644 index fa5b2ec7760..00000000000 --- a/dep/src/zthread/macos/Monitor.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2005, Eric Crahen - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifndef __ZTMONITOR_H__ -#define __ZTMONITOR_H__ - -#include "../Status.h" -#include "../FastLock.h" - -namespace ZThread { - -/** - * @class Monitor - * @author Eric Crahen <http://www.code-foo.com/> - * @date <2003-07-29T11:24:58-0400> - * @version 2.2.1 - */ -class Monitor : public Status, private NonCopyable { - - //! Serialize access to external objects - FastLock _lock; - - //! Serialize access to internal state - FastLock _waitLock; - - //! Semaphore to control the owning thread - MPSemaphoreID _sema; - - //! Owning thread - MPTaskID _owner; - - //! Waiting flag, to avoid uneccessary signals - volatile bool _waiting; - - //! Waiting flag, to avoid too many signals - volatile bool _pending; - - //! State of the monitor - volatile int _state; - - public: - - //! Create a new monitor. - Monitor(); - - //! Destroy the monitor. - ~Monitor() throw(); - - //! Acquire the external lock for this monitor. - inline void acquire() { - _lock.acquire(); - } - - //! Try to acquire the external lock for this monitor. - inline bool tryAcquire() { - return _lock.tryAcquire(); - } - - //! Release the external lock for this monitor. - inline void release() { - _lock.release(); - } - - /** - * Wait for a state change and atomically unlock the external lock. - * Blocks for an indefinent amount of time. - * - * @return INTERRUPTED if the wait was ended by a interrupt() - * or SIGNALED if the wait was ended by a notify() - * - * @post the external lock is always acquired before this function returns - */ - inline STATE wait() { - return wait(0); - } - - /** - * Wait for a state change and atomically unlock the external lock. - * May blocks for an indefinent amount of time. - * - * @param timeout - maximum time to block (milliseconds) or 0 to - * block indefinently - * - * @return INTERRUPTED if the wait was ended by a interrupt() - * or TIMEDOUT if the maximum wait time expired. - * or SIGNALED if the wait was ended by a notify() - * - * @post the external lock is always acquired before this function returns - */ - STATE wait(unsigned long timeout); - - /** - * Interrupt this monitor. If there is a thread blocked on this monitor object - * it will be signaled and released. If there is no waiter, a flag is set and - * the next attempt to wait() will return INTERRUPTED w/o blocking. - * - * @return false if the thread was previously INTERRUPTED. - */ - bool interrupt(); - - /** - * Notify this monitor. If there is a thread blocked on this monitor object - * it will be signaled and released. If there is no waiter, a flag is set and - * the next attempt to wait() will return SIGNALED w/o blocking, if no other - * flag is set. - * - * @return false if the thread was previously INTERRUPTED. - */ - bool notify(); - - /** - * Check the state of this monitor, clearing the INTERRUPTED status if set. - * - * @return bool true if the monitor was INTERRUPTED. - * @post INTERRUPTED flag cleared if the calling thread owns the monitor. - */ - bool isInterrupted(); - - /** - * Mark the Status CANCELED, and INTERRUPT the montor. - * - * @see interrupt() - */ - bool cancel(); - - /** - * Test the CANCELED Status, clearing the INTERRUPTED status if set. - * - * @return bool - */ - bool isCanceled(); - -}; - -}; - -#endif - diff --git a/dep/src/zthread/macos/TSS.h b/dep/src/zthread/macos/TSS.h deleted file mode 100644 index e73050c4612..00000000000 --- a/dep/src/zthread/macos/TSS.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2005, Eric Crahen - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifndef __ZTTSS_H__ -#define __ZTTSS_H__ - -#include "zthread/NonCopyable.h" -#include "zthread/Exceptions.h" - -#include <assert.h> -#include <CoreServices/CoreServices.h> -//#include <Multiprocessing.h> - -namespace ZThread { - - /** - * @class TSS - * @author Eric Crahen <http://www.code-foo.com> - * @date <2003-07-27T14:19:10-0400> - * @version 2.1.6 - * - * An abstraction for dealing with POSIX thread specific storage (tss). - * Provides get/set and creation/destruction. - */ - template <typename T> - class TSS : private NonCopyable { - - TaskStorageIndex _key; - - public: - - /** - * Create a new object for accessing tss. - */ - TSS() { - - // Apple TN1071 - static bool init = MPLibraryIsLoaded(); - - if(!init || MPAllocateTaskStorageIndex(&_key) != noErr) { - assert(0); - throw Initialization_Exception(); - } - - } - - /** - * Destroy the underlying supoprt for accessing tss with this - * object. - */ - ~TSS() { - - OSStatus status = MPDeallocateTaskStorageIndex(_key); - if(status != noErr) - assert(0); - - } - - /** - * Get the value stored in tss. - * - * @return T - * - * @exception InvalidOp_exception thrown when the tss is not properly initialized - */ - T get() const { - return reinterpret_cast<T>(MPGetTaskStorageValue(_key)); - } - - - /** - * Store a value in tss. - * - * @param value T - * @return T old value - * - * @exception InvalidOp_exception thrown when the tss is not properly initialized - */ - T set(T value) const { - - T oldValue = get(); - - OSStatus status = - MPSetTaskStorageValue(_key, reinterpret_cast<TaskStorageValue>(value)); - - if(status != noErr) { - assert(0); - throw Synchronization_Exception(); - } - - return oldValue; - - } - - }; - -} - -#endif - - - diff --git a/dep/src/zthread/macos/ThreadOps.cxx b/dep/src/zthread/macos/ThreadOps.cxx deleted file mode 100644 index ddb380992b0..00000000000 --- a/dep/src/zthread/macos/ThreadOps.cxx +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2005, Eric Crahen - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - - -#include "ThreadOps.h" -#include "zthread/Exceptions.h" -#include "zthread/Runnable.h" - -namespace ZThread { - -const ThreadOps ThreadOps::INVALID(0); - -ThreadOps::ThreadOps() : _queue(0), _tid(0) { - - if(MPCreateQueue(&_queue) != noErr) - throw Initialization_Exception(); - -} - -ThreadOps::~ThreadOps() throw() { - - if(_queue != 0) { - - OSStatus status = MPDeleteQueue(_queue); - if(status != noErr) - assert(0); - - } - -} - -bool ThreadOps::join(ThreadOps* ops) { - - assert(ops); - assert(ops->_tid != 0); - - OSStatus status = MPWaitOnQueue(ops->_queue, NULL, NULL, NULL, kDurationForever); - - return status == noErr; - -} - -bool ThreadOps::yield() { - - MPYield(); - return true; - -} - -bool ThreadOps::setPriority(ThreadOps* impl, Priority p) { - return true; -} - -bool ThreadOps::getPriority(ThreadOps* impl, Priority& p) { - return true; -} - - -bool ThreadOps::spawn(Runnable* task) { - - OSStatus status = - MPCreateTask(&_dispatch, task, 0UL, _queue, NULL, NULL, 0UL, &_tid); - - return status == noErr; - -} - -OSStatus ThreadOps::_dispatch(void *arg) { - - Runnable* task = reinterpret_cast<Runnable*>(arg); - assert(task); - - // Run the task from the correct context - task->run(); - - // Exit the thread - MPExit(noErr); - return noErr; - -} - -} // namespace ZThread - - diff --git a/dep/src/zthread/macos/ThreadOps.h b/dep/src/zthread/macos/ThreadOps.h deleted file mode 100644 index c0417f0bb2f..00000000000 --- a/dep/src/zthread/macos/ThreadOps.h +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2005, Eric Crahen - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifndef __ZTTHREADOPS_H__ -#define __ZTTHREADOPS_H__ - -#include "zthread/Priority.h" - -#include <assert.h> -#include <CoreServices/CoreServices.h> -//#include <Multiprocessing.h> -//#include <MultiprocessingInfo.h> - -namespace ZThread { - -class Runnable; - -/** - * @class ThreadOps - * @author Eric Crahen <http://www.code-foo.com> - * @date <2003-07-16T23:26:01-0400> - * @version 2.2.0 - * - * This class is an abstraction used to perform various operations on a - * native POSIX thread. - */ -class ThreadOps { - - //! Keep track of the pthreads handle for the native thread - MPQueueID _queue; - MPTaskID _tid; - - ThreadOps(MPTaskID tid) : _queue(0), _tid(tid) { } - - static OSStatus _dispatch(void*); - -public: - - const static ThreadOps INVALID; - - /** - * Create a new ThreadOps to manipulate a native thread. - */ - ThreadOps(); - - ThreadOps(const ThreadOps& ops) : _queue(0), _tid(ops._tid) {} - - ~ThreadOps() throw(); - - inline bool operator==(const ThreadOps& ops) const { - return ops._tid == _tid; - } - - const ThreadOps& operator=(const ThreadOps& ops) { - - assert(_queue == 0); - _tid = ops._tid; - - return *this; - - } - - static ThreadOps self() { - return ThreadOps(MPCurrentTaskID()); - } - - /** - * Activating an instance of ThreadOps will map it onto the currently - * executing thread. - */ - static void activate(ThreadOps* ops) { - - assert(ops); - assert(ops->_tid == 0); - - ops->_tid = MPCurrentTaskID(); - - } - - /** - * Test if this object represents the currently executing - * native thread. - * - * @return bool true if successful - */ - - static bool isCurrent(ThreadOps* ops) { - - assert(ops); - - return MPCurrentTaskID() == ops->_tid; - - } - - /** - * Join a native thread. - * - * @return bool true if successful - */ - static bool join(ThreadOps*); - - /** - * Force the current native thread to yield, letting the scheduler - * give the CPU time to another thread. - * - * @return bool true if successful, false if the operation can't - * be supported. - */ - static bool yield(); - - /** - * Set the priority for the native thread if supported by the - * system. - * - * @param PRIORITY requested priority - * @return bool false if unsuccessful - */ - static bool setPriority(ThreadOps*, Priority); - - /** - * Set the priority for the native thread if supported by the - * system. - * - * @param Thread::PRIORITY& current priority - * @return bool false if unsuccessful - */ - static bool getPriority(ThreadOps*, Priority&); - -protected: - - /** - * Spawn a native thread. - * - * @param ThreadImpl* parent thread - * @param ThreadImpl* child thread being started. - * @param Runnable* task being executed. - * - * @return bool true if successful - */ - bool spawn(Runnable*); - -}; - - -} - -#endif // __ZTTHREADOPS_H__ - - diff --git a/dep/src/zthread/macos/UpTimeStrategy.h b/dep/src/zthread/macos/UpTimeStrategy.h deleted file mode 100644 index 4d94a48f3cd..00000000000 --- a/dep/src/zthread/macos/UpTimeStrategy.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2005, Eric Crahen - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifndef __ZTTIMESTRATEGY_H__ -#define __ZTTIMESTRATEGY_H__ - -#include <CoreServices/CoreServices.h> -//#include <DriverServices.h> - -namespace ZThread { - - -/** - * @class TimeStrategy - * - * Implement a strategy for time operatons based on UpTime - */ -class TimeStrategy { - - unsigned long _ms; - unsigned long _s; - - public: - - TimeStrategy() { - - // Get the absolute time in milliseconds relative to the program startup - static AbsoluteTime sysUpTime(UpTime()); - AbsoluteTime delta = AbsoluteDeltaToNanoseconds(UpTime(), sysUpTime); - - uint64_t now = *reinterpret_cast<uint64_t*>(&delta) / 1000000; - - _s = now / 1000; - _ms = now % 1000; - - } - - inline unsigned long seconds() const { - return _s; - } - - inline unsigned long milliseconds() const { - return _ms; - } - - unsigned long seconds(unsigned long s) { - - unsigned long z = seconds(); - _s = s; - return z; - - } - - unsigned long milliseconds(unsigned long ms) { - - unsigned long z = milliseconds(); - _ms = ms; - - return z; - - } - -}; - -}; - -#endif // __ZTTIMESTRATEGY_H__ - |