Back to index

salome-kernel  6.5.0
data_short_port_provides.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : data_short_port_provides.cxx
00024 //  Author : André RIBES (EDF)
00025 //  Module : KERNEL
00026 //
00027 #include "data_short_port_provides.hxx"
00028 
00029 data_short_port_provides::data_short_port_provides() {
00030   _val = 0;
00031   short_termine = false;                    
00032   short_mutex = new pthread_mutex_t();
00033   pthread_mutex_init(short_mutex, NULL);
00034   short_condition = new pthread_cond_t();
00035   pthread_cond_init(short_condition, NULL);
00036   short_termine_cp = true;                  
00037   short_mutex_cp = new pthread_mutex_t();
00038   pthread_mutex_init(short_mutex_cp, NULL);
00039   short_condition_cp = new pthread_cond_t();
00040   pthread_cond_init(short_condition_cp, NULL);
00041 }
00042 
00043 data_short_port_provides::~data_short_port_provides() {
00044   pthread_mutex_destroy(short_mutex);
00045   delete short_mutex;
00046   pthread_cond_destroy(short_condition);
00047   delete short_condition;
00048   pthread_mutex_destroy(short_mutex_cp);
00049   delete short_mutex_cp;
00050   pthread_cond_destroy(short_condition_cp);
00051   delete short_condition_cp;
00052 }
00053 
00054 void
00055 data_short_port_provides::put(CORBA::Short data) {
00056   // On attend que le get soit fait
00057   pthread_mutex_lock(short_mutex_cp);
00058   while (short_termine_cp == false)
00059   {
00060      pthread_cond_wait(short_condition_cp, short_mutex_cp);
00061   }
00062   short_termine_cp = false;
00063   pthread_mutex_unlock(short_mutex_cp);
00064 
00065   pthread_mutex_lock(short_mutex);
00066   _val = data;
00067   short_termine = true;
00068   pthread_cond_signal(short_condition);
00069   pthread_mutex_unlock(short_mutex);
00070 }
00071 
00072 CORBA::Short
00073 data_short_port_provides::get() {
00074   CORBA::Short result;
00075   pthread_mutex_lock(short_mutex);
00076   while (short_termine == false)
00077   {
00078      pthread_cond_wait(short_condition, short_mutex);
00079   }
00080   result = _val;
00081   short_termine = false;
00082   pthread_mutex_unlock(short_mutex);
00083 
00084   // On indique que l'on a copie la valeur
00085   pthread_mutex_lock(short_mutex_cp);
00086   short_termine_cp = true;
00087   pthread_cond_signal(short_condition_cp);
00088   pthread_mutex_unlock(short_mutex_cp);
00089   return result;
00090 }
00091 
00092 Ports::Port_ptr
00093 data_short_port_provides::get_port_ref() {
00094   return this->_this();
00095 }