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

Unified Diff: base/shared_memory_posix.cc

Issue 7184032: Upstream android file related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update DEPS Created 9 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 side-by-side diff with in-line comments
Download patch
Index: base/shared_memory_posix.cc
diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc
index 7a238ed880b12a641b7461fc01285b7d169d9cc2..5651dc0232bac4dd5865d5ff7448df82ba4bbe02 100644
--- a/base/shared_memory_posix.cc
+++ b/base/shared_memory_posix.cc
@@ -24,10 +24,21 @@
namespace base {
namespace {
+
// Paranoia. Semaphores and shared memory segments should live in different
// namespaces, but who knows what's out there.
const char kSemaphoreSuffix[] = "-sem";
+
+#if defined(OS_ANDROID)
+// The lockf() function is not available on Android; we translate to flock().
+#define F_LOCK LOCK_EX
+#define F_ULOCK LOCK_UN
+inline int lockf(int fd, int cmd, off_t ignored_len) {
+ return flock(fd, cmd);
}
+#endif
+
+} // namespace.
SharedMemory::SharedMemory()
: mapped_file_(-1),
@@ -95,6 +106,7 @@ bool SharedMemory::CreateAnonymous(uint32 size) {
return CreateNamed("", false, size);
}
+#if !defined(OS_ANDROID)
// Chromium mostly only uses the unique/private shmem as specified by
// "name == L"". The exception is in the StatsTable.
// TODO(jrg): there is no way to "clean up" all unused named shmem if
@@ -177,6 +189,7 @@ bool SharedMemory::CreateNamed(const std::string& name,
// These files need to be deleted explicitly.
// In practice this call is only needed for unit tests.
bool SharedMemory::Delete(const std::string& name) {
+
joth 2011/06/19 12:48:05 nit: remove \n
michaelbai 2011/06/20 22:50:36 Done.
FilePath path;
if (!FilePathForMemoryName(name, &path))
return false;
@@ -201,10 +214,25 @@ bool SharedMemory::Open(const std::string& name, bool read_only) {
return PrepareMapFile(fp);
}
+#endif // !defined(OS_ANDROID)
+
bool SharedMemory::Map(uint32 bytes) {
if (mapped_file_ == -1)
return false;
+#if defined(OS_ANDROID)
+ int ashmem_bytes = GetAshmenSizeRegion();
+ DCHECK_GE((uint32)ashmem_bytes, bytes);
joth 2011/06/19 12:48:05 nit: static_cast<uint32>(ashmem_bytes) although th
michaelbai 2011/06/20 22:50:36 Done.
+ if (bytes == 0) {
+ // The caller wants to determine the map region size from ashmem.
+ bytes = ashmem_bytes;
+ // TODO(port): we set the created size here so that it is available in
+ // transport_dib_android.cc. We should use
+ // SharedMemory::GetAshmenSizeRegion() in TransportDIB::Map().
+ created_size_ = bytes;
+ }
+#endif
joth 2011/06/19 12:48:05 seems unfortunate to commit this hack when the cod
+
memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE),
MAP_SHARED, mapped_file_, 0);
@@ -248,6 +276,7 @@ void SharedMemory::Unlock() {
LockOrUnlockCommon(F_ULOCK);
}
+#if !defined(OS_ANDROID)
bool SharedMemory::PrepareMapFile(FILE *fp) {
DCHECK_EQ(-1, mapped_file_);
if (fp == NULL) return false;
@@ -276,6 +305,7 @@ bool SharedMemory::PrepareMapFile(FILE *fp) {
return true;
}
+#endif
// For the given shmem named |mem_name|, return a filename to mmap()
// (and possibly create). Modifies |filename|. Return false on

Powered by Google App Engine
This is Rietveld 408576698