Browse Source

more minor speed improvements

David Rose 19 years ago
parent
commit
4559b15c18

+ 0 - 1
panda/src/display/graphicsStateGuardian.cxx

@@ -1260,7 +1260,6 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
                       const GeomVertexDataPipelineReader *data_reader) {
                       const GeomVertexDataPipelineReader *data_reader) {
   _munger = munger;
   _munger = munger;
   _data_reader = data_reader;
   _data_reader = data_reader;
-  nassertr(geom_reader->check_valid(data_reader), false);
   return _data_reader->has_vertex();
   return _data_reader->has_vertex();
 }
 }
 
 

+ 1 - 0
panda/src/gobj/geom.cxx

@@ -1386,6 +1386,7 @@ draw(GraphicsStateGuardianBase *gsg, const GeomMunger *munger,
       GeomPrimitivePipelineReader reader(primitive, _current_thread);
       GeomPrimitivePipelineReader reader(primitive, _current_thread);
       if (reader.get_num_vertices() != 0) {
       if (reader.get_num_vertices() != 0) {
         reader.check_minmax();
         reader.check_minmax();
+        nassertv(reader.check_valid(data_reader));
         primitive->draw(gsg, &reader);
         primitive->draw(gsg, &reader);
       }
       }
     }
     }

+ 9 - 9
panda/src/pgraph/renderState.cxx

@@ -621,16 +621,16 @@ unref() const {
   if (get_cache_ref_count() > 0 &&
   if (get_cache_ref_count() > 0 &&
       get_ref_count() == get_cache_ref_count() + 1) {
       get_ref_count() == get_cache_ref_count() + 1) {
 
 
-    ReMutexHolder holder(*_states_lock);
-
-    if (get_cache_ref_count() > 0 &&
-        get_ref_count() == get_cache_ref_count() + 1) {
-      // If we are about to remove the one reference that is not in the
-      // cache, leaving only references in the cache, then we need to
-      // check for a cycle involving this RenderState and break it if
-      // it exists.
+    if (auto_break_cycles) {
+      ReMutexHolder holder(*_states_lock);
       
       
-      if (auto_break_cycles) {
+      if (get_cache_ref_count() > 0 &&
+          get_ref_count() == get_cache_ref_count() + 1) {
+        // If we are about to remove the one reference that is not in the
+        // cache, leaving only references in the cache, then we need to
+        // check for a cycle involving this RenderState and break it if
+        // it exists.
+        
         ++_last_cycle_detect;
         ++_last_cycle_detect;
         if (r_detect_cycles(this, this, 1, _last_cycle_detect, NULL)) {
         if (r_detect_cycles(this, this, 1, _last_cycle_detect, NULL)) {
           // Ok, we have a cycle.  This will be a leak unless we break the
           // Ok, we have a cycle.  This will be a leak unless we break the

+ 9 - 9
panda/src/pgraph/transformState.cxx

@@ -820,16 +820,16 @@ unref() const {
   if (get_cache_ref_count() > 0 &&
   if (get_cache_ref_count() > 0 &&
       get_ref_count() == get_cache_ref_count() + 1) {
       get_ref_count() == get_cache_ref_count() + 1) {
 
 
-    ReMutexHolder holder(*_states_lock);
-
-    if (get_cache_ref_count() > 0 &&
-        get_ref_count() == get_cache_ref_count() + 1) {
-      // If we are about to remove the one reference that is not in the
-      // cache, leaving only references in the cache, then we need to
-      // check for a cycle involving this TransformState and break it if
-      // it exists.
+    if (auto_break_cycles) {
+      ReMutexHolder holder(*_states_lock);
       
       
-      if (auto_break_cycles) {
+      if (get_cache_ref_count() > 0 &&
+          get_ref_count() == get_cache_ref_count() + 1) {
+        // If we are about to remove the one reference that is not in the
+        // cache, leaving only references in the cache, then we need to
+        // check for a cycle involving this TransformState and break it if
+        // it exists.
+        
         ++_last_cycle_detect;
         ++_last_cycle_detect;
         if (r_detect_cycles(this, this, 1, _last_cycle_detect, NULL)) {
         if (r_detect_cycles(this, this, 1, _last_cycle_detect, NULL)) {
           // Ok, we have a cycle.  This will be a leak unless we break the
           // Ok, we have a cycle.  This will be a leak unless we break the

+ 43 - 17
panda/src/putil/updateSeq.I

@@ -23,7 +23,7 @@
 //  Description: Creates an UpdateSeq in the 'initial' state.
 //  Description: Creates an UpdateSeq in the 'initial' state.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE UpdateSeq::
 INLINE UpdateSeq::
-UpdateSeq() : _lock("UpdateSeq") {
+UpdateSeq() {
   _seq = (unsigned int)SC_initial;
   _seq = (unsigned int)SC_initial;
 }
 }
 
 
@@ -67,7 +67,7 @@ fresh() {
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE UpdateSeq::
 INLINE UpdateSeq::
-UpdateSeq(const UpdateSeq &copy) : _lock("UpdateSeq") {
+UpdateSeq(const UpdateSeq &copy) {
   _seq = AtomicAdjust::get(copy._seq);
   _seq = AtomicAdjust::get(copy._seq);
 }
 }
 
 
@@ -203,18 +203,30 @@ operator >= (const UpdateSeq &other) const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE UpdateSeq UpdateSeq::
 INLINE UpdateSeq UpdateSeq::
 operator ++ () {
 operator ++ () {
-  {
-    MutexHolder holder(_lock);
+  PN_int32 old_seq = AtomicAdjust::get(_seq);
+  PN_int32 new_seq = old_seq + 1;
+  if (priv_is_special(new_seq)) {
+    // Oops, wraparound.  We don't want to confuse the new value
+    // with our special cases.
+    new_seq = (PN_int32)SC_old;
+  }
 
 
-    PN_int32 new_seq = _seq + 1;
+#ifdef HAVE_THREADS
+  PN_int32 result = AtomicAdjust::compare_and_exchange(_seq, old_seq, new_seq);
+  while (result != old_seq) {
+    // Some other thread beat us to it; try again.
+    old_seq = AtomicAdjust::get(_seq);
+    new_seq = old_seq + 1;
     if (priv_is_special(new_seq)) {
     if (priv_is_special(new_seq)) {
       // Oops, wraparound.  We don't want to confuse the new value
       // Oops, wraparound.  We don't want to confuse the new value
       // with our special cases.
       // with our special cases.
-      AtomicAdjust::set(_seq, (PN_int32)SC_old + 1);
-    } else {
-      AtomicAdjust::set(_seq, new_seq);
+      new_seq = (PN_int32)SC_old;
     }
     }
+    result = AtomicAdjust::compare_and_exchange(_seq, old_seq, new_seq);
   }
   }
+#else
+  _seq = new_seq;
+#endif  // HAVE_THREADS
     
     
   return *this;
   return *this;
 }
 }
@@ -226,19 +238,33 @@ operator ++ () {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE UpdateSeq UpdateSeq::
 INLINE UpdateSeq UpdateSeq::
 operator ++ (int) {
 operator ++ (int) {
-  UpdateSeq temp;
-  {
-    MutexHolder holder(_lock);
-    temp._seq = _seq;
+  PN_int32 old_seq = AtomicAdjust::get(_seq);
+  PN_int32 new_seq = old_seq + 1;
+  if (priv_is_special(new_seq)) {
+    // Oops, wraparound.  We don't want to confuse the new value
+    // with our special cases.
+    new_seq = (PN_int32)SC_old;
+  }
 
 
-    PN_int32 new_seq = _seq + 1;
+#ifdef HAVE_THREADS
+  PN_int32 result = AtomicAdjust::compare_and_exchange(_seq, old_seq, new_seq);
+  while (result != old_seq) {
+    // Some other thread beat us to it; try again.
+    old_seq = AtomicAdjust::get(_seq);
+    new_seq = old_seq + 1;
     if (priv_is_special(new_seq)) {
     if (priv_is_special(new_seq)) {
-      AtomicAdjust::set(_seq, (PN_int32)SC_old + 1);
-    } else {
-      AtomicAdjust::set(_seq, new_seq);
+      // Oops, wraparound.  We don't want to confuse the new value
+      // with our special cases.
+      new_seq = (PN_int32)SC_old;
     }
     }
+    result = AtomicAdjust::compare_and_exchange(_seq, old_seq, new_seq);
   }
   }
-    
+#else
+  _seq = new_seq;
+#endif  // HAVE_THREADS
+
+  UpdateSeq temp;
+  temp._seq = old_seq;
   return temp;
   return temp;
 }
 }
 
 

+ 0 - 1
panda/src/putil/updateSeq.h

@@ -86,7 +86,6 @@ private:
   };
   };
 
 
   PN_int32 _seq;
   PN_int32 _seq;
-  Mutex _lock;
 };
 };
 
 
 INLINE ostream &operator << (ostream &out, const UpdateSeq &value);
 INLINE ostream &operator << (ostream &out, const UpdateSeq &value);