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>
40 static int MYDEBUG = 0;
42 static int MYDEBUG = 0;
46 static pthread_t myThread;
48 void SALOME_Event::GetSessionThread(){
49 myThread = pthread_self();
52 bool SALOME_Event::IsSessionThread(){
53 bool aResult = myThread == pthread_self();
54 if(MYDEBUG) INFOS("IsSessionThread() - "<<aResult);
59 //===========================================================
61 * SALOME_Event::SALOME_Event
64 //===========================================================
65 SALOME_Event::SALOME_Event(){
66 if(MYDEBUG) MESSAGE( "SALOME_Event::SALOME_Event(): this = "<<this );
67 // Prepare the semaphore
68 mySemaphore = new QSemaphore( 2 );
72 //===========================================================
74 * SALOME_Event::~SALOME_Event
77 //===========================================================
78 SALOME_Event::~SALOME_Event(){
79 if(MYDEBUG) MESSAGE( "SALOME_Event::~SALOME_Event(): this = "<<this );
80 if ( mySemaphore->available() < mySemaphore->total() )
81 *mySemaphore -= mySemaphore->total() - mySemaphore->available();
85 //===========================================================
87 * SALOME_Event::process
88 * Posts the event and optionally waits for its completion
90 //===========================================================
91 void SALOME_Event::process()
93 QThread::postEvent( qApp, new QCustomEvent( SALOME_EVENT, (void*)this ) );
94 if(MYDEBUG) MESSAGE( "SALOME_Event::process(): this = "<<this<<", *mySemaphore += 1 " );
96 if(MYDEBUG) MESSAGE( "SALOME_Event::process(): this = "<<this<<" - COMPLETED" );
99 //===========================================================
101 * SALOME_Event::processed
102 * Signals that this event has been processed
104 //===========================================================
105 void SALOME_Event::processed()
107 if(MYDEBUG) MESSAGE( "SALOME_Event::processed(): this = "<<this );
108 // process() takes control over mySemaphore after the next line is executed