Salome HOME
CCAR: some corrections in :
[modules/kernel.git] / src / DSC / DSC_User / Datastream / Calcium / CalciumGenericProvidesPort.hxx
index 6f8fd6d9769eebc9bee5ffe01c2d2b8732dfadf0..7adf70ce1e9c782a3071cc85e2683a7c50a4b2a2 100644 (file)
                             public virtual POA_Ports::PortProperties,  \
                             public GenericProvidesPort< __VA_ARGS__ , CalciumCouplingPolicy, calcium_provides_port > { \
   private :                                                            \
-    omni_semaphore _mustnotdisconnectyet;                              \
+    omni_mutex     _disconnect_mutex; \
+    int            _mustnotdisconnect; \
   public :                                                             \
     typedef  __VA_ARGS__               DataManipulator;                        \
     typedef  DataManipulator::Type     CorbaDataType;                  \
     typedef GenericPort< DataManipulator ,                             \
       CalciumCouplingPolicy >          Port;                           \
+      specificPortName () : _mustnotdisconnect(0) {}; \
                                                                        \
-    specificPortName () :_mustnotdisconnectyet(0) {};                  \
-                                                                       \
     virtual ~ specificPortName ();                                     \
                                                                        \
     inline void disconnect(bool provideLastGivenValue) {               \
-      if (! _mustnotdisconnectyet.trywait() ) {                                \
-       Port::disconnect(provideLastGivenValue);                        \
-      }                                                                        \
-    }                                                                          \
+      _disconnect_mutex.lock();                       \
+      if(_mustnotdisconnect > 1)                      \
+      {                                               \
+        _mustnotdisconnect--;                         \
+      }                                               \
+      else if(_mustnotdisconnect == 1)                \
+      {                                               \
+        _mustnotdisconnect--;                         \
+        Port::disconnect(provideLastGivenValue);      \
+      }                                               \
+      _disconnect_mutex.unlock();                     \
+    }                                                                                                        \
     inline void setDependencyType(CalciumTypes::DependencyType dependencyType) { \
       Port::setDependencyType(dependencyType);                         \
     }                                                                  \
     virtual void provides_port_changed(int connection_nbr,             \
                                       const Engines::DSC::Message message) { \
       if ( message == Engines::DSC::AddingConnection)                  \
-       _mustnotdisconnectyet.post();                                   \
+        {                                                 \
+          _disconnect_mutex.lock();                \
+          _mustnotdisconnect++;                           \
+          _disconnect_mutex.unlock();              \
+        }                                                 \
       else if ( message == Engines::DSC::RemovingConnection )          \
-       disconnect(false);                                              \
+        {                                                 \
+          disconnect(false);                              \
+        }                                                 \
     }                                                                  \
   };                                                                   \