]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
add equals function for distribution add description for subtract function
authorSvetlana Shmidt <sshmidt@google.com>
Tue, 8 Sep 2020 09:18:41 +0000 (09:18 +0000)
committerSvetlana Shmidt <sshmidt@google.com>
Tue, 8 Sep 2020 09:18:41 +0000 (09:18 +0000)
src/daemon/distribution.c
src/daemon/distribution.h

index 53cdb04db3f6fd742c448d387fc9ae63d9850fc8..51cfeafd1f9eb77b5594e8603a4930d6f0ebeb44 100644 (file)
@@ -379,6 +379,17 @@ static int *distribution_cmp(distribution_t *d1, distribution_t *d2) {
   return comparison;
 }
 
+bool distribution_equal(distribution_t *d1, distribution_t *d2) {
+  pthread_mutex_lock(&d1->mutex);
+  pthread_mutex_lock(&d2->mutex);
+  int *cmp = distribution_cmp(d1, d2);
+  bool ans = (cmp[0] == 0 && cmp[1] == 0);
+  pthread_mutex_unlock(&d2->mutex);
+  pthread_mutex_unlock(&d1->mutex);
+  free(cmp);
+  return ans;
+}
+
 /* TODO(bkjg): add tests for this function */
 int distribution_sub(distribution_t *d1, distribution_t *d2) {
   pthread_mutex_lock(&d1->mutex);
@@ -403,6 +414,6 @@ int distribution_sub(distribution_t *d1, distribution_t *d2) {
 
   pthread_mutex_unlock(&d2->mutex);
   pthread_mutex_unlock(&d1->mutex);
-
+  free(cmp_status);
   return 0;
 }
index 28d6d1454b01a216fe29a204ba35292f719a9781..6c837f708a43a77f05125c78fdafbf4fb69dd0e2 100644 (file)
@@ -118,6 +118,14 @@ double distribution_squared_deviation_sum(distribution_t *dist);
 
 void destroy_buckets_array(buckets_array_t buckets_array);
 
-/* TODO(bkjg): add description */
+/** @return true if distributions are equal false otherwise
+ * This function holds both mutexes for d1 and d2. Be sure that you call the function with the same order of arguments everytime **/
+bool distribution_equals(distribution_t *d1, distribution_t *d2);
+
+/** This function subtracts d2 from d1 if arguments are correct
+ *  if arguments are NULL pointers or the structure of distributions is different then EINVAL is returned
+ *  if distributions have the same structure but the second distribution is not less then the first then ERANGE is returned
+ *  in case of success returns 0
+ *  This function holds both mutexes for d1 and d2. Be sure that you call the function with the same order of arguments everytime **/
 int distribution_sub(distribution_t *d1, distribution_t *d2);
 #endif // COLLECTD_DISTRIBUTION_H
\ No newline at end of file