| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/service_process_util_posix.h" | 5 #include "chrome/common/service_process_util_posix.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <memory> |
| 10 |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/location.h" | 12 #include "base/location.h" |
| 11 #include "base/posix/eintr_wrapper.h" | 13 #include "base/posix/eintr_wrapper.h" |
| 12 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 13 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 14 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 15 #include "chrome/common/multi_process_lock.h" | 17 #include "chrome/common/multi_process_lock.h" |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 int g_signal_socket = -1; | 20 int g_signal_socket = -1; |
| 19 } | 21 } |
| 20 | 22 |
| 21 // Attempts to take a lock named |name|. If |waiting| is true then this will | 23 // Attempts to take a lock named |name|. If |waiting| is true then this will |
| 22 // make multiple attempts to acquire the lock. | 24 // make multiple attempts to acquire the lock. |
| 23 // Caller is responsible for ownership of the MultiProcessLock. | 25 // Caller is responsible for ownership of the MultiProcessLock. |
| 24 MultiProcessLock* TakeNamedLock(const std::string& name, bool waiting) { | 26 MultiProcessLock* TakeNamedLock(const std::string& name, bool waiting) { |
| 25 scoped_ptr<MultiProcessLock> lock(MultiProcessLock::Create(name)); | 27 std::unique_ptr<MultiProcessLock> lock(MultiProcessLock::Create(name)); |
| 26 if (lock == NULL) return NULL; | 28 if (lock == NULL) return NULL; |
| 27 bool got_lock = false; | 29 bool got_lock = false; |
| 28 for (int i = 0; i < 10; ++i) { | 30 for (int i = 0; i < 10; ++i) { |
| 29 if (lock->TryLock()) { | 31 if (lock->TryLock()) { |
| 30 got_lock = true; | 32 got_lock = true; |
| 31 break; | 33 break; |
| 32 } | 34 } |
| 33 if (!waiting) break; | 35 if (!waiting) break; |
| 34 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100 * i)); | 36 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100 * i)); |
| 35 } | 37 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 signal_ready.Wait(); | 191 signal_ready.Wait(); |
| 190 return success; | 192 return success; |
| 191 } | 193 } |
| 192 | 194 |
| 193 void ServiceProcessState::TearDownState() { | 195 void ServiceProcessState::TearDownState() { |
| 194 if (state_) { | 196 if (state_) { |
| 195 state_->Release(); | 197 state_->Release(); |
| 196 state_ = NULL; | 198 state_ = NULL; |
| 197 } | 199 } |
| 198 } | 200 } |
| OLD | NEW |