Skip to content
Snippets Groups Projects
Commit 566f87d4 authored by Barbu Alexandru Daniel's avatar Barbu Alexandru Daniel
Browse files

Linter fixes 2.


Signed-off-by: default avatarBarbu Alexandru Daniel <barbualex.daniel2004@gmail.com>
parent 3ec63791
No related branches found
No related tags found
1 merge request!9Solutions
Pipeline #93814 passed
......@@ -32,9 +32,9 @@ void add_packet(char *packet, int writer_id)
writers[writer_id].status = 1;
char out_buf[PKT_SZ];
int len = snprintf(out_buf, 256, "%s %016lx %lu\n",
RES_TO_STR(rez), hash, timestamp);
// char out_buf[PKT_SZ];
// int len = snprintf(out_buf, 256, "%s %016lx %lu\n",
// RES_TO_STR(rez), hash, timestamp);
// printf("Idnetificator: %s\n", out_buf);
}
......@@ -67,17 +67,14 @@ int everyone_is_finished(void)
return 1;
}
void print_results_to_file(char *empty_packet)
void print_results_to_file(void)
{
for (int i = 0; i < num_of_threads; i++) {
if (memcmp(&writers[i], empty_packet, PKT_SZ)) {
char out_buf[PKT_SZ];
int len = snprintf(out_buf, 256, "%s %016lx %lu\n",
RES_TO_STR(writers[i].rez), writers[i].hash, writers[i].timestamp);
write(out_file_fd, out_buf, len);
}
char out_buf[PKT_SZ];
int len = snprintf(out_buf, 256, "%s %016lx %lu\n",
RES_TO_STR(writers[i].rez), writers[i].hash, writers[i].timestamp);
write(out_file_fd, out_buf, len);
}
}
......@@ -91,6 +88,7 @@ void *consumer_thread(void *args)
char *empty_packet = calloc(1, PKT_SZ);
int to_be_continued = 1;
while (to_be_continued) {
pthread_mutex_lock(&consumer_dequeue_lock);
......@@ -128,39 +126,14 @@ void *consumer_thread(void *args)
pthread_mutex_lock(&consumer_write_lock);
if (everyone_is_finished()) {
sort_packets();
print_results_to_file(empty_packet);
print_results_to_file();
empty_packet_array();
}
pthread_mutex_unlock(&consumer_write_lock);
// if (!ctx->producer_rb->producer_is_alive && ctx->producer_rb->len <= 0)
// {
// break;
// }
// // packet processing, thread independent
// int rez = process_packet((so_packet_t *)packet);
// unsigned long hash = packet_hash((so_packet_t *)packet);
// unsigned long timestamp = ((so_packet_t *)packet)->hdr.timestamp;
// // print the packet log
// char out_buf[PKT_SZ];
// int len = snprintf(out_buf, 256, "%s %016lx %lu\n",
// RES_TO_STR(rez), hash, timestamp);
// // printf("thread: %d wrote %s", ctx->thread_number, out_buf);
// pthread_mutex_lock(&consumer_write_lock);
// write(out_file_fd, out_buf, len);
// pthread_mutex_unlock(&consumer_write_lock);
memset(packet, 0, PKT_SZ);
}
// printf("thread: %d finished\n", ctx->thread_number);
free(packet);
free(empty_packet);
free(ctx);
......@@ -180,6 +153,7 @@ int create_consumers(pthread_t *tids,
for (int i = 0; i < num_consumers; i++) {
/* TODO: Launch consumer threads */
so_consumer_ctx_t *ctx = calloc(1, sizeof(so_consumer_ctx_t));
ctx->producer_rb = rb;
ctx->out_file_name = out_filename;
ctx->thread_number = i;
......@@ -202,4 +176,4 @@ void set_common_variables(int outus_fd, int thrd_cnt)
{
out_file_fd = outus_fd;
num_of_threads = thrd_cnt;
}
\ No newline at end of file
}
No preview for this file type
......@@ -4,7 +4,7 @@
#define PKT_SIZE 256
int is_initialised = 0;
int is_initialised;
pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t producer_started = PTHREAD_COND_INITIALIZER;
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment