diff --git a/ddcd.cpp b/ddcd.cpp index ef428b7..e16a5c2 100644 --- a/ddcd.cpp +++ b/ddcd.cpp @@ -267,6 +267,8 @@ void* client_thread (void* param) //!TODO { client_t* me_the_client = (client_t*)param; + + pthread_exit(NULL); return NULL; } diff --git a/tsmpool.cpp b/tsmpool.cpp index 237ef44..6593595 100644 --- a/tsmpool.cpp +++ b/tsmpool.cpp @@ -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); } diff --git a/tsmpool.h b/tsmpool.h index f855226..2f097d1 100644 --- a/tsmpool.h +++ b/tsmpool.h @@ -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();