Salome HOME
Revert "Synchronize adm files"
[modules/kernel.git] / src / DSC / DSC_User / Basic / data_short_port_provides.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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, or (at your option) any later version.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  File   : data_short_port_provides.cxx
24 //  Author : AndrĂ© RIBES (EDF)
25 //  Module : KERNEL
26 //
27 #include "data_short_port_provides.hxx"
28
29 data_short_port_provides::data_short_port_provides() {
30   _val = 0;
31   short_termine = false;                    
32   short_mutex = new pthread_mutex_t();
33   pthread_mutex_init(short_mutex, NULL);
34   short_condition = new pthread_cond_t();
35   pthread_cond_init(short_condition, NULL);
36   short_termine_cp = true;                  
37   short_mutex_cp = new pthread_mutex_t();
38   pthread_mutex_init(short_mutex_cp, NULL);
39   short_condition_cp = new pthread_cond_t();
40   pthread_cond_init(short_condition_cp, NULL);
41 }
42
43 data_short_port_provides::~data_short_port_provides() {
44   pthread_mutex_destroy(short_mutex);
45   delete short_mutex;
46   pthread_cond_destroy(short_condition);
47   delete short_condition;
48   pthread_mutex_destroy(short_mutex_cp);
49   delete short_mutex_cp;
50   pthread_cond_destroy(short_condition_cp);
51   delete short_condition_cp;
52 }
53
54 void
55 data_short_port_provides::put(CORBA::Short data) {
56   // On attend que le get soit fait
57   pthread_mutex_lock(short_mutex_cp);
58   while (short_termine_cp == false)
59   {
60      pthread_cond_wait(short_condition_cp, short_mutex_cp);
61   }
62   short_termine_cp = false;
63   pthread_mutex_unlock(short_mutex_cp);
64
65   pthread_mutex_lock(short_mutex);
66   _val = data;
67   short_termine = true;
68   pthread_cond_signal(short_condition);
69   pthread_mutex_unlock(short_mutex);
70 }
71
72 CORBA::Short
73 data_short_port_provides::get() {
74   CORBA::Short result;
75   pthread_mutex_lock(short_mutex);
76   while (short_termine == false)
77   {
78      pthread_cond_wait(short_condition, short_mutex);
79   }
80   result = _val;
81   short_termine = false;
82   pthread_mutex_unlock(short_mutex);
83
84   // On indique que l'on a copie la valeur
85   pthread_mutex_lock(short_mutex_cp);
86   short_termine_cp = true;
87   pthread_cond_signal(short_condition_cp);
88   pthread_mutex_unlock(short_mutex_cp);
89   return result;
90 }
91
92 Ports::Port_ptr
93 data_short_port_provides::get_port_ref() {
94   return this->_this();
95 }