wangzhengquan
2020-07-28 6441a27cc69dc95d74f64f2869eb54181b10cbec
src/queue/hashtable.c
@@ -91,9 +91,12 @@
  size_t code = hashcode(key);
  tailq_entry_t *item;
  void *oldvalue;
  SemUtil::dec(hashtable->wlock);
  tailq_header_t *my_tailq_head = hashtable->array[code] ;
  if ( my_tailq_head == NULL)
  {
    SemUtil::inc(hashtable->wlock);
    return NULL;
  }
  else
@@ -108,11 +111,12 @@
        /* mm_free the item as we don't need it anymore. */
        mm_free(item);
        SemUtil::inc(hashtable->wlock);
        return oldvalue;
      }
    }
  }
  SemUtil::inc(hashtable->wlock);
  return NULL;
}
@@ -124,6 +128,7 @@
void hashtable_removeall(hashtable_t *hashtable)
{
  tailq_entry_t *item;
  SemUtil::dec(hashtable->wlock);
  for (int i = 0; i < MAPSIZE; i++)
  {
    tailq_header_t *my_tailq_head = hashtable->array[i] ;
@@ -139,6 +144,7 @@
    mm_free(my_tailq_head);
    hashtable->array[i] = NULL;
  }
  SemUtil::inc(hashtable->wlock);
}
/**
@@ -171,18 +177,7 @@
}
int hashtable_alloc_key(hashtable_t *hashtable) {
  int key = START_KEY;
  SemUtil::dec(hashtable->wlock);
  while(_hashtable_get(hashtable, key) != NULL) {
    key++;
  }
  _hashtable_put(hashtable, key, (void *)1);
  SemUtil::inc(hashtable->wlock);
  return key;
}
void *hashtable_get(hashtable_t *hashtable, int key) {
   SemUtil::dec(hashtable->mutex);
@@ -245,6 +240,19 @@
  }
}
int hashtable_alloc_key(hashtable_t *hashtable) {
  int key = START_KEY;
  SemUtil::dec(hashtable->wlock);
  while(_hashtable_get(hashtable, key) != NULL) {
    key++;
  }
  _hashtable_put(hashtable, key, (void *)1);
  SemUtil::inc(hashtable->wlock);
  return key;
}
std::set<int> * hashtable_keyset(hashtable_t *hashtable) {
  std::set<int> *keyset = new std::set<int>;
  tailq_entry_t *item;
@@ -261,3 +269,5 @@
  }
  return keyset;
}