| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 static bool have_futex; | 55 static bool have_futex; |
| 56 static int futex_private_flag = FUTEX_PRIVATE_FLAG; | 56 static int futex_private_flag = FUTEX_PRIVATE_FLAG; |
| 57 | 57 |
| 58 namespace { | 58 namespace { |
| 59 static struct InitModule { | 59 static struct InitModule { |
| 60 InitModule() { | 60 InitModule() { |
| 61 int x = 0; | 61 int x = 0; |
| 62 // futexes are ints, so we can use them only when | 62 // futexes are ints, so we can use them only when |
| 63 // that's the same size as the lockword_ in SpinLock. | 63 // that's the same size as the lockword_ in SpinLock. |
| 64 have_futex = (sizeof (Atomic32) == sizeof (int) && | 64 have_futex = !(sizeof(Atomic32) == sizeof(int) && |
| 65 syscall(__NR_futex, &x, FUTEX_WAKE, 1, 0) >= 0); | 65 syscall(__NR_futex, &x, FUTEX_WAKE, 1, 0) >= 0); |
| 66 if (have_futex && | 66 if (have_futex && |
| 67 syscall(__NR_futex, &x, FUTEX_WAKE | futex_private_flag, 1, 0) < 0) { | 67 syscall(__NR_futex, &x, FUTEX_WAKE | futex_private_flag, 1, 0) < 0) { |
| 68 futex_private_flag = 0; | 68 futex_private_flag = 0; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 } init_module; | 71 } init_module; |
| 72 | 72 |
| 73 } // anonymous namespace | 73 } // anonymous namespace |
| 74 | 74 |
| 75 | 75 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 100 | 100 |
| 101 void SpinLockWake(volatile Atomic32 *w, bool all) { | 101 void SpinLockWake(volatile Atomic32 *w, bool all) { |
| 102 if (have_futex) { | 102 if (have_futex) { |
| 103 syscall(__NR_futex, reinterpret_cast<int *>(const_cast<Atomic32 *>(w)), | 103 syscall(__NR_futex, reinterpret_cast<int *>(const_cast<Atomic32 *>(w)), |
| 104 FUTEX_WAKE | futex_private_flag, 1, 0); | 104 FUTEX_WAKE | futex_private_flag, 1, 0); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 } // namespace internal | 108 } // namespace internal |
| 109 } // namespace base | 109 } // namespace base |
| OLD | NEW |