* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
+#define IOKIT_ENABLE_SHARED_PTR
+
+#include <libkern/c++/OSSharedPtr.h>
#include <IOKit/IOKernelReportStructs.h>
#include <IOKit/IOKernelReporters.h>
#include "IOReporterDefs.h"
/* static */
-IOStateReporter*
+OSSharedPtr<IOStateReporter>
IOStateReporter::with(IOService *reportingService,
IOReportCategories categories,
int nstates,
IOReportUnit unit /* = kIOReportUnitHWTicks*/)
{
- IOStateReporter *reporter, *rval = NULL;
-
- // kprintf("%s\n", __func__); // can't IORLOG() from static
+ OSSharedPtr<IOStateReporter> reporter;
- reporter = new IOStateReporter;
- if (!reporter) {
- goto finish;
+ if (nstates > INT16_MAX) {
+ return nullptr;
}
- if (!reporter->initWith(reportingService, categories, nstates, unit)) {
- goto finish;
+ reporter = OSMakeShared<IOStateReporter>();
+ if (!reporter) {
+ return nullptr;
}
- // success
- rval = reporter;
-
-finish:
- if (!rval) {
- OSSafeReleaseNULL(reporter);
+ if (!reporter->initWith(reportingService, categories, (int16_t) nstates, unit)) {
+ return nullptr;
}
- return rval;
+ return reporter;
}
bool