summaryrefslogtreecommitdiff
path: root/src/SFML/Window/OSX/AutoreleasePoolWrapper.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/SFML/Window/OSX/AutoreleasePoolWrapper.mm')
-rw-r--r--src/SFML/Window/OSX/AutoreleasePoolWrapper.mm77
1 files changed, 11 insertions, 66 deletions
diff --git a/src/SFML/Window/OSX/AutoreleasePoolWrapper.mm b/src/SFML/Window/OSX/AutoreleasePoolWrapper.mm
index 6b341b2..9b33184 100644
--- a/src/SFML/Window/OSX/AutoreleasePoolWrapper.mm
+++ b/src/SFML/Window/OSX/AutoreleasePoolWrapper.mm
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2018 Marco Antognini (antognini.marco@gmail.com),
+// Copyright (C) 2007-2023 Marco Antognini (antognini.marco@gmail.com),
// Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
@@ -26,80 +26,25 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
-#include <cassert>
-#include <pthread.h>
-#import <SFML/Window/OSX/AutoreleasePoolWrapper.h>
-#import <Foundation/Foundation.h>
-
-
-////////////////////////////////////////////////////////////
-/// Here we manage one and only one pool by thread. This prevents draining one
-/// pool and making other pools invalid which can lead to a crash on 10.5 and an
-/// annoying message on 10.6 (*** attempt to pop an unknown autorelease pool).
-///
-////////////////////////////////////////////////////////////
-
-
-////////////////////////////////////////////////////////////
-// Private data
-////////////////////////////////////////////////////////////
-static pthread_key_t poolKey;
-static pthread_once_t initOnceToken = PTHREAD_ONCE_INIT;
-
-
-////////////////////////////////////////////////////////////
-/// \brief (local function) Drain one more time the pool
-/// but this time don't create a new one.
-///
-////////////////////////////////////////////////////////////
-static void destroyPool(void* data)
-{
- NSAutoreleasePool* pool = (NSAutoreleasePool*)data;
- [pool drain];
-}
+#include <SFML/Window/OSX/AutoreleasePoolWrapper.hpp>
+#import <Foundation/Foundation.h>
-////////////////////////////////////////////////////////////
-/// \brief (local function) Init the pthread key for the pool
-///
-////////////////////////////////////////////////////////////
-static void createPoolKey(void)
+namespace sf
{
- pthread_key_create(&poolKey, destroyPool);
-}
-
-////////////////////////////////////////////////////////////
-/// \brief (local function) Store a new pool for this thread
-///
-////////////////////////////////////////////////////////////
-static void createNewPool(void)
+////////////////////////////////////////////////////////
+AutoreleasePool::AutoreleasePool()
{
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- pthread_setspecific(poolKey, pool);
+ pool = [[NSAutoreleasePool alloc] init];
}
-////////////////////////////////////////////////////////////
-void ensureThreadHasPool(void)
+////////////////////////////////////////////////////////
+AutoreleasePool::~AutoreleasePool()
{
- pthread_once(&initOnceToken, createPoolKey);
- if (pthread_getspecific(poolKey) == NULL)
- {
- createNewPool();
- }
-}
-
-
-////////////////////////////////////////////////////////////
-void drainThreadPool(void)
-{
- void* data = pthread_getspecific(poolKey);
- assert(data != NULL);
-
- // Drain the pool but keep it alive by creating a new one
- destroyPool(data);
- createNewPool();
+ [pool drain];
}
+} // namespace sf