[haiku-commits] haiku: hrev53381 - src/kits/media

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 16 Aug 2019 19:55:11 -0400 (EDT)

hrev53381 adds 1 changeset to branch 'master'
old head: b5be469eee595f20dc4ff094869fe16611953151
new head: 472d26a3c0a3f0af2932079147a0a273bcf18f7b
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=472d26a3c0a3+%5Eb5be469eee59

----------------------------------------------------------------------------

472d26a3c0a3: Media Kit: Delete the PortPool in a more deliberate way
  
  Letting it get deleted statically can cause segfaults since it is needed for
  some final quit messages.
  
  This mimic changes Axel made for the DormantNodeManager and
  TimeSourceObjectManager.
  
  I also pulled PortPool into its own file and header.
  
  Fixes #15135.
  
  Change-Id: Ie64753e1876d58b52f7cb95536c6be3df2e6d40c
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/1721
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

                                  [ Ryan Leavengood <leavengood@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev53381
Commit:      472d26a3c0a3f0af2932079147a0a273bcf18f7b
URL:         https://git.haiku-os.org/haiku/commit/?id=472d26a3c0a3
Author:      Ryan Leavengood <leavengood@xxxxxxxxx>
Date:        Fri Aug 16 22:23:11 2019 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Fri Aug 16 23:55:07 2019 UTC

Ticket:      https://dev.haiku-os.org/ticket/15135

----------------------------------------------------------------------------

5 files changed, 127 insertions(+), 70 deletions(-)
src/kits/media/Jamfile          |  1 +
src/kits/media/MediaRoster.cpp  |  7 ++++
src/kits/media/PortPool.cpp     | 73 ++++++++++++++++++++++++++++++++++++
src/kits/media/PortPool.h       | 41 ++++++++++++++++++++
src/kits/media/request_data.cpp | 75 +++----------------------------------

----------------------------------------------------------------------------

diff --git a/src/kits/media/Jamfile b/src/kits/media/Jamfile
index 6d58df4a28..9ef1106f4d 100644
--- a/src/kits/media/Jamfile
+++ b/src/kits/media/Jamfile
@@ -63,6 +63,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
                        FormatManager.cpp
                        MediaRecorderNode.cpp
                        Notifications.cpp
+                       PortPool.cpp
                        request_data.cpp
                        SharedBufferList.cpp
                        TrackReader.cpp
diff --git a/src/kits/media/MediaRoster.cpp b/src/kits/media/MediaRoster.cpp
index 77529bfc9e..f3ae2ad7ea 100644
--- a/src/kits/media/MediaRoster.cpp
+++ b/src/kits/media/MediaRoster.cpp
@@ -70,6 +70,7 @@ char __dont_remove_copyright_from_binary[] = "Copyright (c) 
2002-2006 Marcus "
 #include <SharedBufferList.h>
 #include <TList.h>
 
+#include "PortPool.h"
 #include "TimeSourceObjectManager.h"
 
 
@@ -144,6 +145,9 @@ public:
                        wait_for_thread(roster, &err);
                        if (err != B_OK)
                                ERROR("BMediaRoster: wait_for_thread returned 
error");
+
+                       // Only now delete the port pool
+                       delete gPortPool;
                }
        }
 };
@@ -165,6 +169,9 @@ BMediaRosterEx::BMediaRosterEx(status_t* _error)
 {
        gDormantNodeManager = new DormantNodeManager();
        gTimeSourceObjectManager = new TimeSourceObjectManager();
+       gPortPool = new PortPool();
+               // This is created here but deleted in the 
MediaRosterUndertaker because
+               // otherwise there are segfaults trying to send final quit 
messages.
 
        *_error = BuildConnections();
 
diff --git a/src/kits/media/PortPool.cpp b/src/kits/media/PortPool.cpp
new file mode 100644
index 0000000000..e19e3fcdb0
--- /dev/null
+++ b/src/kits/media/PortPool.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include <set>
+
+#include <Autolock.h>
+#include <Locker.h>
+
+#include <MediaDebug.h>
+
+#include "PortPool.h"
+
+
+namespace BPrivate {
+namespace media {
+
+
+PortPool* gPortPool;
+       // initialized by BMediaRosterEx, deleted by MediaRosterUndertaker.
+
+
+PortPool::PortPool()
+       :
+       BLocker("port pool")
+{
+}
+
+
+PortPool::~PortPool()
+{
+       PortSet::iterator iterator = fPool.begin();
+
+       for (; iterator != fPool.end(); iterator++)
+               delete_port(*iterator);
+}
+
+
+port_id
+PortPool::GetPort()
+{
+       BAutolock _(this);
+
+       if (fPool.empty())
+               return create_port(1, "media reply port");
+
+       port_id port = *fPool.begin();
+       fPool.erase(port);
+
+       ASSERT(port >= 0);
+       return port;
+}
+
+
+void
+PortPool::PutPort(port_id port)
+{
+       ASSERT(port >= 0);
+
+       BAutolock _(this);
+
+       try {
+               fPool.insert(port);
+       } catch (std::bad_alloc& exception) {
+               delete_port(port);
+       }
+}
+
+
+}      // namespace media
+}      // namespace BPrivate
diff --git a/src/kits/media/PortPool.h b/src/kits/media/PortPool.h
new file mode 100644
index 0000000000..2594749386
--- /dev/null
+++ b/src/kits/media/PortPool.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2019, Ryan Leavengood
+ * Copyright 2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef _PORT_POOL_H
+#define _PORT_POOL_H
+
+
+#include <ServerInterface.h>
+
+#include <set>
+
+
+namespace BPrivate {
+namespace media {
+
+
+class PortPool : BLocker {
+public:
+                                                               PortPool();
+                                                               ~PortPool();
+
+                       port_id                         GetPort();
+                       void                            PutPort(port_id port);
+
+private:
+                       typedef std::set<port_id> PortSet;
+
+                       PortSet                         fPool;
+};
+
+
+extern PortPool* gPortPool;
+
+
+}      // namespace media
+}      // namespace BPrivate
+
+
+#endif // _PORT_POOL_H
\ No newline at end of file
diff --git a/src/kits/media/request_data.cpp b/src/kits/media/request_data.cpp
index c4b9fe7a7c..ceb0fa9376 100644
--- a/src/kits/media/request_data.cpp
+++ b/src/kits/media/request_data.cpp
@@ -1,4 +1,5 @@
 /*
+ * Copyright 2019, Ryan Leavengood
  * Copyright 2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
  * Distributed under the terms of the MIT License.
  */
@@ -14,88 +15,22 @@
 #include <DataExchange.h>
 #include <MediaDebug.h>
 
+#include "PortPool.h"
+
 
 namespace BPrivate {
 namespace media {
 
 
-class PortPool : BLocker {
-public:
-                                                               PortPool();
-                                                               ~PortPool();
-
-                       port_id                         GetPort();
-                       void                            PutPort(port_id port);
-
-private:
-                       typedef std::set<port_id> PortSet;
-
-                       PortSet                         fPool;
-};
-
-
-static PortPool sPortPool;
-
-
-PortPool::PortPool()
-       :
-       BLocker("port pool")
-{
-}
-
-
-PortPool::~PortPool()
-{
-       PortSet::iterator iterator = fPool.begin();
-
-       for (; iterator != fPool.end(); iterator++)
-               delete_port(*iterator);
-}
-
-
-port_id
-PortPool::GetPort()
-{
-       BAutolock _(this);
-
-       if (fPool.empty())
-               return create_port(1, "media reply port");
-
-       port_id port = *fPool.begin();
-       fPool.erase(port);
-
-       ASSERT(port >= 0);
-       return port;
-}
-
-
-void
-PortPool::PutPort(port_id port)
-{
-       ASSERT(port >= 0);
-
-       BAutolock _(this);
-
-       try {
-               fPool.insert(port);
-       } catch (std::bad_alloc& exception) {
-               delete_port(port);
-       }
-}
-
-
-// #pragma mark -
-
-
 request_data::request_data()
 {
-       reply_port = sPortPool.GetPort();
+       reply_port = gPortPool->GetPort();
 }
 
 
 request_data::~request_data()
 {
-       sPortPool.PutPort(reply_port);
+       gPortPool->PutPort(reply_port);
 }
 
 


Other related posts:

  • » [haiku-commits] haiku: hrev53381 - src/kits/media - waddlesplash