1 // KERNEL SALOME_Event : Define event posting mechanism
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SALOME_Event.cxx
25 // Author : Sergey ANIKIN
29 #include "SALOME_Event.hxx"
31 //#include "utilities.h"
33 #include <qsemaphore.h>
34 #include <qapplication.h>
37 // asv 21.02.05 : introducing multi-platform approach of thread comparison
38 // on Unix using pthread_t type for storing ThreadId
39 // on Win32 using integer type for storing ThreadId
40 // NOT using integer ThreadId on both Unix and Win32 because (from documentation):
41 // "...Do not allow your program to rely on the internal structure or size of the pthread_t..."
46 static DWORD myThread;
51 static pthread_t myThread;
57 void SALOME_Event::GetSessionThread(){
59 myThread = ::GetCurrentThreadId();
61 myThread = pthread_self();
66 \return true if it is session thread
68 bool SALOME_Event::IsSessionThread(){
71 aResult = myThread == ::GetCurrentThreadId();
73 aResult = myThread == pthread_self();
75 // if(MYDEBUG) INFOS("IsSessionThread() - "<<aResult);
83 SALOME_Event::SALOME_Event(){
84 // if(MYDEBUG) MESSAGE( "SALOME_Event::SALOME_Event(): this = "<<this );
85 // Prepare the semaphore
86 mySemaphore = new QSemaphore( 2 );
93 SALOME_Event::~SALOME_Event(){
94 // if(MYDEBUG) MESSAGE( "SALOME_Event::~SALOME_Event(): this = "<<this );
95 if ( mySemaphore->available() < mySemaphore->total() )
96 *mySemaphore -= mySemaphore->total() - mySemaphore->available();
101 Posts the event and optionally waits for its completion
103 void SALOME_Event::process()
105 QThread::postEvent( qApp, new QCustomEvent( SALOME_EVENT, (void*)this ) );
106 // if(MYDEBUG) MESSAGE( "SALOME_Event::process(): this = "<<this<<", *mySemaphore += 1 " );
108 // if(MYDEBUG) MESSAGE( "SALOME_Event::process(): this = "<<this<<" - COMPLETED" );
112 Signals that this event has been processed
114 void SALOME_Event::processed()
116 // if(MYDEBUG) MESSAGE( "SALOME_Event::processed(): this = "<<this );
117 // process() takes control over mySemaphore after the next line is executed