Skip to content

Commit

Permalink
Switched from slave-peer model to removing the words master-slave and
Browse files Browse the repository at this point in the history
having two threads per peer.
  • Loading branch information
Nikhil Samith Bysani committed Dec 21, 2008
1 parent 20fb9dc commit b6162aa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
49 changes: 27 additions & 22 deletions src/base/bang-com.c
Expand Up @@ -8,48 +8,53 @@
#include"bang-com.h"
#include"bang-signals.h"
#include<pthread.h>
#include<semaphore.h>
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<unistd.h>

/**
* \page Master-Slave Model
*
* A master thread should service requests from its slave-peer threads, and then request
* things of them. (These requests would be made by the modules).
*/
typedef struct _request_node {
struct _request_node *next;
} request_node;

typedef struct {
sem_t lock;
sem_t num_requests;
request_node *node;
} BANG_requests;

///Represents one of our peers.
typedef struct {
pthread_t *thread;
int peer_id;
} peer_slave;
BANG_requests *requests;
} peer;

int num_peers = 0;
peer_slave *peer_slaves;

///TODO: Question to be answered, how do these communicate? BANG_signals?
peer *peers;

void* BANG_master_thread(void *args) {
///TODO:Implement this whole thing..
while (1) {
}
return NULL;
}

void* BANG_slave_thread(void *socket) {
///TODO: Implement this whole idea.. uhh any volunteers?
/**
* \page Peer Implemntation
* Outgoing requests are serviced by iterating through the peers and sending out requests using the
* peers list and corresponding structure. There are two threads for each peer. One to manage
* incoming requests, and one to manage outgoing requests.
*/
void* BANG_peer_thread(void *socket) {
while (1) {}
close(*((int*)socket));
free(socket);
return NULL;
}

void BANG_connection_signal_handler(int signal,int sig_id,void* socket) {
peer_slaves = (peer_slave*) realloc(peer_slaves,(++num_peers) * sizeof(peer_slave));
peer_slaves[num_peers - 1].thread = (pthread_t*) calloc(1,sizeof(pthread_t));
peer_slaves[num_peers - 1].peer_id = num_peers - 1;
pthread_create(peer_slaves[num_peers - 1].thread,NULL,&BANG_slave_thread,socket);
peers= (peer*) realloc(peers,(++num_peers) * sizeof(peer));
peers[num_peers - 1].thread = (pthread_t*) calloc(1,sizeof(pthread_t));
peers[num_peers - 1].peer_id = num_peers - 1;
peers[num_peers - 1].requests = (BANG_requests*) calloc(1,sizeof(BANG_requests));
sem_init(&(peers[num_peers - 1].requests->lock),0,1);
sem_init(&(peers[num_peers - 1].requests->num_requests),0,0);
pthread_create(peers[num_peers - 1].thread,NULL,&BANG_peer_thread,socket);
BANG_acknowledge_signal(signal,sig_id);
}
12 changes: 2 additions & 10 deletions src/base/bang-com.h
Expand Up @@ -7,20 +7,12 @@
* */
#ifndef __BANG_COM_H
#define __BANG_COM_H
/**
* \param args
*
* \brief The master of all the slaves threads. It should make sure their request are fulfilled, and
* send out requests using its slaves.
*/
void* BANG_master_thread(void *args);

/**
* \param socket The connection with the peer.
*
* \brief A slave connection thread. This thread symbolizes a connection with another peer.
* \brief A peer connection thread.
*/
void* BANG_slave_thread(void *socket);
void* BANG_peer_thread(void *socket);

/**
* \param socket The slave client socket.
Expand Down
1 change: 1 addition & 0 deletions src/base/bang-module.h
Expand Up @@ -21,4 +21,5 @@ int BANG_load_module(char *path);
* \brief Runs a module.
*/
void BANG_run_module(BANG_module *module);

#endif

0 comments on commit b6162aa

Please sign in to comment.