mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
Wrap code for posting of notifications (for becoming multithreaded and for a thread being about to exit) in an autorelease loop. This should avoid possible leakage of objects and warnings during the notification process.
This commit is contained in:
parent
1be8a1375a
commit
6fd8dd7a20
1 changed files with 7 additions and 2 deletions
|
@ -763,6 +763,7 @@ GSCurrentThreadDictionary(void)
|
|||
static void
|
||||
gnustep_base_thread_callback(void)
|
||||
{
|
||||
static pthread_mutex_t threadLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
/*
|
||||
* Protect this function with locking ... to avoid any possibility
|
||||
* of multiple threads registering with the system simultaneously,
|
||||
|
@ -771,9 +772,10 @@ gnustep_base_thread_callback(void)
|
|||
*/
|
||||
if (entered_multi_threaded_state == NO)
|
||||
{
|
||||
[gnustep_global_lock lock];
|
||||
pthread_mutex_lock(&threadLock);
|
||||
if (entered_multi_threaded_state == NO)
|
||||
{
|
||||
ENTER_POOL
|
||||
/*
|
||||
* For apple compatibility ... and to make things easier for
|
||||
* code called indirectly within a will-become-multi-threaded
|
||||
|
@ -814,8 +816,9 @@ gnustep_base_thread_callback(void)
|
|||
fflush(stderr);
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
LEAVE_POOL
|
||||
}
|
||||
[gnustep_global_lock unlock];
|
||||
pthread_mutex_unlock(&threadLock);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -862,6 +865,7 @@ unregisterActiveThread(NSThread *thread)
|
|||
{
|
||||
/* Let observers know this thread is exiting.
|
||||
*/
|
||||
ENTER_POOL
|
||||
if (nc == nil)
|
||||
{
|
||||
nc = RETAIN([NSNotificationCenter defaultCenter]);
|
||||
|
@ -877,6 +881,7 @@ unregisterActiveThread(NSThread *thread)
|
|||
thread->_finished = YES;
|
||||
|
||||
[(GSRunLoopThreadInfo*)thread->_runLoopInfo invalidate];
|
||||
LEAVE_POOL
|
||||
RELEASE(thread);
|
||||
pthread_setspecific(thread_object_key, nil);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue