Title: [102927] trunk/Source/WebKit2
Revision
102927
Author
[email protected]
Date
2011-12-15 05:19:31 -0800 (Thu, 15 Dec 2011)

Log Message

[WK2] Eliminate unnecessary GTK/QT ifdefs for shared memory implementation
https://bugs.webkit.org/show_bug.cgi?id=74602

Patch by Simon Hausmann <[email protected]> on 2011-12-15
Reviewed by Kenneth Rohde Christiansen.

For shared memory Qt was using shm_open, Gtk was using files in /tmp. There
is no reason to obfuscate the code with #ifdefs or let Gtk use an inferior
method of opening shared memory. So this patch makes SharedMemoryUnix.cpp
truly Qt and Gtk independent.

* Platform/unix/SharedMemoryUnix.cpp:
(WebKit::SharedMemory::create):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (102926 => 102927)


--- trunk/Source/WebKit2/ChangeLog	2011-12-15 13:18:44 UTC (rev 102926)
+++ trunk/Source/WebKit2/ChangeLog	2011-12-15 13:19:31 UTC (rev 102927)
@@ -1,5 +1,20 @@
 2011-12-15  Simon Hausmann  <[email protected]>
 
+        [WK2] Eliminate unnecessary GTK/QT ifdefs for shared memory implementation
+        https://bugs.webkit.org/show_bug.cgi?id=74602
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        For shared memory Qt was using shm_open, Gtk was using files in /tmp. There
+        is no reason to obfuscate the code with #ifdefs or let Gtk use an inferior
+        method of opening shared memory. So this patch makes SharedMemoryUnix.cpp
+        truly Qt and Gtk independent.
+
+        * Platform/unix/SharedMemoryUnix.cpp:
+        (WebKit::SharedMemory::create):
+
+2011-12-15  Simon Hausmann  <[email protected]>
+
         [Qt] Cleanup: Remove unnecessary const_cast
 
         Reviewed by Kenneth Christiansen.

Modified: trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp (102926 => 102927)


--- trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp	2011-12-15 13:18:44 UTC (rev 102926)
+++ trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp	2011-12-15 13:19:31 UTC (rev 102927)
@@ -41,14 +41,9 @@
 #include <unistd.h>
 #include <wtf/Assertions.h>
 #include <wtf/CurrentTime.h>
+#include <wtf/RandomNumber.h>
+#include <wtf/text/CString.h>
 
-#if PLATFORM(QT)
-#include <QDir>
-#elif PLATFORM(GTK)
-#include <glib.h>
-#include <wtf/gobject/GOwnPtr.h>
-#endif
-
 namespace WebKit {
 
 SharedMemory::Handle::Handle()
@@ -104,42 +99,24 @@
 
 PassRefPtr<SharedMemory> SharedMemory::create(size_t size)
 {
-#if PLATFORM(QT)
-    QByteArray tempNameCSTR("/qwkshm.");
-    tempNameCSTR += QByteArray::number(qrand(), 36);
-    char* tempNameC = tempNameCSTR.data();
-#elif PLATFORM(GTK)
-    GOwnPtr<gchar> tempName(g_build_filename(g_get_tmp_dir(), "WK2SharedMemoryXXXXXX", NULL));
-    gchar* tempNameC = tempName.get();
-#endif
+    CString tempName;
 
-    int fileDescriptor;
-#if PLATFORM(QT)
-    while ((fileDescriptor = shm_open(tempNameC, O_CREAT | O_CLOEXEC | O_RDWR, S_IRUSR | S_IWUSR)) == -1) {
-        if (errno != EINTR)
-            return 0;
+    int fileDescriptor = -1;
+    for (int tries = 0; fileDescriptor == -1 && tries < 10; ++tries) {
+        String name = String("/WK2SharedMemory.") + String::number(static_cast<unsigned>(WTF::randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)));
+        tempName = name.utf8();
+
+        do {
+            fileDescriptor = shm_open(tempName.data(), O_CREAT | O_CLOEXEC | O_RDWR, S_IRUSR | S_IWUSR);
+        } while (fileDescriptor == -1 && errno == EINTR);
     }
-#else
-    while ((fileDescriptor = mkstemp(tempNameC)) == -1) {
-        if (errno != EINTR)
-            return 0;
-    }
-    while (fcntl(fileDescriptor, F_SETFD, FD_CLOEXEC) == -1) {
-        if (errno != EINTR) {
-            while (close(fileDescriptor) == -1 && errno == EINTR) { }
-            unlink(tempNameC);
-            return 0;
-        }
-    }
-#endif
+    if (fileDescriptor == -1)
+        return 0;
+
     while (ftruncate(fileDescriptor, size) == -1) {
         if (errno != EINTR) {
             while (close(fileDescriptor) == -1 && errno == EINTR) { }
-#if PLATFORM(QT)
-            shm_unlink(tempNameC);
-#else
-            unlink(tempNameC);
-#endif
+            shm_unlink(tempName.data());
             return 0;
         }
     }
@@ -147,19 +124,11 @@
     void* data = "" size, PROT_READ | PROT_WRITE, MAP_SHARED, fileDescriptor, 0);
     if (data == MAP_FAILED) {
         while (close(fileDescriptor) == -1 && errno == EINTR) { }
-#if PLATFORM(QT)
-        shm_unlink(tempNameC);
-#else
-        unlink(tempNameC);
-#endif
+        shm_unlink(tempName.data());
         return 0;
     }
 
-#if PLATFORM(QT)
-    shm_unlink(tempNameC);
-#else
-    unlink(tempNameC);
-#endif
+    shm_unlink(tempName.data());
 
     RefPtr<SharedMemory> instance = adoptRef(new SharedMemory());
     instance->m_data = data;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to