Commit e3bd49ec authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Better asserts in SharedPointer

parent 96901122
Loading
Loading
Loading
Loading
+16 −16
Original line number Diff line number Diff line
@@ -142,25 +142,25 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer

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

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

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

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

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

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

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

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

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

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

      Object& operator *()
      {
         TNL_ASSERT_TRUE( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         TNL_ASSERT_TRUE( this->pd, "Attempt to dereference a null pointer" );
         this->pd->maybe_modified = true;
         return this->pd->data;
      }
@@ -446,8 +446,8 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer
      const Object& getData() const
      {
         static_assert( std::is_same< Device, Devices::Host >::value || std::is_same< Device, Devices::Cuda >::value, "Only Devices::Host or Devices::Cuda devices are accepted here." );
         TNL_ASSERT( this->pd, );
         TNL_ASSERT( this->cuda_pointer, );
         TNL_ASSERT_TRUE( this->pd, "Attempt to dereference a null pointer" );
         TNL_ASSERT_TRUE( this->cuda_pointer, "Attempt to dereference a null pointer" );
         if( std::is_same< Device, Devices::Host >::value )
            return this->pd->data;
         if( std::is_same< Device, Devices::Cuda >::value )
@@ -459,8 +459,8 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer
      Object& modifyData()
      {
         static_assert( std::is_same< Device, Devices::Host >::value || std::is_same< Device, Devices::Cuda >::value, "Only Devices::Host or Devices::Cuda devices are accepted here." );
         TNL_ASSERT( this->pd, );
         TNL_ASSERT( this->cuda_pointer, );
         TNL_ASSERT_TRUE( this->pd, "Attempt to dereference a null pointer" );
         TNL_ASSERT_TRUE( this->cuda_pointer, "Attempt to dereference a null pointer" );
         if( std::is_same< Device, Devices::Host >::value )
         {
            this->pd->maybe_modified = true;
@@ -606,14 +606,14 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer

      void set_last_sync_state()
      {
         TNL_ASSERT( this->pd, );
         TNL_ASSERT_TRUE( this->pd, "Attempt to dereference a null pointer" );
         std::memcpy( (void*) &this->pd->data_image, (void*) &this->pd->data, sizeof( Object ) );
         this->pd->maybe_modified = false;
      }

      bool modified()
      {
         TNL_ASSERT( this->pd, );
         TNL_ASSERT_TRUE( this->pd, "Attempt to dereference a null pointer" );
         // optimization: skip bitwise comparison if we're sure that the data is the same
         if( ! this->pd->maybe_modified )
            return false;
+6 −6
Original line number Diff line number Diff line
@@ -118,25 +118,25 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer

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

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

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

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

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

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

+10 −10
Original line number Diff line number Diff line
@@ -126,26 +126,26 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer

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

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

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

      Object& operator *()
      {
         TNL_ASSERT_TRUE( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
         TNL_ASSERT_TRUE( this->pd, "Attempt to dereference a null pointer" );
         this->pd->maybe_modified = true;
         return this->pd->data;
      }
@@ -160,8 +160,8 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer
      const Object& getData() const
      {
         static_assert( std::is_same< Device, Devices::Host >::value || std::is_same< Device, Devices::MIC >::value, "Only Devices::Host or Devices::MIC devices are accepted here." );
         TNL_ASSERT( this->pd, );
         TNL_ASSERT( this->mic_pointer, );
         TNL_ASSERT_TRUE( this->pd, "Attempt to dereference a null pointer" );
         TNL_ASSERT_TRUE( this->mic_pointer, "Attempt to dereference a null pointer" );
         if( std::is_same< Device, Devices::Host >::value )
            return this->pd->data;
         if( std::is_same< Device, Devices::MIC >::value )
@@ -174,8 +174,8 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer
      Object& modifyData()
      {
         static_assert( std::is_same< Device, Devices::Host >::value || std::is_same< Device, Devices::MIC >::value, "Only Devices::Host or Devices::MIC devices are accepted here." );
         TNL_ASSERT( this->pd, );
         TNL_ASSERT( this->mic_pointer, );
         TNL_ASSERT_TRUE( this->pd, "Attempt to dereference a null pointer" );
         TNL_ASSERT_TRUE( this->mic_pointer, "Attempt to dereference a null pointer" );
         if( std::is_same< Device, Devices::Host >::value )
         {
            this->pd->maybe_modified = true;
@@ -323,14 +323,14 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer

      void set_last_sync_state()
      {
         TNL_ASSERT( this->pd, );
         TNL_ASSERT_TRUE( this->pd, "Attempt to dereference a null pointer" );
         std::memcpy( (void*) &this->pd->data_image, (void*) &this->pd->data, sizeof( Object ) );
         this->pd->maybe_modified = false;
      }

      bool modified()
      {
         TNL_ASSERT( this->pd, );
         TNL_ASSERT_TRUE( this->pd, "Attempt to dereference a null pointer" );
         // optimization: skip bitwise comparison if we're sure that the data is the same
         if( ! this->pd->maybe_modified )
            return false;