Commit 2c3773fe authored by Théo De Waele's avatar Théo De Waele

Suppression mutex_busy

parent 88f6e4d2
Pipeline #9371 failed with stage
in 0 seconds
......@@ -36,7 +36,7 @@ typedef struct s_Data
int small_factors_size; /**< The size of the allocated buffer Data#small_factors */
int small_factors_count; /**< The number of factors smaller than 2**16 found */
pthread_mutex_t busy; /**< The mutex used if there is multiple producer threads */
struct s_Data *next; /**< Link to the next @c Data struct or NULL if it's the end of the list*/
......
......@@ -74,8 +74,8 @@ Data *Data__init(void)
mpz_init(self->N);
mpz_init(self->remainder);
// Initialize the busy mutex
pthread_mutex_init(&(self->busy), NULL);
self->next = NULL;
return self;
......@@ -123,7 +123,7 @@ Data *__Data__destroy(Data *self, void *a __attribute__((unused))) //correction
for(int i=0; i < self->big_factors_size; i++)
mpz_clear(self->big_factors[i]);
pthread_mutex_destroy(&self->busy);
free(self->big_factors);
free(self);
......
......@@ -46,15 +46,14 @@ void *produce(void *args)
Data *head = (Data*) args;
while(head)
{
if(pthread_mutex_trylock(&(head->busy)) != EBUSY)
{
//Wait for empty slot lock and insert a node
sem_wait(&(threads_buffer->empty));
pthread_mutex_lock(&(threads_buffer->buffer_mutex));
ThreadBuffer__insert(head);
pthread_mutex_unlock(&(threads_buffer->buffer_mutex));
sem_post(&(threads_buffer->full));
}
head = head->next;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment