← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/markos-scratch into lp:zorba

 

Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch into lp:zorba.

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/122068

rchandle cleanup
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/122068
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/api/item.cpp'
--- src/api/item.cpp	2012-08-29 11:12:58 +0000
+++ src/api/item.cpp	2012-08-30 13:56:23 +0000
@@ -486,6 +486,7 @@
   return store::StoreConsts::jsonItem;
 }
 
+
 uint64_t
 Item::getArraySize() const
 {
@@ -494,9 +495,10 @@
 
     return to_xs_long(m_item->getArraySize());
   ITEM_CATCH
-  return NULL;
+  return 0;
 }
 
+
 Item
 Item::getArrayValue(uint32_t aIndex) const
 {
@@ -508,6 +510,7 @@
   return Item();
 }
 
+
 Iterator_t
 Item::getObjectKeys() const
 {
@@ -520,6 +523,7 @@
   return NULL;
 }
 
+
 Item
 Item::getObjectValue(String aName) const
 {

=== modified file 'src/context/static_context.cpp'
--- src/context/static_context.cpp	2012-08-29 11:12:58 +0000
+++ src/context/static_context.cpp	2012-08-30 13:56:23 +0000
@@ -1039,8 +1039,8 @@
     else
       ar & theParent;
 
-    if(theParent)
-      theParent->addReference(theParent->getSharedRefCounter() SYNC_PARAM2(theParent->getRCLock()));
+    if (theParent)
+      theParent->addReference(SYNC_CODE(theParent->getRCLock()));
   }
 
   ar & theModuleNamespace;

=== modified file 'src/zorbatypes/rchandle.cpp'
--- src/zorbatypes/rchandle.cpp	2012-08-29 11:12:58 +0000
+++ src/zorbatypes/rchandle.cpp	2012-08-30 13:56:23 +0000
@@ -53,17 +53,15 @@
 }
 
 
-void RCObject::addReference(long* sharedCounter SYNC_PARAM2(RCLock* lock)) const
+void RCObject::addReference(SYNC_CODE(RCLock* lock)) const
 {
 #if defined WIN32 && !defined CYGWIN &&!defined ZORBA_FOR_ONE_THREAD_ONLY
   if(lock)
   {
-    if (sharedCounter) InterlockedIncrement(sharedCounter);
     InterlockedIncrement(&theRefCount);
   }
   else
   {
-    if (sharedCounter) ++(*sharedCounter);
     ++theRefCount;
   }
 
@@ -71,7 +69,6 @@
 
   SYNC_CODE(if (lock) lock->acquire());
 
-  if (sharedCounter) ++(*sharedCounter);
   ++theRefCount;
 
   SYNC_CODE(if (lock) lock->release());
@@ -80,21 +77,12 @@
 }
 
 
-void RCObject::removeReference(long* sharedCounter SYNC_PARAM2(RCLock* lock))
+void RCObject::removeReference(SYNC_CODE(RCLock* lock))
 {
 #if defined WIN32 && !defined CYGWIN &&!defined ZORBA_FOR_ONE_THREAD_ONLY
-  if(lock)
+  if (lock)
   {
-    if (sharedCounter)
-    {
-      InterlockedDecrement(&theRefCount);
-      if (!InterlockedDecrement(sharedCounter))
-      {
-        free();
-        return;
-      }
-    }
-    else if (!InterlockedDecrement(&theRefCount))
+    if (!InterlockedDecrement(&theRefCount))
     {
       free();
       return;
@@ -102,16 +90,7 @@
   }
   else
   {
-    if (sharedCounter)
-    {
-      --theRefCount;
-      if (--(*sharedCounter) == 0)
-      {
-        free();
-        return;
-      }
-    }
-    else if (--theRefCount == 0)
+    if (--theRefCount == 0)
     {
       free();
       return; 
@@ -122,17 +101,7 @@
 
   SYNC_CODE(if (lock) lock->acquire());
 
-  if (sharedCounter)
-  {
-    --theRefCount;
-    if (--(*sharedCounter) == 0)
-    {
-      SYNC_CODE(if (lock) lock->release());
-      free();
-      return;
-    }
-  }
-  else if (--theRefCount == 0)
+  if (--theRefCount == 0)
   {
     SYNC_CODE(if (lock) lock->release());
     free();

=== modified file 'src/zorbatypes/rchandle.h'
--- src/zorbatypes/rchandle.h	2012-08-29 11:12:58 +0000
+++ src/zorbatypes/rchandle.h	2012-08-30 13:56:23 +0000
@@ -53,7 +53,7 @@
   reference count becomes 0.
 
 ********************************************************************************/
-class ZORBA_DLL_PUBLIC RCObject : public ::zorba::serialization::SerializeBaseClass
+class ZORBA_DLL_PUBLIC RCObject : public serialization::SerializeBaseClass
 {
 protected:
   mutable long  theRefCount;
@@ -93,38 +93,70 @@
 
   long getRefCount() const { return theRefCount; }
 
-  void addReference(long* sharedCounter SYNC_PARAM2(RCLock* lock)) const;
+  void addReference(SYNC_CODE(RCLock* lock)) const;
 
-  void removeReference(long* sharedCounter SYNC_PARAM2(RCLock* lock));
+  void removeReference(SYNC_CODE(RCLock* lock));
 };
 
 
 /*******************************************************************************
 
 ********************************************************************************/
-class ZORBA_DLL_PUBLIC SimpleRCObject : public RCObject
+class ZORBA_DLL_PUBLIC SimpleRCObject : public serialization::SerializeBaseClass
 {
-public:
-  SERIALIZABLE_CLASS(SimpleRCObject)
-  SERIALIZABLE_CLASS_CONSTRUCTOR2(SimpleRCObject, RCObject)
-  void serialize(::zorba::serialization::Archiver& ar);
-
-public:
-  SimpleRCObject() : RCObject() { }
-
-  SimpleRCObject(const SimpleRCObject& rhs) : RCObject(rhs) { }
-
-  void free() { delete this; }
-
-  long* getSharedRefCounter() const  { return NULL; } 
+protected:
+  mutable long  theRefCount;
+
+public:
+  SERIALIZABLE_CLASS(SimpleRCObject);
+
+  SimpleRCObject(serialization::Archiver& ar)  
+    :
+    serialization::SerializeBaseClass(),
+    theRefCount(0)
+  {
+  }
+
+  void serialize(serialization::Archiver& ar);
+
+public:
+  SimpleRCObject()
+    :
+    serialization::SerializeBaseClass(),
+    theRefCount(0)
+  {
+  }
+
+  SimpleRCObject(const SimpleRCObject&) 
+    :
+    serialization::SerializeBaseClass(),
+    theRefCount(0) 
+  {
+  }
+
+  virtual ~SimpleRCObject() { }
+
+  SimpleRCObject& operator=(const SimpleRCObject&) { return *this; }
+
+  virtual void free() { delete this; }
+
+  long getRefCount() const { return theRefCount; }
+
+  void addReference(SYNC_CODE(RCLock* lock)) const { ++theRefCount; }
+
+  void removeReference(SYNC_CODE(RCLock* lock))
+  {
+    if (--theRefCount == 0)
+    {
+      free();
+      return; 
+    }
+  }
 
   SYNC_CODE(RCLock* getRCLock() const { return NULL; })
-
-  SimpleRCObject& operator=(const SimpleRCObject&) { return *this; }
 };
 
 
-
 /*******************************************************************************
 
   rchandle = r(ef)c(ount)handle
@@ -166,7 +198,7 @@
   ~rchandle()
   {
     if (p)
-      p->removeReference(p->getSharedRefCounter() SYNC_PARAM2(p->getRCLock()));
+      p->removeReference(SYNC_CODE(p->getRCLock()));
     p = 0;
   }
 
@@ -221,8 +253,7 @@
   {
     if (p != rhs)
     {
-      if (p) p->removeReference(p->getSharedRefCounter()
-                                SYNC_PARAM2(p->getRCLock()));
+      if (p) p->removeReference(SYNC_CODE(p->getRCLock()));
       p = const_cast<T*>(rhs);
       init();
     }
@@ -233,8 +264,7 @@
   {
     if (p != rhs)
     {
-      if (p) p->removeReference(p->getSharedRefCounter()
-                                SYNC_PARAM2(p->getRCLock()));
+      if (p) p->removeReference(SYNC_CODE(p->getRCLock()));
       p = static_cast<T*>(const_cast<otherT*>(rhs));
       init();
     }
@@ -255,8 +285,7 @@
   {
     if (p != rhs.getp())
     {
-      if (p) p->removeReference(p->getSharedRefCounter()
-                                SYNC_PARAM2(p->getRCLock()));
+      if (p) p->removeReference(SYNC_CODE(p->getRCLock()));
       p = static_cast<T*>(rhs.getp());
       rhs.setNull();
     }
@@ -267,8 +296,7 @@
   {
     if (p != rhs.p)
     {
-      if (p) p->removeReference(p->getSharedRefCounter()
-                                SYNC_PARAM2(p->getRCLock()));
+      if (p) p->removeReference(SYNC_CODE(p->getRCLock()));
       p = rhs.p;
       rhs.p = NULL;
     }
@@ -294,7 +322,7 @@
   void init()
   {
     if (p == 0) return;
-    p->addReference(p->getSharedRefCounter() SYNC_PARAM2(p->getRCLock()));
+    p->addReference(SYNC_CODE(p->getRCLock()));
   }
 
 
@@ -302,8 +330,7 @@
   {
     if (p != rhs.getp())
     {
-      if (p) p->removeReference(p->getSharedRefCounter()
-                                SYNC_PARAM2(p->getRCLock()));
+      if (p) p->removeReference(SYNC_CODE(p->getRCLock()));
       p = static_cast<T*>(rhs.getp());
       init();
     }
@@ -312,15 +339,20 @@
 
 };
 
-namespace ztd {
+
+namespace ztd 
+{
 
 template<typename T> inline
-std::string to_string( rchandle<T> const &r ) {
+std::string to_string(const rchandle<T>& r)
+{
   return !r ? "<null>" : to_string( *r );
 }
 
+
 template<typename T,class OutputStringType> inline
-void to_string( rchandle<T> const &r, OutputStringType *out ) {
+void to_string(const rchandle<T>& r, OutputStringType* out )
+{
   if ( !r )
     *out = "<null>";
   else
@@ -349,11 +381,14 @@
   }
 
 public:
-  bool isNull () const        { return rchandle<T>::isNull(); }
-  void setNull()              { rchandle<T>::setNull();}
+  bool isNull () const { return rchandle<T>::isNull(); }
+
+  void setNull() { rchandle<T>::setNull();}
 
   const T* getp () const { return rchandle<T>::getp (); }
-  typename rchandle<T>::union_T getp_ref()             { return rchandle<T>::getp_ref(); }
+
+  typename rchandle<T>::union_T getp_ref() { return rchandle<T>::getp_ref(); }
+
   operator const T * () const { return rchandle<T>::getp (); }
 
   const T* operator->() const { return getp(); } 
@@ -376,15 +411,13 @@
   template<class T> 
   static void addReference(T *t)
   {
-    t->addReference(t->getSharedRefCounter()
-                    SYNC_PARAM2(t->getRCLock()));
+    t->addReference(SYNC_CODE(t->getRCLock()));
   }
 
   template<class T> 
   static void removeReference(T *t)
   {
-    t->removeReference(t->getSharedRefCounter()
-                       SYNC_PARAM2(t->getRCLock()));
+    t->removeReference(SYNC_CODE(t->getRCLock()));
   }
 
   template<class T> 


Follow ups