[K/N] Move AutoreleasePool into objc_support ^KT-63423
This commit is contained in:
committed by
Space Team
parent
815b452435
commit
c4992f1912
@@ -17,9 +17,9 @@
|
||||
#include "ScopedThread.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "Logging.hpp"
|
||||
#include "objc_support/AutoreleasePool.hpp"
|
||||
|
||||
#if KONAN_OBJC_INTEROP
|
||||
#include "ObjCMMAPI.h"
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CoreFoundation/CFRunLoop.h>
|
||||
#endif
|
||||
@@ -100,9 +100,7 @@ private:
|
||||
|
||||
void processSingle(FinalizerQueue&& queue, int64_t currentEpoch) noexcept {
|
||||
if (!FinalizerQueueTraits::isEmpty(queue)) {
|
||||
#if KONAN_OBJC_INTEROP
|
||||
konan::AutoreleasePool autoreleasePool;
|
||||
#endif
|
||||
objc_support::AutoreleasePool autoreleasePool;
|
||||
ThreadStateGuard guard(ThreadState::kRunnable);
|
||||
FinalizerQueueTraits::process(std::move(queue));
|
||||
}
|
||||
@@ -150,7 +148,7 @@ private:
|
||||
}
|
||||
|
||||
void body() override {
|
||||
konan::AutoreleasePool autoreleasePool;
|
||||
objc_support::AutoreleasePool autoreleasePool;
|
||||
auto mode = kCFRunLoopDefaultMode;
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource_, mode);
|
||||
|
||||
|
||||
@@ -335,14 +335,6 @@ id objc_allocWithZone(Class clazz);
|
||||
id objc_retain(id ptr);
|
||||
void objc_release(id ptr);
|
||||
|
||||
konan::AutoreleasePool::AutoreleasePool()
|
||||
: handle(objc_autoreleasePoolPush()) {}
|
||||
|
||||
konan::AutoreleasePool::~AutoreleasePool() {
|
||||
kotlin::ThreadStateGuard guard(kotlin::ThreadState::kNative, true);
|
||||
objc_autoreleasePoolPop(handle);
|
||||
}
|
||||
|
||||
void* Kotlin_objc_autoreleasePoolPush() {
|
||||
return objc_autoreleasePoolPush();
|
||||
}
|
||||
|
||||
@@ -7,23 +7,11 @@
|
||||
#define RUNTIME_OBJCMMAPI_H
|
||||
|
||||
#include "Common.h"
|
||||
#include "Utils.hpp"
|
||||
|
||||
#if KONAN_OBJC_INTEROP
|
||||
|
||||
extern "C" ALWAYS_INLINE void Kotlin_ObjCExport_releaseAssociatedObject(void* associatedObject);
|
||||
|
||||
namespace konan {
|
||||
class AutoreleasePool : private kotlin::Pinned {
|
||||
public:
|
||||
AutoreleasePool();
|
||||
~AutoreleasePool();
|
||||
|
||||
private:
|
||||
void* handle;
|
||||
};
|
||||
} // namespace konan
|
||||
|
||||
#endif // KONAN_OBJC_INTEROP
|
||||
|
||||
#endif // RUNTIME_OBJCMMAPI_H
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <deque>
|
||||
#include <set>
|
||||
@@ -29,10 +30,10 @@
|
||||
#include "KAssert.h"
|
||||
#include "Memory.h"
|
||||
#include "Natives.h"
|
||||
#include "ObjCMMAPI.h"
|
||||
#include "Runtime.h"
|
||||
#include "Types.h"
|
||||
#include "Worker.h"
|
||||
#include "objc_support/AutoreleasePool.hpp"
|
||||
|
||||
using namespace kotlin;
|
||||
|
||||
@@ -1036,9 +1037,7 @@ JobKind Worker::processQueueElement(bool blocking) {
|
||||
ObjHolder operationHolder, dummyHolder;
|
||||
KRef obj = DerefStablePointer(job.executeAfter.operation, operationHolder.slot());
|
||||
try {
|
||||
#if KONAN_OBJC_INTEROP
|
||||
konan::AutoreleasePool autoreleasePool;
|
||||
#endif
|
||||
objc_support::AutoreleasePool autoreleasePool;
|
||||
WorkerLaunchpad(obj, dummyHolder.slot());
|
||||
} catch(ExceptionObjHolder& e) {
|
||||
switch (exceptionHandling()) {
|
||||
@@ -1062,9 +1061,7 @@ JobKind Worker::processQueueElement(bool blocking) {
|
||||
ObjHolder resultHolder;
|
||||
KRef argument = AdoptStablePointer(job.regularJob.argument, argumentHolder.slot());
|
||||
try {
|
||||
#if KONAN_OBJC_INTEROP
|
||||
konan::AutoreleasePool autoreleasePool;
|
||||
#endif
|
||||
objc_support::AutoreleasePool autoreleasePool;
|
||||
{
|
||||
CurrentFrameGuard guard;
|
||||
job.regularJob.function(argument, resultHolder.slot());
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "AutoreleasePool.hpp"
|
||||
#include "Memory.h"
|
||||
|
||||
using namespace kotlin;
|
||||
|
||||
#if KONAN_OBJC_INTEROP
|
||||
|
||||
// Obj-C runtime provided by clang.
|
||||
extern "C" void* objc_autoreleasePoolPush(void);
|
||||
extern "C" void objc_autoreleasePoolPop(void*);
|
||||
|
||||
objc_support::AutoreleasePool::AutoreleasePool() noexcept : handle_(objc_autoreleasePoolPush()) {}
|
||||
|
||||
objc_support::AutoreleasePool::~AutoreleasePool() {
|
||||
NativeOrUnregisteredThreadGuard guard(/* reentrant = */ true);
|
||||
objc_autoreleasePoolPop(handle_);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
objc_support::AutoreleasePool::AutoreleasePool() noexcept = default;
|
||||
objc_support::AutoreleasePool::~AutoreleasePool() = default;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Utils.hpp"
|
||||
|
||||
namespace kotlin::objc_support {
|
||||
|
||||
class AutoreleasePool : private Pinned {
|
||||
public:
|
||||
AutoreleasePool() noexcept;
|
||||
~AutoreleasePool();
|
||||
|
||||
private:
|
||||
#if KONAN_OBJC_INTEROP
|
||||
void* handle_;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace kotlin::objc_support
|
||||
Reference in New Issue
Block a user