| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // should be using a real lock. | 39 // should be using a real lock. |
| 40 | 40 |
| 41 #include "wtf/Atomics.h" | 41 #include "wtf/Atomics.h" |
| 42 | 42 |
| 43 namespace WTF { | 43 namespace WTF { |
| 44 | 44 |
| 45 // This is called if the initial attempt to acquire the lock fails. It's a bit | 45 // This is called if the initial attempt to acquire the lock fails. It's a bit |
| 46 // slower, but has a much better scheduling and power consumption behavior. | 46 // slower, but has a much better scheduling and power consumption behavior. |
| 47 WTF_EXPORT void slowSpinLockLock(int volatile* lock); | 47 WTF_EXPORT void slowSpinLockLock(int volatile* lock); |
| 48 | 48 |
| 49 ALWAYS_INLINE void spinLockLock(int volatile* lock) | 49 ALWAYS_INLINE void spinLockLock(int volatile* lock) { |
| 50 { | 50 if (LIKELY(!atomicTestAndSetToOne(lock))) |
| 51 if (LIKELY(!atomicTestAndSetToOne(lock))) | 51 return; |
| 52 return; | 52 slowSpinLockLock(lock); |
| 53 slowSpinLockLock(lock); | |
| 54 } | 53 } |
| 55 | 54 |
| 56 ALWAYS_INLINE void spinLockUnlock(int volatile* lock) | 55 ALWAYS_INLINE void spinLockUnlock(int volatile* lock) { |
| 57 { | 56 atomicSetOneToZero(lock); |
| 58 atomicSetOneToZero(lock); | |
| 59 } | 57 } |
| 60 | 58 |
| 61 } // namespace WTF | 59 } // namespace WTF |
| 62 | 60 |
| 63 using WTF::spinLockLock; | 61 using WTF::spinLockLock; |
| 64 using WTF::spinLockUnlock; | 62 using WTF::spinLockUnlock; |
| 65 | 63 |
| 66 #endif // WTF_SpinLock_h | 64 #endif // WTF_SpinLock_h |
| OLD | NEW |