| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/shared_memory.h" | 5 #include "base/shared_memory.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 | 9 |
| 10 namespace base { | 10 namespace base { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 memory_ = NULL; | 190 memory_ = NULL; |
| 191 } | 191 } |
| 192 | 192 |
| 193 if (mapped_file_ != NULL) { | 193 if (mapped_file_ != NULL) { |
| 194 CloseHandle(mapped_file_); | 194 CloseHandle(mapped_file_); |
| 195 mapped_file_ = NULL; | 195 mapped_file_ = NULL; |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 | 198 |
| 199 void SharedMemory::Lock() { | 199 void SharedMemory::Lock() { |
| 200 Lock(INFINITE); | 200 Lock(INFINITE, NULL); |
| 201 } | 201 } |
| 202 | 202 |
| 203 bool SharedMemory::Lock(uint32 timeout_ms) { | 203 bool SharedMemory::Lock(uint32 timeout_ms, SECURITY_ATTRIBUTES* sec_attr) { |
| 204 if (lock_ == NULL) { | 204 if (lock_ == NULL) { |
| 205 std::wstring name = name_; | 205 std::wstring name = name_; |
| 206 name.append(L"lock"); | 206 name.append(L"lock"); |
| 207 lock_ = CreateMutex(NULL, FALSE, name.c_str()); | 207 lock_ = CreateMutex(sec_attr, FALSE, name.c_str()); |
| 208 DCHECK(lock_ != NULL); | |
| 209 if (lock_ == NULL) { | 208 if (lock_ == NULL) { |
| 210 DLOG(ERROR) << "Could not create mutex" << GetLastError(); | 209 PLOG(ERROR) << "Could not create mutex."; |
| 211 return false; // there is nothing good we can do here. | 210 return false; // there is nothing good we can do here. |
| 212 } | 211 } |
| 213 } | 212 } |
| 214 DWORD result = WaitForSingleObject(lock_, timeout_ms); | 213 DWORD result = WaitForSingleObject(lock_, timeout_ms); |
| 215 | 214 |
| 216 // Return false for WAIT_ABANDONED, WAIT_TIMEOUT or WAIT_FAILED. | 215 // Return false for WAIT_ABANDONED, WAIT_TIMEOUT or WAIT_FAILED. |
| 217 return (result == WAIT_OBJECT_0); | 216 return (result == WAIT_OBJECT_0); |
| 218 } | 217 } |
| 219 | 218 |
| 220 void SharedMemory::Unlock() { | 219 void SharedMemory::Unlock() { |
| 221 DCHECK(lock_ != NULL); | 220 DCHECK(lock_ != NULL); |
| 222 ReleaseMutex(lock_); | 221 ReleaseMutex(lock_); |
| 223 } | 222 } |
| 224 | 223 |
| 225 SharedMemoryHandle SharedMemory::handle() const { | 224 SharedMemoryHandle SharedMemory::handle() const { |
| 226 return mapped_file_; | 225 return mapped_file_; |
| 227 } | 226 } |
| 228 | 227 |
| 229 } // namespace base | 228 } // namespace base |
| OLD | NEW |