@ -377,10 +377,11 @@ int TQApplication::composedUnicode = 0;
TQMutex * TQApplication : : tqt_mutex = 0 ;
TQMutex * TQApplication : : tqt_mutex = 0 ;
TQMutex * tqt_sharedStringMutex = 0 ;
TQMutex * tqt_sharedStringMutex = 0 ;
TQ_EXPORT TQMutex * tqt_sharedMetaObjectMutex = 0 ;
TQ_EXPORT TQMutex * tqt_sharedMetaObjectMutex = 0 ;
# ifdef QT_USE_GLIBMAINLOOP
# ifdef QT_USE_GLIBMAINLOOP
TQMutex * tqt_timerListMutex = 0 ;
TQMutex * tqt_timerListMutex = 0 ;
# endif // QT_USE_GLIBMAINLOOP
# endif // QT_USE_GLIBMAINLOOP
static TQMutex * postevent_mutex = 0 ;
static TQt : : HANDLE tqt_application_thread_id = 0 ;
static TQt : : HANDLE tqt_application_thread_id = 0 ;
TQ_EXPORT TQt : : HANDLE tqt_get_application_thread_id ( )
TQ_EXPORT TQt : : HANDLE tqt_get_application_thread_id ( )
{
{
@ -595,7 +596,7 @@ static TQCoreApplicationThread tqt_main_thread;
// Definitions for posted events
// Definitions for posted events
struct TQPostEvent {
struct TQPostEvent {
TQPostEvent ( TQObject * r , TQEvent * e ) : receiver ( r ) , event ( e ) { }
TQPostEvent ( TQObject * r , TQEvent * e ) : receiver ( r ) , event ( e ) { }
~ TQPostEvent ( ) { delete event ; }
~ TQPostEvent ( ) { delete event ; }
TQObject * receiver ;
TQObject * receiver ;
TQEvent * event ;
TQEvent * event ;
} ;
} ;
@ -603,36 +604,68 @@ struct TQPostEvent {
class TQ_EXPORT TQPostEventList : public TQPtrList < TQPostEvent >
class TQ_EXPORT TQPostEventList : public TQPtrList < TQPostEvent >
{
{
public :
public :
TQPostEventList ( ) : TQPtrList < TQPostEvent > ( ) { }
TQPostEventList ( bool with_mutex = false ) : TQPtrList < TQPostEvent > ( ) , m_mutex ( nullptr )
TQPostEventList ( const TQPostEventList & list ) : TQPtrList < TQPostEvent > ( list ) { }
{
~ TQPostEventList ( ) { clear ( ) ; }
# ifdef TQT_THREAD_SUPPORT
TQPostEventList & operator = ( const TQPostEventList & list )
if ( with_mutex )
{ return ( TQPostEventList & ) TQPtrList < TQPostEvent > : : operator = ( list ) ; }
{
m_mutex = new TQMutex ( TRUE ) ;
}
# endif
}
~ TQPostEventList ( )
{
if ( m_mutex )
{
delete m_mutex ;
m_mutex = nullptr ;
}
clear ( ) ;
}
TQMutex * mutex ( ) const { return m_mutex ; }
private :
TQMutex * m_mutex ;
TQPostEventList ( const TQPostEventList & ) = delete ;
TQPostEventList & operator = ( const TQPostEventList & ) = delete ;
} ;
} ;
class TQ_EXPORT TQPostEventListIt : public TQPtrListIterator < TQPostEvent >
class TQ_EXPORT TQPostEventListIt : public TQPtrListIterator < TQPostEvent >
{
{
public :
public :
TQPostEventListIt ( const TQPostEventList & l ) : TQPtrListIterator < TQPostEvent > ( l ) { }
TQPostEventListIt ( const TQPostEventList & l ) : TQPtrListIterator < TQPostEvent > ( l ) { }
TQPostEventListIt & operator = ( const TQPostEventListIt & i )
TQPostEventListIt & operator = ( const TQPostEventListIt & i )
{ return ( TQPostEventListIt & ) TQPtrListIterator < TQPostEvent > : : operator = ( i ) ; }
{
return ( TQPostEventListIt & ) TQPtrListIterator < TQPostEvent > : : operator = ( i ) ; }
} ;
} ;
static TQPostEventList * globalPostedEvents = 0 ; // list of posted events
// The global list and its pointer are initialized in different functions
// to optimize access to the list pointer in normal usage
static TQPostEventList * InitGlobalPostedEventsList ( )
{
static TQPostEventList _globalEventList ( true ) ;
_globalEventList . setAutoDelete ( TRUE ) ;
return & _globalEventList ;
}
static TQPostEventList * GlobalPostedEvents ( )
{
static TQPostEventList * _globalPostedEvents = InitGlobalPostedEventsList ( ) ;
return _globalPostedEvents ;
}
uint qGlobalPostedEventsCount ( )
uint qGlobalPostedEventsCount ( )
{
{
# ifdef TQT_THREAD_SUPPORT
# ifdef TQT_THREAD_SUPPORT
TQMutexLocker locker ( postevent_mutex ) ;
TQMutexLocker locker ( GlobalPostedEvents( ) - > mutex ( ) ) ;
# endif // TQT_THREAD_SUPPORT
# endif // TQT_THREAD_SUPPORT
if ( ! globalPostedEvents ) {
return GlobalPostedEvents ( ) - > count ( ) ;
return 0 ;
}
return globalPostedEvents - > count ( ) ;
}
}
static TQSingleCleanupHandler < TQPostEventList > qapp_cleanup_events ;
# ifndef TQT_NO_PALETTE
# ifndef TQT_NO_PALETTE
TQPalette * tqt_std_pal = 0 ;
TQPalette * tqt_std_pal = 0 ;
@ -1088,7 +1121,6 @@ void TQApplication::initialize( int argc, char **argv, bool enable_sm )
# ifdef QT_USE_GLIBMAINLOOP
# ifdef QT_USE_GLIBMAINLOOP
tqt_timerListMutex = new TQMutex ( TRUE ) ;
tqt_timerListMutex = new TQMutex ( TRUE ) ;
# endif // QT_USE_GLIBMAINLOOP
# endif // QT_USE_GLIBMAINLOOP
postevent_mutex = new TQMutex ( TRUE ) ;
tqt_application_thread_id = TQThread : : currentThread ( ) ;
tqt_application_thread_id = TQThread : : currentThread ( ) ;
# endif // TQT_THREAD_SUPPORT
# endif // TQT_THREAD_SUPPORT
@ -1247,8 +1279,6 @@ TQApplication::~TQApplication()
# ifdef TQT_THREAD_SUPPORT
# ifdef TQT_THREAD_SUPPORT
delete tqt_mutex ;
delete tqt_mutex ;
tqt_mutex = 0 ;
tqt_mutex = 0 ;
delete postevent_mutex ;
postevent_mutex = 0 ;
# endif // TQT_THREAD_SUPPORT
# endif // TQT_THREAD_SUPPORT
if ( tqApp = = this ) {
if ( tqApp = = this ) {
@ -2538,33 +2568,31 @@ bool TQApplication::notify( TQObject *receiver, TQEvent *e )
if ( e - > type ( ) = = TQEvent : : ChildRemoved & & receiver - > postedEvents ) {
if ( e - > type ( ) = = TQEvent : : ChildRemoved & & receiver - > postedEvents ) {
# ifdef TQT_THREAD_SUPPORT
# ifdef TQT_THREAD_SUPPORT
TQMutexLocker locker ( postevent_mutex ) ;
TQMutexLocker locker ( GlobalPostedEvents( ) - > mutex ( ) ) ;
# endif // TQT_THREAD_SUPPORT
# endif // TQT_THREAD_SUPPORT
if ( globalPostedEvents ) {
// the TQObject destructor calls TQObject::removeChild, which calls
// the TQObject destructor calls TQObject::removeChild, which calls
// TQApplication::sendEvent() directly. this can happen while the event
// TQApplication::sendEvent() directly. this can happen while the event
// loop is in the middle of posting events, and when we get here, we may
// loop is in the middle of posting events, and when we get here, we may
// not have any more posted events for this object.
// not have any more posted events for this object.
if ( receiver - > postedEvents ) {
if ( receiver - > postedEvents ) {
// if this is a child remove event and the child insert
// if this is a child remove event and the child insert
// hasn't been dispatched yet, kill that insert
// hasn't been dispatched yet, kill that insert
TQPostEventList * l = receiver - > postedEvents ;
TQPostEventList * l = receiver - > postedEvents ;
TQObject * c = ( ( TQChildEvent * ) e ) - > child ( ) ;
TQObject * c = ( ( TQChildEvent * ) e ) - > child ( ) ;
TQPostEvent * pe ;
TQPostEvent * pe ;
l - > first ( ) ;
l - > first ( ) ;
while ( ( pe = l - > current ( ) ) ! = 0 ) {
while ( ( pe = l - > current ( ) ) ! = 0 ) {
if ( pe - > event & & pe - > receiver = = receiver & &
if ( pe - > event & & pe - > receiver = = receiver & &
pe - > event - > type ( ) = = TQEvent : : ChildInserted & &
pe - > event - > type ( ) = = TQEvent : : ChildInserted & &
( ( TQChildEvent * ) pe - > event ) - > child ( ) = = c ) {
( ( TQChildEvent * ) pe - > event ) - > child ( ) = = c ) {
pe - > event - > posted = FALSE ;
pe - > event - > posted = FALSE ;
delete pe - > event ;
delete pe - > event ;
pe - > event = 0 ;
pe - > event = 0 ;
l - > remove ( ) ;
l - > remove ( ) ;
continue ;
continue ;
}
l - > next ( ) ;
}
}
l - > next ( ) ;
}
}
}
}
}
}
@ -3386,16 +3414,9 @@ void TQApplication::postEvent( TQObject *receiver, TQEvent *event )
}
}
# ifdef TQT_THREAD_SUPPORT
# ifdef TQT_THREAD_SUPPORT
TQMutexLocker locker ( postevent_mutex ) ;
TQMutexLocker locker ( GlobalPostedEvents( ) - > mutex ( ) ) ;
# endif // TQT_THREAD_SUPPORT
# endif // TQT_THREAD_SUPPORT
if ( ! globalPostedEvents ) { // create list
globalPostedEvents = new TQPostEventList ;
TQ_CHECK_PTR ( globalPostedEvents ) ;
globalPostedEvents - > setAutoDelete ( TRUE ) ;
qapp_cleanup_events . set ( & globalPostedEvents ) ;
}
if ( ! receiver - > postedEvents ) {
if ( ! receiver - > postedEvents ) {
receiver - > postedEvents = new TQPostEventList ;
receiver - > postedEvents = new TQPostEventList ;
}
}
@ -3479,7 +3500,7 @@ void TQApplication::postEvent( TQObject *receiver, TQEvent *event )
event - > posted = TRUE ;
event - > posted = TRUE ;
TQPostEvent * pe = new TQPostEvent ( receiver , event ) ;
TQPostEvent * pe = new TQPostEvent ( receiver , event ) ;
l - > append ( pe ) ;
l - > append ( pe ) ;
globalPostedEvents - > append ( pe ) ;
GlobalPostedEvents( ) - > append ( pe ) ;
# ifdef TQT_THREAD_SUPPORT
# ifdef TQT_THREAD_SUPPORT
// Wake up the receiver thread event loop
// Wake up the receiver thread event loop
@ -3535,24 +3556,20 @@ void TQApplication::sendPostedEvents( TQObject *receiver, int event_type )
}
}
# ifdef TQT_THREAD_SUPPORT
# ifdef TQT_THREAD_SUPPORT
TQMutexLocker locker ( postevent_mutex ) ;
TQMutexLocker locker ( GlobalPostedEvents( ) - > mutex ( ) ) ;
# endif
# endif
if ( ! globalPostedEvents | | ( receiver & & ! receiver - > postedEvents ) ) {
return ;
}
bool sent = TRUE ;
bool sent = TRUE ;
while ( sent ) {
while ( sent ) {
sent = FALSE ;
sent = FALSE ;
if ( ! globalPostedEvents | | ( receiver & & ! receiver - > postedEvents ) ) {
if ( receiver & & ! receiver - > postedEvents ) {
return ;
return ;
}
}
// if we have a receiver, use the local list. Otherwise, use the
// if we have a receiver, use the local list. Otherwise, use the
// global list
// global list
TQPostEventList * l = receiver ? receiver - > postedEvents : globalPostedEvents ;
TQPostEventList * l = receiver ? receiver - > postedEvents : GlobalPostedEvents( ) ;
// okay. here is the tricky loop. be careful about optimizing
// okay. here is the tricky loop. be careful about optimizing
// this, it looks the way it does for good reasons.
// this, it looks the way it does for good reasons.
@ -3624,14 +3641,14 @@ void TQApplication::sendPostedEvents( TQObject *receiver, int event_type )
// clear the global list, i.e. remove everything that was
// clear the global list, i.e. remove everything that was
// delivered.
// delivered.
if ( l = = globalPostedEvents ) {
if ( l = = GlobalPostedEvents( ) ) {
globalPostedEvents - > first ( ) ;
GlobalPostedEvents( ) - > first ( ) ;
while ( ( pe = globalPostedEvents - > current ( ) ) ! = 0 ) {
while ( ( pe = GlobalPostedEvents( ) - > current ( ) ) ! = 0 ) {
if ( pe - > event ) {
if ( pe - > event ) {
globalPostedEvents - > next ( ) ;
GlobalPostedEvents( ) - > next ( ) ;
}
}
else {
else {
globalPostedEvents - > remove ( ) ;
GlobalPostedEvents( ) - > remove ( ) ;
}
}
}
}
}
}
@ -3673,7 +3690,7 @@ void TQApplication::removePostedEvents( TQObject *receiver, int event_type )
}
}
# ifdef TQT_THREAD_SUPPORT
# ifdef TQT_THREAD_SUPPORT
TQMutexLocker locker ( postevent_mutex ) ;
TQMutexLocker locker ( GlobalPostedEvents( ) - > mutex ( ) ) ;
# endif // TQT_THREAD_SUPPORT
# endif // TQT_THREAD_SUPPORT
// the TQObject destructor calls this function directly. this can
// the TQObject destructor calls this function directly. this can
@ -3726,18 +3743,10 @@ void TQApplication::removePostedEvent( TQEvent * event )
}
}
# ifdef TQT_THREAD_SUPPORT
# ifdef TQT_THREAD_SUPPORT
TQMutexLocker locker ( postevent_mutex ) ;
TQMutexLocker locker ( GlobalPostedEvents( ) - > mutex ( ) ) ;
# endif // TQT_THREAD_SUPPORT
# endif // TQT_THREAD_SUPPORT
if ( ! globalPostedEvents ) {
TQPostEventListIt it ( * GlobalPostedEvents ( ) ) ;
# if defined(QT_DEBUG)
tqDebug ( " TQApplication::removePostedEvent: %p %d is posted: impossible " ,
( void * ) event , event - > type ( ) ) ;
return ;
# endif
}
TQPostEventListIt it ( * globalPostedEvents ) ;
TQPostEvent * pe ;
TQPostEvent * pe ;
while ( ( pe = it . current ( ) ) ! = 0 ) {
while ( ( pe = it . current ( ) ) ! = 0 ) {
+ + it ;
+ + it ;