Przeglądaj źródła

Einige kleine Bugs behoben

kolja 7 lat temu
rodzic
commit
623e176c2d
6 zmienionych plików z 27 dodań i 13 usunięć
  1. 1 0
      Betriebssystem.h
  2. 23 9
      Critical.cpp
  3. 1 0
      Critical.h
  4. 0 2
      Fortschritt.cpp
  5. 0 1
      Model2D.h
  6. 2 1
      Thread.cpp

+ 1 - 0
Betriebssystem.h

@@ -75,6 +75,7 @@ private:
 class CriticalSection;
 #endif
 #define GetCurrentThread               pthread_self
+#define GetThreadId( x )               x
 #define CRITICAL_SECTION               CriticalSection*
 #define InitializeCriticalSection( x ) ( *( x ) ) = new CriticalSection()
 #define DeleteCriticalSection( x )     delete ( *( x ) )

+ 23 - 9
Critical.cpp

@@ -1,6 +1,8 @@
 #include "Critical.h"
 #include "Globals.h"
 #include "Thread.h"
+#include <iostream>
+#include <time.h>
 
 using namespace Framework;
 
@@ -9,22 +11,30 @@ using namespace Framework;
 Critical::Critical()
 {
     InitializeCriticalSection( &cs );
+    owner = 0;
+    lockCount = 0;
+    id = (int)time( 0 );
+    std::cout << "Create Critical: " << id << "\n";
 }
 
 // Destructor
 Critical::~Critical()
 {
+    std::cout << "Delete Critical: " << id << "\n";
     DeleteCriticalSection( &cs );
 }
 
 // sperrt das Objekt
 void Critical::lock()
 {
+    pthread_t t = GetCurrentThread();
+    Thread *tmp = getThreadRegister()->zThread( t );
+    if( tmp )
+        tmp->addCriticalLock();
     EnterCriticalSection( &cs );
+    std::cout << "Lock Critical: " << id << "\n";
     if( !owner )
-        owner = getThreadRegister()->zThread( GetCurrentThread() );
-    if( owner )
-        owner->addCriticalLock();
+        owner = tmp;
     lockCount++;
 }
 
@@ -33,11 +43,13 @@ bool Critical::tryLock()
 {
     if( lockCount > 0 )
         return false;
+    Thread *tmp = getThreadRegister()->zThread( GetCurrentThread() );
+    if( tmp )
+        tmp->addCriticalLock();
     EnterCriticalSection( &cs );
+    std::cout << "Lock Critical: " << id << "\n";
     if( !owner )
-        owner = getThreadRegister()->zThread( GetCurrentThread() );
-    if( owner )
-        owner->addCriticalLock();
+        owner = tmp;
     lockCount++;
     return true;
 }
@@ -45,13 +57,15 @@ bool Critical::tryLock()
 // entsperrt das Objekt
 void Critical::unlock()
 {
-    if( owner && owner->getThreadHandle() != GetCurrentThread() )
+    if( owner && GetThreadId( owner->getThreadHandle() ) != GetThreadId( GetCurrentThread() ) )
         throw std::runtime_error( "A Thread that does not own a Critical Object trys to unlock it" );
-    if( owner )
-        owner->removeCriticalLock();
+    Thread *tmp = owner;
     if( !--lockCount )
         owner = 0;
+    std::cout << "Unlock Critical: " << id << "\n";
     LeaveCriticalSection( &cs );
+    if( tmp )
+        tmp->removeCriticalLock();
 }
 
 

+ 1 - 0
Critical.h

@@ -12,6 +12,7 @@ namespace Framework
         CRITICAL_SECTION cs;
         Thread *owner;
         int lockCount;
+        int id;
 
     public:
         // Konstructor

+ 0 - 2
Fortschritt.cpp

@@ -30,8 +30,6 @@ FBalken::FBalken()
 // Destructor 
 FBalken::~FBalken()
 {
-    if( rahmen )
-        rahmen->release();
     if( fRahmen )
         fRahmen->release();
     if( fBuffer )

+ 0 - 1
Model2D.h

@@ -78,7 +78,6 @@ namespace Framework
         int ref;
         int farbe;
         Bild *textur;
-        Punkt pos;
 
     public:
         // Konstruktor

+ 2 - 1
Thread.cpp

@@ -12,6 +12,7 @@ Thread::Thread()
     threadId = 0;
     thRegister->add( this );
     run = 0;
+    lockCount = 0;
 }
 
 // Destruktor 
@@ -216,7 +217,7 @@ Thread *ThreadRegister::zThread( pthread_t handle )
     EnterCriticalSection( &cs );
     for( auto i = threads.getArray(); i.set; i++ )
     {
-        if( i.var->getThreadHandle() == handle )
+        if( GetThreadId( i.var->getThreadHandle() ) == GetThreadId( handle ) )
         {
             LeaveCriticalSection( &cs );
             return i.var;