diff options
author | tschmelcher@chromium.org <tschmelcher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 23:06:34 +0000 |
---|---|---|
committer | tschmelcher@chromium.org <tschmelcher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 23:06:34 +0000 |
commit | 913015aec3f4418c9e5da1aaa340ea8fde2cdc39 (patch) | |
tree | dd5f6bddeee1f1d5d7e9424e68fbb015e571c9cd /o3d | |
parent | 36fcf85780dc3fbd595fddb4bfb94c1aeba01152 (diff) | |
download | chromium_src-913015aec3f4418c9e5da1aaa340ea8fde2cdc39.zip chromium_src-913015aec3f4418c9e5da1aaa340ea8fde2cdc39.tar.gz chromium_src-913015aec3f4418c9e5da1aaa340ea8fde2cdc39.tar.bz2 |
Fix multiple issues in the way O3D IPC server address name strings were generated:
- They had a small chance of colliding. e.g., message queue 41 for process 4 and message queue 1 for process 44 would both attempt to acquire the name "o3d441", and whichever one came second would fail since it was already in use. The fix is to separate the PID and instance number with a hypen. This way the names in such a case become "o3d4-41" and "o3d41-4", which are distinct.
- The PID in the name was truncated if it was greater than 65535 (possible in some edge cases on Windows and Linux).
- Incrementing of the per-process id was not thread-safe.
TEST=loaded o3d on Linux and verified IPC still works
BUG=none
Review URL: http://codereview.chromium.org/6578008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75810 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r-- | o3d/core/cross/message_queue.cc | 13 | ||||
-rw-r--r-- | o3d/core/cross/message_queue.h | 11 |
2 files changed, 14 insertions, 10 deletions
diff --git a/o3d/core/cross/message_queue.cc b/o3d/core/cross/message_queue.cc index 42f46804..617fde6 100644 --- a/o3d/core/cross/message_queue.cc +++ b/o3d/core/cross/message_queue.cc @@ -53,7 +53,7 @@ namespace o3d { -int MessageQueue::next_message_queue_id_ = 0; +volatile ::base::subtle::Atomic32 MessageQueue::last_message_queue_id_ = -1; // Prefix used to name all server socket addresses for O3D. const char kServerSocketAddressPrefix[] = "o3d"; @@ -143,6 +143,9 @@ MessageQueue::MessageQueue(ServiceLocator* service_locator) pid_t proc_id = getpid(); #endif + int id = ::base::subtle::NoBarrier_AtomicIncrement(&last_message_queue_id_, + 1); + // Create a unique name for the socket used by the message queue. // We use part of the process id to distinguish between different // browsers running o3d at the same time as well as a count to @@ -150,10 +153,10 @@ MessageQueue::MessageQueue(ServiceLocator* service_locator) // browser. ::base::snprintf(server_socket_address_.path, sizeof(server_socket_address_.path), - "%s%d%d", kServerSocketAddressPrefix, (proc_id & 0xFFFF), - next_message_queue_id_); - - next_message_queue_id_++; + "%s%u-%d", + kServerSocketAddressPrefix, + static_cast<unsigned int>(proc_id), + id); } MessageQueue::~MessageQueue() { diff --git a/o3d/core/cross/message_queue.h b/o3d/core/cross/message_queue.h index a129e0f..42924e7 100644 --- a/o3d/core/cross/message_queue.h +++ b/o3d/core/cross/message_queue.h @@ -38,9 +38,11 @@ #define O3D_CORE_CROSS_MESSAGE_QUEUE_H_ #include <vector> -#include "native_client/src/shared/imc/nacl_imc.h" + +#include "base/atomicops.h" #include "core/cross/types.h" #include "core/cross/message_commands.h" +#include "native_client/src/shared/imc/nacl_imc.h" namespace o3d { @@ -211,10 +213,9 @@ class MessageQueue { // created shared memory buffer. int32 next_shared_memory_id_; - // Stores the next available unique id for message queues. This allows - // us to create multiple instances of the MessageQueue, each with a unique - // address. - static int next_message_queue_id_; + // Stores the last used unique id for message queues. This allows us to + // create multiple instances of the MessageQueue, each with a unique address. + static volatile ::base::subtle::Atomic32 last_message_queue_id_; bool has_new_texture_; |