]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IOCommandPool.cpp
xnu-7195.101.1.tar.gz
[apple/xnu.git] / iokit / Kernel / IOCommandPool.cpp
index d61f37fc3a7171fd7116b5383dbdbfa68eeadfc0..0dcb24e0f0522e51fa819853498f33ba83bfd092 100644 (file)
  *
  */
 
+#define IOKIT_ENABLE_SHARED_PTR
+
 #include <IOKit/IOCommandPool.h>
+#include <libkern/c++/OSSharedPtr.h>
 
 #define super OSObject
 OSDefineMetaClassAndStructors(IOCommandPool, OSObject);
@@ -54,15 +57,14 @@ OSMetaClassDefineReservedUnused(IOCommandPool, 7);
 //     withWorkLoop -  primary initializer and factory method
 //--------------------------------------------------------------------------
 
-IOCommandPool *
+OSSharedPtr<IOCommandPool>
 IOCommandPool::
 withWorkLoop(IOWorkLoop *inWorkLoop)
 {
-       IOCommandPool * me = new IOCommandPool;
+       OSSharedPtr<IOCommandPool> me = OSMakeShared<IOCommandPool>();
 
        if (me && !me->initWithWorkLoop(inWorkLoop)) {
-               me->release();
-               return 0;
+               return nullptr;
        }
 
        return me;
@@ -87,7 +89,7 @@ initWithWorkLoop(IOWorkLoop *inWorkLoop)
                return false;
        }
 
-       if (kIOReturnSuccess != inWorkLoop->addEventSource(fSerializer)) {
+       if (kIOReturnSuccess != inWorkLoop->addEventSource(fSerializer.get())) {
                return false;
        }
 
@@ -98,15 +100,14 @@ initWithWorkLoop(IOWorkLoop *inWorkLoop)
 //     commandPool & init -    obsolete initializer and factory method
 //--------------------------------------------------------------------------
 
-IOCommandPool *
+OSSharedPtr<IOCommandPool>
 IOCommandPool::
 commandPool(IOService * inOwner, IOWorkLoop *inWorkLoop, UInt32 inSize)
 {
-       IOCommandPool * me = new IOCommandPool;
+       OSSharedPtr<IOCommandPool> me = OSMakeShared<IOCommandPool>();
 
        if (me && !me->init(inOwner, inWorkLoop, inSize)) {
-               me->release();
-               return 0;
+               return nullptr;
        }
 
        return me;
@@ -131,11 +132,10 @@ IOCommandPool::free(void)
                // remove our event source from owner's workloop
                IOWorkLoop *wl = fSerializer->getWorkLoop();
                if (wl) {
-                       wl->removeEventSource(fSerializer);
+                       wl->removeEventSource(fSerializer.get());
                }
 
-               fSerializer->release();
-               fSerializer = 0;
+               fSerializer.reset();
        }
 
        // Tell our superclass to cleanup too
@@ -149,20 +149,20 @@ IOCommandPool::free(void)
 //                     waiting for resources
 //--------------------------------------------------------------------------
 
-IOCommand *
+OSSharedPtr<IOCommand>
 IOCommandPool::getCommand(bool blockForCommand)
 {
        IOReturn     result  = kIOReturnSuccess;
-       IOCommand *command = 0;
+       IOCommand *command = NULL;
 
        IOCommandGate::Action func = OSMemberFunctionCast(
                IOCommandGate::Action, this, &IOCommandPool::gatedGetCommand);
        result = fSerializer->
            runAction(func, (void *) &command, (void *) blockForCommand);
        if (kIOReturnSuccess == result) {
-               return command;
+               return OSSharedPtr<IOCommand>(command, OSNoRetain);
        } else {
-               return 0;
+               return NULL;
        }
 }