Skip to content

Commit

Permalink
Revert "Removed keys from com, it was not used."
Browse files Browse the repository at this point in the history
We need keys actually.

This reverts commit 1477ccd.
  • Loading branch information
Nikhil Samith Bysani committed Jan 18, 2009
1 parent 1477ccd commit 2f71fa6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/base/bang-com.c
Expand Up @@ -179,6 +179,12 @@ static unsigned int current_peers = 0;
*/
static peer **peers = NULL;

/**
* TODO: make this structure not take linear time when sending a request
* to a specific peer
*/
static int *keys = NULL;

static void acquire_peers_read_lock() {
pthread_mutex_lock(&peers_read_lock);
if (peers_readers == 0)
Expand Down Expand Up @@ -644,6 +650,9 @@ void BANG_add_peer(int socket) {
int current_key = current_peers - 1;
int current_id = peer_count++;

keys = (int*) realloc(keys,current_peers * sizeof(int));
keys[current_key] = current_id;

peers = (peer**) realloc(peers,current_peers * sizeof(peer*));
peers[current_key] = new_peer();
peers[current_key]->peer_id = current_id;
Expand Down Expand Up @@ -701,12 +710,14 @@ void BANG_remove_peer(int peer_id) {

for (;((unsigned int)pos) < current_peers - 1; ++pos) {
peers[pos] = peers[pos + 1];
keys[pos] = keys[pos + 1];
}

--current_peers;


peers = (peer**) realloc(peers,current_peers * sizeof(peer*));
keys = (int*) realloc(keys,current_peers * sizeof(int));

pthread_mutex_unlock(&peers_change_lock);

Expand Down Expand Up @@ -746,6 +757,8 @@ void BANG_com_close() {
pthread_mutex_destroy(&peers_change_lock);
pthread_mutex_destroy(&peers_read_lock);
free(peers);
free(keys);
keys = NULL;
peers = NULL;
current_peers = 0;
peer_count = 0;
Expand Down

0 comments on commit 2f71fa6

Please sign in to comment.