Don't allow readers reach the buffer currently being filled.

feature/nmux
ha7ilm 2016-06-04 23:05:38 +02:00
rodzic 3a38be042a
commit d442696cb8
3 zmienionych plików z 7 dodań i 4 usunięć

Wyświetl plik

@ -267,6 +267,8 @@ void* client_thread (void* param) //!TODO
{
client_t* me_the_client = (client_t*)param;
pthread_exit(NULL);
return NULL;
}

Wyświetl plik

@ -7,6 +7,7 @@ tsmpool::tsmpool(size_t size, int num)
this->num = num; //number of buffers of (size) to alloc
this->ok = 1;
this->lowest_read_index = -1;
this->write_index = 0;
if (pthread_mutex_init(&this->mutex, NULL) != 0) this->ok=0;
}
@ -14,7 +15,7 @@ size_t tsmpool::get_size() { return this->size; }
void* tsmpool::get_write_buffer()
{
if(write_index==index_before(lowest_read_index)) return NULL;
//if(write_index==index_before(lowest_read_index)) return NULL;
void* to_return = buffers[write_index];
write_index=index_next(write_index);
}
@ -24,7 +25,7 @@ tsmthread_t* tsmpool::register_thread()
if(!ok) return NULL;
pthread_mutex_lock(&this->mutex);
tsmthread_t* thread = new tsmthread_t;
thread->read_index = write_index;
thread->read_index = index_before(write_index);
threads.push_back(thread);
pthread_mutex_unlock(&this->mutex);
return thread;
@ -45,7 +46,7 @@ int tsmpool::remove_thread(tsmthread_t* thread)
void* tsmpool::get_read_buffer(tsmthread_t* thread)
{
if(thread->read_index==write_index) return NULL;
if(thread->read_index==index_before(write_index)) return NULL;
void* to_return = buffers[thread->read_index];
thread->read_index=index_next(thread->read_index);
}

Wyświetl plik

@ -19,7 +19,7 @@ private:
pthread_mutex_t mutex;
int ok;
int write_index; //it always points to the next buffer to be written
int lowest_read_index;
int lowest_read_index; //unused
public:
size_t get_size();