Commit 9c90e08f authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Merge branch 'periodic-bc' into develop

parents e3cc7206 efbc768a
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -142,21 +142,25 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer

      const Object* operator->() const
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return &this->pd->data;
      }

      Object* operator->()
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return &this->pd->data;
      }

      const Object& operator *() const
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return this->pd->data;
      }

      Object& operator *()
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return this->pd->data;
      }

@@ -176,6 +180,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer
      __cuda_callable__
      const Object& getData() const
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return this->pd->data;
      }

@@ -183,6 +188,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer
      __cuda_callable__
      Object& modifyData()
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return this->pd->data;
      }

@@ -399,22 +405,26 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer

      const Object* operator->() const
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return &this->pd->data;
      }

      Object* operator->()
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         this->pd->maybe_modified = true;
         return &this->pd->data;
      }

      const Object& operator *() const
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return this->pd->data;
      }

      Object& operator *()
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         this->pd->maybe_modified = true;
         return this->pd->data;
      }
@@ -466,6 +476,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer
         this->free();
         this->pd = (PointerData*) ptr.pd;
         this->cuda_pointer = ptr.cuda_pointer;
         if( this->pd != nullptr )
            this->pd->counter += 1;
#ifdef TNL_DEBUG_SHARED_POINTERS
         std::cerr << "Copy-assigned shared pointer: counter = " << this->pd->counter << ", type: " << demangle(typeid(ObjectType).name()) << std::endl;
@@ -481,6 +492,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer
         this->free();
         this->pd = (PointerData*) ptr.pd;
         this->cuda_pointer = ptr.cuda_pointer;
         if( this->pd != nullptr )
            this->pd->counter += 1;
#ifdef TNL_DEBUG_SHARED_POINTERS
         std::cerr << "Copy-assigned shared pointer: counter = " << this->pd->counter << ", type: " << demangle(typeid(ObjectType).name()) << std::endl;
+6 −0
Original line number Diff line number Diff line
@@ -118,21 +118,25 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer

      const Object* operator->() const
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return &this->pd->data;
      }

      Object* operator->()
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return &this->pd->data;
      }

      const Object& operator *() const
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return this->pd->data;
      }

      Object& operator *()
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return this->pd->data;
      }

@@ -152,6 +156,7 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer
      __cuda_callable__
      const Object& getData() const
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return this->pd->data;
      }

@@ -159,6 +164,7 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer
      __cuda_callable__
      Object& modifyData()
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return this->pd->data;
      }

+3 −0
Original line number Diff line number Diff line
@@ -126,17 +126,20 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer

      const Object* operator->() const
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return &this->pd->data;
      }

      Object* operator->()
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         this->pd->maybe_modified = true;
         return &this->pd->data;
      }

      const Object& operator *() const
      {
         TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         return this->pd->data;
      }

+14 −0
Original line number Diff line number Diff line
@@ -107,6 +107,20 @@ TEST( SharedPointerCudaTest, getDataArrayTest )
#endif
};

TEST( SharedPointerCudaTest, nullptrAssignement )
{
#ifdef HAVE_CUDA
   using TestType = Pointers::SharedPointer< double, Devices::Cuda >;
   TestType p1( 5 ), p2( nullptr );
   
   // This should not crash
   p1 = p2;
   
   ASSERT_FALSE( p1 );
   ASSERT_FALSE( p2 );
#endif
}


#endif

+13 −0
Original line number Diff line number Diff line
@@ -38,6 +38,19 @@ TEST( SharedPointerHostTest, ConstructorTest )
   ASSERT_EQ( ptr1->x(), 1 );
   ASSERT_EQ( ptr1->y(), 2 );
};

TEST( SharedPointerCudaTest, nullptrAssignement )
{
   using TestType = Pointers::SharedPointer< double, Devices::Host >;
   TestType p1( 5 ), p2( nullptr );
   
   // This should not crash
   p1 = p2;
   
   ASSERT_FALSE( p1 );
   ASSERT_FALSE( p2 );
}

#endif

#include "../GtestMissingError.h"