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/win_util.h" | 8 #include "base/win_util.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
(...skipping 27 matching lines...) Expand all Loading... |
38 (read_only_ ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS), | 38 (read_only_ ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS), |
39 FALSE, 0); | 39 FALSE, 0); |
40 } | 40 } |
41 | 41 |
42 SharedMemory::~SharedMemory() { | 42 SharedMemory::~SharedMemory() { |
43 Close(); | 43 Close(); |
44 if (lock_ != NULL) | 44 if (lock_ != NULL) |
45 CloseHandle(lock_); | 45 CloseHandle(lock_); |
46 } | 46 } |
47 | 47 |
| 48 // static |
| 49 bool SharedMemory::IsHandleValid(const SharedMemoryHandle& handle) { |
| 50 return handle != NULL; |
| 51 } |
| 52 |
48 bool SharedMemory::Create(const std::wstring &name, bool read_only, | 53 bool SharedMemory::Create(const std::wstring &name, bool read_only, |
49 bool open_existing, size_t size) { | 54 bool open_existing, size_t size) { |
50 DCHECK(mapped_file_ == NULL); | 55 DCHECK(mapped_file_ == NULL); |
51 | 56 |
52 name_ = name; | 57 name_ = name; |
53 read_only_ = read_only; | 58 read_only_ = read_only; |
54 mapped_file_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, | 59 mapped_file_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, |
55 read_only_ ? PAGE_READONLY : PAGE_READWRITE, 0, static_cast<DWORD>(size), | 60 read_only_ ? PAGE_READONLY : PAGE_READWRITE, 0, static_cast<DWORD>(size), |
56 name.empty() ? NULL : name.c_str()); | 61 name.empty() ? NULL : name.c_str()); |
57 if (!mapped_file_) | 62 if (!mapped_file_) |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 166 } |
162 } | 167 } |
163 WaitForSingleObject(lock_, INFINITE); | 168 WaitForSingleObject(lock_, INFINITE); |
164 } | 169 } |
165 | 170 |
166 void SharedMemory::Unlock() { | 171 void SharedMemory::Unlock() { |
167 DCHECK(lock_ != NULL); | 172 DCHECK(lock_ != NULL); |
168 ReleaseMutex(lock_); | 173 ReleaseMutex(lock_); |
169 } | 174 } |
170 | 175 |
| 176 SharedMemoryHandle SharedMemory::handle() const { |
| 177 return mapped_file_; |
| 178 } |
| 179 |
171 } // namespace base | 180 } // namespace base |
OLD | NEW |