trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject [1/6] git commit: TS-2534 Make sure RecRecord structs are always properly initialized
Date Fri, 31 Jan 2014 20:45:44 GMT
Updated Branches:
  refs/heads/master 8824fbe93 -> d081cdf34


TS-2534 Make sure RecRecord structs are always properly initialized


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/58d3c53c
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/58d3c53c
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/58d3c53c

Branch: refs/heads/master
Commit: 58d3c53c1833a83caca7e399cd34494274b1f2d9
Parents: 8824fbe
Author: Leif Hedstrom <zwoop@apache.org>
Authored: Fri Jan 31 11:11:24 2014 -0700
Committer: Leif Hedstrom <zwoop@apache.org>
Committed: Fri Jan 31 12:16:26 2014 -0700

----------------------------------------------------------------------
 lib/records/I_RecMutex.h |  1 +
 lib/records/P_RecCore.cc | 17 +++++++++++++----
 lib/records/P_RecUtils.h |  9 ++++++++-
 lib/records/RecCore.cc   |  1 -
 lib/records/RecMutex.cc  | 11 ++++++++---
 lib/records/RecUtils.cc  | 20 ++++++++++++++++++--
 6 files changed, 48 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/58d3c53c/lib/records/I_RecMutex.h
----------------------------------------------------------------------
diff --git a/lib/records/I_RecMutex.h b/lib/records/I_RecMutex.h
index 5c59ea2..ace1d26 100644
--- a/lib/records/I_RecMutex.h
+++ b/lib/records/I_RecMutex.h
@@ -40,6 +40,7 @@ struct RecMutex
 };
 
 int rec_mutex_init(RecMutex * m, const char *name = NULL);
+int rec_mutex_destroy(RecMutex * m);
 int rec_mutex_acquire(RecMutex * m);
 int rec_mutex_release(RecMutex * m);
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/58d3c53c/lib/records/P_RecCore.cc
----------------------------------------------------------------------
diff --git a/lib/records/P_RecCore.cc b/lib/records/P_RecCore.cc
index b90a5d3..b8498e4 100644
--- a/lib/records/P_RecCore.cc
+++ b/lib/records/P_RecCore.cc
@@ -33,6 +33,7 @@
 
 RecModeT g_mode_type = RECM_NULL;
 
+
 //-------------------------------------------------------------------------
 // send_reset_message
 //-------------------------------------------------------------------------
@@ -439,7 +440,8 @@ RecSetRecord(RecT rec_type, const char *name, RecDataT data_type, RecData
*data,
       // We don't need to ats_strdup() here as we will make copies of any
       // strings when we marshal them into our RecMessage buffer.
       RecRecord r2;
-      memset(&r2, 0, sizeof(RecRecord));
+
+      RecRecordInit(&r2);
       r2.rec_type = rec_type;
       r2.name = name;
       r2.data_type = (data_type != RECD_NULL) ? data_type : r1->data_type;
@@ -448,6 +450,7 @@ RecSetRecord(RecT rec_type, const char *name, RecDataT data_type, RecData
*data,
         r2.stat_meta.data_raw = *data_raw;
       }
       err = send_set_message(&r2);
+      RecRecordFree(&r2);
     }
   } else {
     // Add the record but do not set the 'registered' flag, as this
@@ -850,13 +853,15 @@ RecResetStatRecord(const char *name)
       err = REC_ERR_OKAY;
     } else {
       RecRecord r2;
-      memset(&r2, 0, sizeof(RecRecord));
+
+      RecRecordInit(&r2);
       r2.rec_type = r1->rec_type;
       r2.name = r1->name;
       r2.data_type = r1->data_type;
       r2.data = r1->data_default;
 
       err = send_reset_message(&r2);
+      RecRecordFree(&r2);
     }
   } else {
     err = REC_ERR_FAIL;
@@ -893,13 +898,15 @@ RecResetStatRecord(RecT type, bool all)
         rec_mutex_release(&(r1->lock));
       } else {
         RecRecord r2;
-        memset(&r2, 0, sizeof(RecRecord));
+
+        RecRecordInit(&r2);
         r2.rec_type = r1->rec_type;
         r2.name = r1->name;
         r2.data_type = r1->data_type;
         r2.data = r1->data_default;
 
         err = send_reset_message(&r2);
+        RecRecordFree(&r2);
       }
     }
   }
@@ -936,13 +943,15 @@ RecSetSyncRequired(char *name, bool lock)
 
       /*
          RecRecord r2;
-         memset(&r2, 0, sizeof(RecRecord));
+
+         RecRecordInit(&r2);
          r2.rec_type  = r1->rec_type;
          r2.name      = r1->name;
          r2.data_type = r1->data_type;
          r2.data      = r1->data_default;
 
          err = send_set_message(&r2);
+         RecRecordFree(&r2);
        */
     }
   }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/58d3c53c/lib/records/P_RecUtils.h
----------------------------------------------------------------------
diff --git a/lib/records/P_RecUtils.h b/lib/records/P_RecUtils.h
index ee90f70..de8f018 100644
--- a/lib/records/P_RecUtils.h
+++ b/lib/records/P_RecUtils.h
@@ -45,10 +45,17 @@
 
 
 //-------------------------------------------------------------------------
+// RecRecord Utils
+//-------------------------------------------------------------------------
+void RecRecordInit(RecRecord *r);
+void RecRecordFree(RecRecord *r);
+RecRecord *RecAlloc(RecT rec_type, const char *name, RecDataT data_type);
+
+
+//-------------------------------------------------------------------------
 // RecData Utils
 //-------------------------------------------------------------------------
 
-RecRecord *RecAlloc(RecT rec_type, const char *name, RecDataT data_type);
 void RecDataClear(RecDataT type, RecData * data);
 void RecDataSetMax(RecDataT type, RecData * data);
 void RecDataSetMin(RecDataT type, RecData * data);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/58d3c53c/lib/records/RecCore.cc
----------------------------------------------------------------------
diff --git a/lib/records/RecCore.cc b/lib/records/RecCore.cc
index 1ed4e10..bcfe6c6 100644
--- a/lib/records/RecCore.cc
+++ b/lib/records/RecCore.cc
@@ -170,7 +170,6 @@ RecCoreInit(RecModeT mode_type, Diags *_diags)
 
   // initialize record array for our internal stats (this can be reallocated later)
   g_records = (RecRecord *)ats_malloc(REC_MAX_RECORDS * sizeof(RecRecord));
-  memset(g_records, 0, REC_MAX_RECORDS * sizeof(RecRecord));
 
   // initialize record hash index
   g_records_ht = ink_hash_table_create(InkHashTableKeyType_String);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/58d3c53c/lib/records/RecMutex.cc
----------------------------------------------------------------------
diff --git a/lib/records/RecMutex.cc b/lib/records/RecMutex.cc
index 888c96c..797e285 100644
--- a/lib/records/RecMutex.cc
+++ b/lib/records/RecMutex.cc
@@ -33,6 +33,14 @@ rec_mutex_init(RecMutex * m, const char *name)
 }
 
 int
+rec_mutex_destroy(RecMutex * m)
+{
+  ink_assert(m->nthread_holding == 0);
+  ink_assert(m->thread_holding == 0);
+  return ink_mutex_destroy(&(m->the_mutex));
+}
+
+int
 rec_mutex_acquire(RecMutex * m)
 {
 
@@ -45,7 +53,6 @@ rec_mutex_acquire(RecMutex * m)
 
   m->nthread_holding++;
   return 0;
-
 }
 
 int
@@ -59,7 +66,5 @@ rec_mutex_release(RecMutex * m)
       ink_mutex_release(&(m->the_mutex));
     }
   }
-
   return 0;
-
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/58d3c53c/lib/records/RecUtils.cc
----------------------------------------------------------------------
diff --git a/lib/records/RecUtils.cc b/lib/records/RecUtils.cc
index 8485984..97feec0 100644
--- a/lib/records/RecUtils.cc
+++ b/lib/records/RecUtils.cc
@@ -27,6 +27,22 @@
 #include "P_RecTree.h"
 
 //-------------------------------------------------------------------------
+// RecRecord initializer / Free
+//-------------------------------------------------------------------------
+void
+RecRecordInit(RecRecord *r)
+{
+  ink_zero(*r);
+  rec_mutex_init(&(r->lock), NULL);
+}
+
+void
+RecRecordFree(RecRecord *r)
+{
+  rec_mutex_destroy(&(r->lock));
+}
+
+//-------------------------------------------------------------------------
 // RecAlloc
 //-------------------------------------------------------------------------
 RecRecord*
@@ -39,12 +55,12 @@ RecAlloc(RecT rec_type, const char *name, RecDataT data_type)
 
   int i = ink_atomic_increment(&g_num_records, 1);
   RecRecord *r = &(g_records[i]);
-  // Note: record should already be memset to 0 from RecCoreInit()
+
+  RecRecordInit(r);
   r->rec_type = rec_type;
   r->name = ats_strdup(name);
   r->order = i;
   r->data_type = data_type;
-  rec_mutex_init(&(r->lock), NULL);
 
   g_records_tree->rec_tree_insert(r->name);
 


Mime
View raw message