| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) | 3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 * | 28 * |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef ThreadingPrimitives_h | 31 #ifndef ThreadingPrimitives_h |
| 32 #define ThreadingPrimitives_h | 32 #define ThreadingPrimitives_h |
| 33 | 33 |
| 34 #include <wtf/Platform.h> | 34 #include <wtf/Platform.h> |
| 35 | 35 |
| 36 #include <wtf/Assertions.h> | 36 #include "wtf/Assertions.h" |
| 37 #include <wtf/FastAllocBase.h> | 37 #include "wtf/FastAllocBase.h" |
| 38 #include <wtf/Locker.h> | 38 #include "wtf/Locker.h" |
| 39 #include <wtf/Noncopyable.h> | 39 #include "wtf/Noncopyable.h" |
| 40 #include "wtf/WTFExport.h" |
| 40 | 41 |
| 41 #if OS(WINDOWS) | 42 #if OS(WINDOWS) |
| 42 #include <windows.h> | 43 #include <windows.h> |
| 43 #endif | 44 #endif |
| 44 | 45 |
| 45 #if USE(PTHREADS) | 46 #if USE(PTHREADS) |
| 46 #include <pthread.h> | 47 #include <pthread.h> |
| 47 #endif | 48 #endif |
| 48 | 49 |
| 49 namespace WTF { | 50 namespace WTF { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 65 HANDLE m_unblockLock; | 66 HANDLE m_unblockLock; |
| 66 | 67 |
| 67 bool timedWait(PlatformMutex&, DWORD durationMilliseconds); | 68 bool timedWait(PlatformMutex&, DWORD durationMilliseconds); |
| 68 void signal(bool unblockAll); | 69 void signal(bool unblockAll); |
| 69 }; | 70 }; |
| 70 #else | 71 #else |
| 71 typedef void* PlatformMutex; | 72 typedef void* PlatformMutex; |
| 72 typedef void* PlatformCondition; | 73 typedef void* PlatformCondition; |
| 73 #endif | 74 #endif |
| 74 | 75 |
| 75 class Mutex { | 76 class WTF_EXPORT Mutex { |
| 76 WTF_MAKE_NONCOPYABLE(Mutex); WTF_MAKE_FAST_ALLOCATED; | 77 WTF_MAKE_NONCOPYABLE(Mutex); WTF_MAKE_FAST_ALLOCATED; |
| 77 public: | 78 public: |
| 78 Mutex(); | 79 Mutex(); |
| 79 ~Mutex(); | 80 ~Mutex(); |
| 80 | 81 |
| 81 void lock(); | 82 void lock(); |
| 82 bool tryLock(); | 83 bool tryLock(); |
| 83 void unlock(); | 84 void unlock(); |
| 84 | 85 |
| 85 public: | 86 public: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 100 m_mutex.unlock(); | 101 m_mutex.unlock(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 bool locked() const { return m_locked; } | 104 bool locked() const { return m_locked; } |
| 104 | 105 |
| 105 private: | 106 private: |
| 106 Mutex& m_mutex; | 107 Mutex& m_mutex; |
| 107 bool m_locked; | 108 bool m_locked; |
| 108 }; | 109 }; |
| 109 | 110 |
| 110 class ThreadCondition { | 111 class WTF_EXPORT ThreadCondition { |
| 111 WTF_MAKE_NONCOPYABLE(ThreadCondition); | 112 WTF_MAKE_NONCOPYABLE(ThreadCondition); |
| 112 public: | 113 public: |
| 113 ThreadCondition(); | 114 ThreadCondition(); |
| 114 ~ThreadCondition(); | 115 ~ThreadCondition(); |
| 115 | 116 |
| 116 void wait(Mutex&); | 117 void wait(Mutex&); |
| 117 // Returns true if the condition was signaled before absoluteTime, false if
the absoluteTime was reached or is in the past. | 118 // Returns true if the condition was signaled before absoluteTime, false if
the absoluteTime was reached or is in the past. |
| 118 // The absoluteTime is in seconds, starting on January 1, 1970. The time is
assumed to use the same time zone as WTF::currentTime(). | 119 // The absoluteTime is in seconds, starting on January 1, 1970. The time is
assumed to use the same time zone as WTF::currentTime(). |
| 119 bool timedWait(Mutex&, double absoluteTime); | 120 bool timedWait(Mutex&, double absoluteTime); |
| 120 void signal(); | 121 void signal(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 135 using WTF::Mutex; | 136 using WTF::Mutex; |
| 136 using WTF::MutexLocker; | 137 using WTF::MutexLocker; |
| 137 using WTF::MutexTryLocker; | 138 using WTF::MutexTryLocker; |
| 138 using WTF::ThreadCondition; | 139 using WTF::ThreadCondition; |
| 139 | 140 |
| 140 #if OS(WINDOWS) | 141 #if OS(WINDOWS) |
| 141 using WTF::absoluteTimeToWaitTimeoutInterval; | 142 using WTF::absoluteTimeToWaitTimeoutInterval; |
| 142 #endif | 143 #endif |
| 143 | 144 |
| 144 #endif // ThreadingPrimitives_h | 145 #endif // ThreadingPrimitives_h |
| OLD | NEW |