Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: base/shared_memory.h

Issue 9463018: Improve SharedMemory::Lock on Posix and reenable StatsTableTest.MultipleThreads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/metrics/stats_table_unittest.cc ('k') | base/shared_memory_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef BASE_SHARED_MEMORY_H_ 5 #ifndef BASE_SHARED_MEMORY_H_
6 #define BASE_SHARED_MEMORY_H_ 6 #define BASE_SHARED_MEMORY_H_
7 #pragma once 7 #pragma once
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 10
11 #include <string>
12
11 #if defined(OS_POSIX) 13 #if defined(OS_POSIX)
12 #include <stdio.h> 14 #include <stdio.h>
13 #include <sys/types.h> 15 #include <sys/types.h>
14 #include <semaphore.h> 16 #include <semaphore.h>
15 #include "base/file_descriptor_posix.h"
16 #endif 17 #endif
17 #include <string>
18 18
19 #include "base/base_export.h" 19 #include "base/base_export.h"
20 #include "base/basictypes.h" 20 #include "base/basictypes.h"
21 #include "base/process.h" 21 #include "base/process.h"
22 22
23 #if defined(OS_POSIX)
24 #include "base/file_descriptor_posix.h"
25 #endif
26
23 class FilePath; 27 class FilePath;
24 28
25 namespace base { 29 namespace base {
26 30
27 // SharedMemoryHandle is a platform specific type which represents 31 // SharedMemoryHandle is a platform specific type which represents
28 // the underlying OS handle to a shared memory segment. 32 // the underlying OS handle to a shared memory segment.
29 #if defined(OS_WIN) 33 #if defined(OS_WIN)
30 typedef HANDLE SharedMemoryHandle; 34 typedef HANDLE SharedMemoryHandle;
31 typedef HANDLE SharedMemoryLock; 35 typedef HANDLE SharedMemoryLock;
32 #elif defined(OS_POSIX) 36 #elif defined(OS_POSIX)
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // Close(); 198 // Close();
195 // return ok; 199 // return ok;
196 // Note that the memory is unmapped by calling this method, regardless of the 200 // Note that the memory is unmapped by calling this method, regardless of the
197 // return value. 201 // return value.
198 bool GiveToProcess(ProcessHandle process, 202 bool GiveToProcess(ProcessHandle process,
199 SharedMemoryHandle* new_handle) { 203 SharedMemoryHandle* new_handle) {
200 return ShareToProcessCommon(process, new_handle, true); 204 return ShareToProcessCommon(process, new_handle, true);
201 } 205 }
202 206
203 // Locks the shared memory. 207 // Locks the shared memory.
204 // This is a cross-process lock which may be recursively 208 //
205 // locked by the same thread. 209 // WARNING: on POSIX the memory locking primitive only works across
206 // TODO(port): 210 // processes, not across threads. The Lock method is not currently
207 // WARNING: on POSIX the lock only works across processes, not 211 // used in inner loops, so we protect against multiple threads in a
208 // across threads. 2 threads in the same process can both grab the 212 // critical section using a class global lock.
209 // lock at the same time. There are several solutions for this
210 // (futex, lockf+anon_semaphore) but none are both clean and common
211 // across Mac and Linux.
212 void Lock(); 213 void Lock();
213 214
214 #if defined(OS_WIN) 215 #if defined(OS_WIN)
215 // A Lock() implementation with a timeout that also allows setting 216 // A Lock() implementation with a timeout that also allows setting
216 // security attributes on the mutex. sec_attr may be NULL. 217 // security attributes on the mutex. sec_attr may be NULL.
217 // Returns true if the Lock() has been acquired, false if the timeout was 218 // Returns true if the Lock() has been acquired, false if the timeout was
218 // reached. 219 // reached.
219 bool Lock(uint32 timeout_ms, SECURITY_ATTRIBUTES* sec_attr); 220 bool Lock(uint32 timeout_ms, SECURITY_ATTRIBUTES* sec_attr);
220 #endif 221 #endif
221 222
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 265 }
265 266
266 private: 267 private:
267 SharedMemory* shared_memory_; 268 SharedMemory* shared_memory_;
268 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLock); 269 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLock);
269 }; 270 };
270 271
271 } // namespace base 272 } // namespace base
272 273
273 #endif // BASE_SHARED_MEMORY_H_ 274 #endif // BASE_SHARED_MEMORY_H_
OLDNEW
« no previous file with comments | « base/metrics/stats_table_unittest.cc ('k') | base/shared_memory_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698