Index: branches/v5/modules/vci_mem_cache_dspin_coherence/caba/source/include/vci_mem_cache_dspin_coherence.h
===================================================================
--- branches/v5/modules/vci_mem_cache_dspin_coherence/caba/source/include/vci_mem_cache_dspin_coherence.h	(revision 335)
+++ branches/v5/modules/vci_mem_cache_dspin_coherence/caba/source/include/vci_mem_cache_dspin_coherence.h	(revision 336)
@@ -565,5 +565,5 @@
       sc_signal<size_t>   r_write_upt_index;  // index in Update Table
       sc_signal<bool>     r_write_sc_fail;    // sc command failed
-      sc_signal<bool>     r_write_pending_sc; // sc command pending in WRITE fsm
+      sc_signal<bool>     r_write_pending_sc; // sc command pending
 
       // Buffer between WRITE fsm and TGT_RSP fsm (acknowledge a write command from L1)
Index: branches/v5/modules/vci_mem_cache_dspin_coherence/caba/source/src/vci_mem_cache_dspin_coherence.cpp
===================================================================
--- branches/v5/modules/vci_mem_cache_dspin_coherence/caba/source/src/vci_mem_cache_dspin_coherence.cpp	(revision 335)
+++ branches/v5/modules/vci_mem_cache_dspin_coherence/caba/source/src/vci_mem_cache_dspin_coherence.cpp	(revision 336)
@@ -1940,5 +1940,4 @@
         // consume a word in the FIFO & write it in the local buffer
         cmd_write_fifo_get  = true;
-        r_write_pending_sc  = false;
         size_t index        = m_x[(vci_addr_t)(m_cmd_write_addr_fifo.read())];
 
@@ -1950,4 +1949,5 @@
         r_write_trdid       = m_cmd_write_trdid_fifo.read();
         r_write_pktid       = m_cmd_write_pktid_fifo.read();
+        r_write_pending_sc  = false;
 
         // initialize the be field for all words
@@ -1955,8 +1955,8 @@
         {
           if(word == index) r_write_be[word] = m_cmd_write_be_fifo.read();
-          else                 r_write_be[word] = 0x0;
-        }
-
-        if(m_cmd_write_eop_fifo.read() || ((m_cmd_write_pktid_fifo.read() & 0x7)  == TYPE_SC))
+          else              r_write_be[word] = 0x0;
+        }
+
+        if (m_cmd_write_eop_fifo.read() || ((m_cmd_write_pktid_fifo.read() & 0x7) == TYPE_SC))
         {
           r_write_fsm = WRITE_DIR_REQ;
@@ -1989,5 +1989,6 @@
         if(m_debug_write_fsm)
         {
-          std::cout << "  <MEMC " << name() << ".WRITE_NEXT> Write another word in local buffer"
+          std::cout << "  <MEMC " << name()
+                    << ".WRITE_NEXT> Write another word in local buffer"
                     << std::endl;
         }
@@ -2007,5 +2008,4 @@
         // consume a word in the FIFO & write it in the local buffer
         cmd_write_fifo_get  = true;
-        r_write_pending_sc  = false;
         size_t index        = r_write_word_index.read() + r_write_word_count.read();
 
@@ -2024,40 +2024,47 @@
     ////////////////////
     case WRITE_DIR_REQ:
+    {
       // Get the lock to the directory
-    {
+      // and access the llsc_global_table
       if(r_alloc_dir_fsm.read() == ALLOC_DIR_WRITE)
       {
-        if(((r_write_pktid.read() & 0x7) == TYPE_SC) && not r_write_pending_sc.read())    // check for an SC command (and check that its second flit is not already consumed)
-        {
-          if(m_cmd_write_addr_fifo.rok())
-          {
-            size_t index    = m_x[(vci_addr_t)(r_write_address.read())];
-            bool sc_success = m_llsc_table.sc(r_write_address.read(),r_write_data[index].read());
-            r_write_sc_fail = !sc_success;
-
-            assert(m_cmd_write_eop_fifo.read() && "Error in VCI_MEM_CACHE : invalid packet format for SC command");
-            // consume a word in the FIFO & write it in the local buffer
-            cmd_write_fifo_get  = true;
-            r_write_pending_sc  = true;
-            index               = m_x[(vci_addr_t)(m_cmd_write_addr_fifo.read())];
-
-            r_write_address     = (addr_t)(m_cmd_write_addr_fifo.read());
-            r_write_word_index  = index;
-            r_write_word_count  = 1;
-            r_write_data[index] = m_cmd_write_data_fifo.read();
-            if(!sc_success)
-            {
-              r_write_fsm = WRITE_RSP;
-              break;
-            }
-          }
-          else break;
-        }
-        //else it is a TYPE_WRITE, need a simple sw access to the
-        // llsc_global_table
-        else
-        {
-          m_llsc_table.sw(r_write_address.read());
-        }
+        ///////////////////////////////////////////////////////////////////////
+        // SC command treatment
+        // We test the r_write_pending_sc register to know if we are returning
+        // from the WAIT state.
+        // In this case, the SC has already succeed and we cannot consume
+        // another time from the FIFO. Also, we don't have to test another
+        // time if the SC has succeed
+        if(((r_write_pktid.read() & 0x7) == TYPE_SC) and not r_write_pending_sc.read())
+        {
+          if(not m_cmd_write_addr_fifo.rok()) break;
+
+          assert(m_cmd_write_eop_fifo.read() &&
+                 "Error in VCI_MEM_CACHE : "
+                 "invalid packet format for SC command");
+
+          size_t index    = r_write_word_index.read();
+          bool sc_success = m_llsc_table.sc(r_write_address.read()    ,
+                                            r_write_data[index].read());
+
+          // consume a word in the FIFO & write it in the local buffer
+          cmd_write_fifo_get  = true;
+          r_write_data[index] = m_cmd_write_data_fifo.read();
+          r_write_sc_fail     = not sc_success;
+          r_write_pending_sc  = true;
+
+          if(not sc_success) r_write_fsm = WRITE_RSP;
+          else               r_write_fsm = WRITE_DIR_LOCK;
+
+          break;
+        }
+
+        ///////////////////////////////////////////////////////////////////////
+        // WRITE command treatment or SC command returning from the WAIT state
+        // In the second case, we must access the LL/SC global table to
+        // erase any possible new reservation when we release the lock on the
+        // directory
+        m_llsc_table.sw(r_write_address.read());
+
         r_write_fsm = WRITE_DIR_LOCK;
       }
@@ -2231,10 +2238,10 @@
 
       if(no_update)
-        // Write transaction completed
+      // Write transaction completed
       {
         r_write_fsm = WRITE_RSP;
       }
       else
-        // coherence update required
+      // coherence update required
       {
         if(!r_write_to_cc_send_multi_req.read()   &&
@@ -2323,5 +2330,5 @@
         //  releases the lock protecting UPT and the DIR if no entry...
         if(wok) r_write_fsm = WRITE_UPT_HEAP_LOCK;
-        else       r_write_fsm = WRITE_WAIT;
+        else    r_write_fsm = WRITE_WAIT;
       }
       break;
@@ -2539,5 +2546,4 @@
           // consume a word in the FIFO & write it in the local buffer
           cmd_write_fifo_get  = true;
-          r_write_pending_sc  = false;
           size_t index        = m_x[(vci_addr_t)(m_cmd_write_addr_fifo.read())];
 
@@ -2549,4 +2555,5 @@
           r_write_trdid       = m_cmd_write_trdid_fifo.read();
           r_write_pktid       = m_cmd_write_pktid_fifo.read();
+          r_write_pending_sc  = false;
 
           // initialize the be field for all words
