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

Side by Side Diff: base/memory/shared_memory_handle.h

Issue 1163943004: Make SharedMemoryHandle a class on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared_memory_make_class3_base
Patch Set: Use right include on windows. Created 5 years, 6 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_MEMORY_SHARED_MEMORY_HANDLE_H_
6 #define BASE_MEMORY_SHARED_MEMORY_HANDLE_H_
7
8 #include "build/build_config.h"
9
10 #if defined(OS_WIN)
11 #include <windows.h>
12 #elif defined(OS_MACOSX) && !defined(OS_IOS)
13 #include <sys/types.h>
14 #include "base/base_export.h"
15 #include "base/file_descriptor_posix.h"
16 #include "base/macros.h"
17 #elif defined(OS_POSIX)
18 #include <sys/types.h>
19 #include "base/file_descriptor_posix.h"
20 #endif
21
22 namespace base {
23
24 // SharedMemoryHandle is a platform specific type which represents
25 // the underlying OS handle to a shared memory segment.
26 #if defined(OS_WIN)
27 typedef HANDLE SharedMemoryHandle;
28 #elif defined(OS_MACOSX) && !defined(OS_IOS)
29
30 class BASE_EXPORT SharedMemoryHandle {
31 public:
32 enum Mechanism {
33 // Indicates that the SharedMemoryHandle is backed by a POSIX fd.
34 POSIX_FD = 0,
Robert Sesek 2015/06/05 19:27:14 I think just POSIX and MACH are better names.
erikchen 2015/06/06 01:47:00 Done.
35 // Indicates that the SharedMemoryHandle is backed by the Mach primitive
36 // "memory object".
37 MACH_PRIMITIVE = 1,
38 };
39
40 // The default constructor returns an invalid SharedMemoryHandle.
41 SharedMemoryHandle();
42
43 // Constructs a SharedMemoryHandle backed by |file_descriptor|.
44 explicit SharedMemoryHandle(const FileDescriptor& file_descriptor);
45
46 // Constructs a SharedMemoryHandle backed by the components of a
47 // FileDescriptor.
48 SharedMemoryHandle(int fd, bool auto_close);
49
50 // Standard copy constructor. The new instance shares the underlying OS
51 // primitives.
52 SharedMemoryHandle(const SharedMemoryHandle& handle);
53
54 // Standard assignment operator. The updated instance shares the underlying
55 // OS primitives.
56 SharedMemoryHandle& operator=(const SharedMemoryHandle& handle);
57
58 // Comparison operators.
59 bool operator==(const SharedMemoryHandle& handle) const;
60 bool operator!=(const SharedMemoryHandle& handle) const;
61
62 // Returns the mechanism that backs the SharedMemoryHandle for wire transfer.
63 uint32_t GetMechanismForWire() const;
Robert Sesek 2015/06/05 19:27:14 These names are kind of awkward. Why not just have
erikchen 2015/06/06 01:47:00 I moved the mechanism logic into this class, but t
64
65 // Sets the mechanism used to back the SharedMemoryHandle.
66 // Returns whether |mechanism| was a valid input.
67 bool SetMechanismFromWire(uint32_t mechanism);
68
69 // Whether the instance is backed by a POSIX fd.
70 bool IsBackedByPOSIXFd() const;
71
72 // Returns the POSIX fd backing the SharedMemoryHandle. Requires that the
73 // SharedMemoryHandle be backed by a POSIX fd.
74 int GetFileHandle() const;
75
76 // Sets the POSIX fd backing the SharedMemoryHandle. Requires that the
77 // SharedMemoryHandle be backed by a POSIX fd.
78 void SetFileHandle(int fd, bool auto_close);
79
80 // Returns the address of the POSIX FileDescriptor backing the
81 // SharedMemoryHandle.
82 FileDescriptor* GetFileDescriptor();
83 const FileDescriptor* GetFileDescriptor() const;
84
85 // Duplicates the underlying OS resources.
86 SharedMemoryHandle Duplicate() const;
87
88 private:
89 Mechanism mechanism_;
90 FileDescriptor file_descriptor_;
91 };
92 #elif defined(OS_POSIX)
93 typedef FileDescriptor SharedMemoryHandle;
94 #endif
95
96 } // namespace base
97
98 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698