Browse Source

Fix simulator under GCC6

Kai Mast 7 years ago
parent
commit
7e00ad320f
3 changed files with 16 additions and 15 deletions
  1. 4 9
      psw/urts/node.cpp
  2. 4 2
      psw/urts/node.h
  3. 8 4
      psw/urts/tcs.cpp

+ 4 - 9
psw/urts/node.cpp

@@ -37,10 +37,8 @@
 
 template<class T1, class T2>
 Node<T1, T2>::Node(const T1& k, const T2& v)
+    : key(k), value(v), next(nullptr)
 {
-    this->key = k;
-    this->value = v;
-    this->next = NULL;
 }
 
 template<class T1, class T2>
@@ -71,14 +69,11 @@ Node<T1, T2>* Node<T1, T2>::Remove(const T1& k)
 template<class T1, class T2>
 Node<T1, T2>* Node<T1, T2>::Find(const T1& k)
 {
-    Node<T1, T2>* c = this;
-    if (c == NULL) return NULL;
-    while (c != NULL) {
+    for(auto c = this; c != nullptr; c = c->next) {
         if (c->key == k)
-            break;
-        c = c->next;
+            return c;
     }
-    return c;
+    return nullptr;
 }
 
 

+ 4 - 2
psw/urts/node.h

@@ -39,14 +39,16 @@ template<class T1, class T2>
 class Node: private Uncopyable
 {
 public:
-    T1 key;
-    T2 value;
+    const T1 key;
+    const T2 value;
+    
     Node<T1, T2> * next;
 
     Node();
     Node(const T1& key, const T2& value);
 
     bool InsertNext(Node<T1, T2>* p);
+    
     Node<T1, T2>* Find(const T1& key);
     Node<T1, T2>* Remove(const T1& key);
 };

+ 8 - 4
psw/urts/tcs.cpp

@@ -150,11 +150,15 @@ int CTrustThreadPool::bind_thread(const se_thread_id_t thread_id,  CTrustThread
 
 CTrustThread * CTrustThreadPool::get_bound_thread(const se_thread_id_t thread_id)
 {
-    CTrustThread *trust_thread = NULL;
+    CTrustThread *trust_thread = nullptr;
 
-    Node<se_thread_id_t, CTrustThread*>* it = m_thread_list->Find(thread_id);
-    if(it != NULL)
-        trust_thread = it->value;
+    if(m_thread_list)
+    {
+        auto it =  m_thread_list->Find(thread_id);
+
+        if(it)
+           trust_thread = it->value;
+    }
 
     return trust_thread;
 }