raft_entry_t *log_peektail(log_t * me_) { log_private_t* me = (log_private_t*)me_; if (0 == log_count(me_)) return NULL; if (0 == me->back) return &me->entries[me->size - 1]; else return &me->entries[me->back - 1]; }
void *log_poll(log_t * me_) { log_private_t* me = (log_private_t*)me_; if (0 == log_count(me_)) return NULL; const void *elem = &me->entries[me->front]; if (me->cb && me->cb->log_poll) me->cb->log_poll(me->raft, raft_get_udata(me->raft), &me->entries[me->front], me->front); me->front++; me->count--; me->base_log_idx++; return (void*)elem; }
void log_delete(log_t* me_, int idx) { log_private_t* me = (log_private_t*)me_; int end; /* idx starts at 1 */ idx -= 1; idx -= me->base_log_idx; for (end = log_count(me_); idx < end; idx++) { if (me->cb && me->cb->log_pop) me->cb->log_pop(me->raft, raft_get_udata(me->raft), &me->entries[me->back], me->back); me->back--; me->count--; } }
/* * Entry point: WordCounter * The word counter reads file names from the files queue, one by one, and counts the words in them. * It will write the result to a log file. * Then it should free the memory of the dequeued file name string (it was allocated by the Listener thread). * If the dequeue operation fails (returns NULL), it means that the application is trying * to exit and therefore the thread should simply terminate. */ void *run_wordcounter(void *param) { WordCounterData *data; BoundedBuffer *buff; int word_count; char *dequeued_file; data = (WordCounterData*) param; buff = data->buff; // Keep dequeuing until signal is given to exit application (NULL) while ((dequeued_file = bounded_buffer_dequeue(buff)) != NULL) { // Count words in file word_count = count_words_in_file(dequeued_file); // Log log_count(data, dequeued_file, word_count); // Free buffer holding the file name free(dequeued_file); } return NULL; }
int raft_get_log_count(raft_server_t* me_) { raft_server_private_t* me = (raft_server_private_t*)me_; return log_count(me->log); }
int log_get_current_idx(log_t* me_) { log_private_t* me = (log_private_t*)me_; return log_count(me_) + me->base; }