This commit is contained in:
Nikolaj
2021-11-21 12:35:45 +01:00
parent db4ae92595
commit a833af7f36
5 changed files with 12 additions and 5 deletions

Binary file not shown.

View File

@ -14,7 +14,7 @@
#include "job_queue.h"
pthread_mutex_t stdout_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
// err.h contains various nonstandard BSD extensions, but they are
// very handy.
@ -26,7 +26,12 @@ int global_histogram[8] = { 0 };
struct job_queue q;
void update_histogram_mt(int local_histogram[8]) {
pthread_mutex_lock(&mutex);
merge_histogram(local_histogram, global_histogram);
print_histogram(global_histogram);
pthread_mutex_unlock(&mutex);
}
int fhistogram_mt(char const *path) {
FILE *f = fopen(path, "r");

Binary file not shown.

Binary file not shown.

View File

@ -329,7 +329,9 @@ csc_file_t* csc_parse_file(const char* sourcefile, const char* destination)
casc_file_data->blockcount = 1 + floor(
(casc_file_data->targetsize - 1.0)/casc_file_data->blocksize
);
casc_file_data->trailblocksize = casc_file_data->targetsize - ((casc_file_data->blockcount - 1) * casc_file_data->blocksize);
casc_file_data->trailblocksize = casc_file_data->targetsize - (
(casc_file_data->blockcount - 1) * casc_file_data->blocksize
);
casc_file_data->completed = 0;
csc_block_t* block_list = malloc(
@ -405,8 +407,9 @@ void get_block(csc_block_t* block, csc_peer_t peer, unsigned char* hash, char* o
} else {
buffer_size = MAX_LINE;
}
rio_t rio;
char rio_buf[buffer_size];
rio_t rio;
int peer_socket;
peer_socket = Open_clientfd(peer.ip, peer.port);
Rio_readinitb(&rio, peer_socket);
@ -487,7 +490,6 @@ void get_block(csc_block_t* block, csc_peer_t peer, unsigned char* hash, char* o
*/
int get_peers_list(csc_peer_t** peers, uint8_t hash[32])
{
rio_t rio;
uint8_t rio_buf[MAX_LINE];