| OLD | NEW |
| 1 /* Copyright (c) 2009, Google Inc. | 1 /* Copyright (c) 2009, Google Inc. |
| 2 * All rights reserved. | 2 * 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 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 * | 29 * |
| 30 * --- | 30 * --- |
| 31 * This file is a Posix-specific part of spinlock.cc | 31 * This file is a Posix-specific part of spinlock_internal.cc |
| 32 */ | 32 */ |
| 33 | 33 |
| 34 #include <sched.h> | 34 #include <config.h> |
| 35 #include <time.h> | 35 #include <errno.h> |
| 36 #ifdef HAVE_SCHED_H |
| 37 #include <sched.h> /* For sched_yield() */ |
| 38 #endif |
| 39 #include <time.h> /* For nanosleep() */ |
| 36 | 40 |
| 37 static void SpinLockWait(volatile Atomic32 *w) { | 41 namespace base { |
| 42 namespace internal { |
| 43 |
| 44 void SpinLockDelay(volatile Atomic32 *w, int32 value, int loop) { |
| 38 int save_errno = errno; | 45 int save_errno = errno; |
| 39 struct timespec tm; | 46 if (loop == 0) { |
| 40 tm.tv_sec = 0; | 47 } else if (loop == 1) { |
| 41 tm.tv_nsec = 1000000; | |
| 42 if (base::subtle::NoBarrier_Load(w) != 0) { | |
| 43 sched_yield(); | 48 sched_yield(); |
| 44 } | 49 } else { |
| 45 while (base::subtle::Acquire_CompareAndSwap(w, 0, 1) != 0) { | 50 struct timespec tm; |
| 51 tm.tv_sec = 0; |
| 52 tm.tv_nsec = 1000000; |
| 46 nanosleep(&tm, NULL); | 53 nanosleep(&tm, NULL); |
| 47 } | 54 } |
| 48 errno = save_errno; | 55 errno = save_errno; |
| 49 } | 56 } |
| 50 | 57 |
| 51 static void SpinLockWake(volatile Atomic32 *w) { | 58 void SpinLockWake(volatile Atomic32 *w, bool all) { |
| 52 } | 59 } |
| 60 |
| 61 } // namespace internal |
| 62 } // namespace base |
| OLD | NEW |