Skip to content

Commit

Permalink
Merge pull request #75 from pzaino/develop
Browse files Browse the repository at this point in the history
last cumulative merge of improvements for today
  • Loading branch information
pzaino authored Jan 22, 2022
2 parents cb24da1 + fd1d13e commit 6150a8b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ tests: test
$(info ===========================)
$(info Running all found tests... )
$(info ===========================)
for test in $(TESTBINS) ; do ./$(TESTBIN)$$test ; done
for test in $(TESTBINS) ; do time ./$(TESTBIN)$$test ; done

.PHONY: debug
debug: CFLAGS+= -ggdb3
Expand Down
24 changes: 12 additions & 12 deletions tests/02ITest002.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,11 @@ void *producer(void *arg) {
// Let's test if the value we have retrieved is correct:
printf("Produced Event %*d: ID (%*d) - Message: %s\n", 2, i, 2,
item.eventID, item.msg);
evt_counter++;
fflush(stdout);
evt_counter++;
}

printf("Producer done. Produced %d events.\n", evt_counter);
testID++;

fflush(stdout);

pthread_exit(NULL);
Expand All @@ -131,34 +129,36 @@ void *consumer(void *arg) {
fflush(stdout);

uint32_t i;
for (i = 0; i < MAX_ITEMS; i++)
for (i = 0; i < MAX_ITEMS;)
{
while (vect_is_empty(v))
;
// For beginners: this is how in C we convert back a void * into the original dtata_type
StackItem *item = (StackItem *)malloc(sizeof(StackItem *));
int fetched_item = 0;

vect_lock(v);

// Let's retrieve the value from the vector correctly:
// For beginners: this is how in C we convert back a void * into the original dtata_type
StackItem *item = (StackItem *)malloc(sizeof(StackItem *));
if (!vect_is_empty(v))
{
item = (StackItem *)vect_pop(v);
fetched_item = 1;
}

vect_unlock(v);

if (item != NULL)
if ( fetched_item == 1 )
{
// Let's test if the value we have retrieved is correct:
printf("Consumed Event %*d: ID (%*d) - Message: %s\n", 2, i, 2, item->eventID, item->msg);
evt_counter++;
fflush(stdout);
evt_counter++;
i++;
}

free(item);
}

printf("Consumer done. Consumed %d events.\n", evt_counter);
testID++;

fflush(stdout);

pthread_exit(NULL);
Expand Down
24 changes: 12 additions & 12 deletions tests/02ITest003.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,11 @@ void *producer(void *arg) {
// Let's test if the value we have retrieved is correct:
printf("Produced Event %*d: ID (%*d) - Message: %s\n", 2, i, 2,
item.eventID, item.msg);
evt_counter++;
fflush(stdout);
evt_counter++;
}

printf("Producer done. Produced %d events.\n", evt_counter);
testID++;

fflush(stdout);

pthread_exit(NULL);
Expand All @@ -128,32 +126,34 @@ void *consumer(void *arg) {
fflush(stdout);

uint32_t i;
for (i = 0; i < MAX_ITEMS; i++) {
while (vect_is_empty(v))
;
for (i = 0; i < MAX_ITEMS;) {
// For beginners: this is how in C we convert back a void * into the original dtata_type
QueueItem *item = (QueueItem *)malloc(sizeof(QueueItem *));
int fetched_item = 0;

vect_lock(v);

// Let's retrieve the value from the vector correctly:
// For beginners: this is how in C we convert back a void * into the original dtata_type
QueueItem *item = (QueueItem *)malloc(sizeof(QueueItem *));
if (!vect_is_empty(v))
{
item = (QueueItem *)vect_remove_front(v);
fetched_item=1;
}

vect_unlock(v);

if ( item != NULL ) {
if ( fetched_item == 1 ) {
// Let's test if the value we have retrieved is correct:
printf("Consumed Event %*d: ID (%*d) - Message: %s\n", 2, i, 2, item->eventID, item->msg);
evt_counter++;
fflush(stdout);
evt_counter++;
i++;
}

free(item);
}

printf("Consumer done. Consumed %d events.\n", evt_counter);
testID++;

fflush(stdout);

pthread_exit(NULL);
Expand Down
5 changes: 3 additions & 2 deletions tests/02ITest004.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ void *producer(void *arg) {
// Let's test if the value we have retrieved is correct:
printf("T %*i produced Event %*d: ID (%*d) - Message: %s\n", 2, id, 2, i, 3,
item.eventID, item.msg);
evt_counter++;
fflush(stdout);
evt_counter++;
}

printf("Producer thread %i done. Produced %d events.\n", id, evt_counter);
fflush(stdout);

Expand Down Expand Up @@ -157,8 +158,8 @@ void *consumer(void *arg) {
{
// Let's test if the value we have retrieved is correct:
printf("T %*i consumed Event %*d: ID (%*d) - Message: %s\n", 2, id, 2, i, 3, item->eventID, item->msg);
evt_counter++;
fflush(stdout);
evt_counter++;
i++;
}

Expand Down

0 comments on commit 6150a8b

Please sign in to comment.