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;
54 void SALOME_Event::GetSessionThread(){
56 myThread = ::GetCurrentThreadId();
58 myThread = pthread_self();
62 bool SALOME_Event::IsSessionThread(){
65 aResult = myThread == ::GetCurrentThreadId();
67 aResult = myThread == pthread_self();
69 // if(MYDEBUG) INFOS("IsSessionThread() - "<<aResult);
74 //===========================================================
76 * SALOME_Event::SALOME_Event
79 //===========================================================
80 SALOME_Event::SALOME_Event(){
81 // if(MYDEBUG) MESSAGE( "SALOME_Event::SALOME_Event(): this = "<<this );
82 // Prepare the semaphore
83 mySemaphore = new QSemaphore( 2 );
87 //===========================================================
89 * SALOME_Event::~SALOME_Event
92 //===========================================================
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();
100 //===========================================================
102 * SALOME_Event::process
103 * Posts the event and optionally waits for its completion
105 //===========================================================
106 void SALOME_Event::process()
108 QThread::postEvent( qApp, new QCustomEvent( SALOME_EVENT, (void*)this ) );
109 // if(MYDEBUG) MESSAGE( "SALOME_Event::process(): this = "<<this<<", *mySemaphore += 1 " );
111 // if(MYDEBUG) MESSAGE( "SALOME_Event::process(): this = "<<this<<" - COMPLETED" );
114 //===========================================================
116 * SALOME_Event::processed
117 * Signals that this event has been processed
119 //===========================================================
120 void SALOME_Event::processed()
122 // if(MYDEBUG) MESSAGE( "SALOME_Event::processed(): this = "<<this );
123 // process() takes control over mySemaphore after the next line is executed