/** Copy contents of ctg_set into std::vector. */ int copy_to_vector(std::vector<T>& items) const { int sz = size(); items.resize(sz); T* itemsPtr = &(items[0]); return(copy_to_array(sz, itemsPtr)); }
int consensus_based_tob_decided_callback(int *data, int count, int istance) { int * buffer = (int*) malloc(sizeof(int) * (count + 1)); buffer[0] = istance; copy_to_array(&buffer[1], data, count); _add_event(buffer, count + 1, _consensus_based_tob_fc_decided); return 0; }
int add_to_unordered(int id, int real_sender, int *message, int size, int handle) { unordered * d = (unordered *) malloc(sizeof(unordered)); d->rank = real_sender; d->callback_id = handle; d->id = id; d->size = size; d->message = (int*) malloc(sizeof(int) * size); copy_to_array(d->message, message, size); d->next = unordered_set->next; unordered_set->next = d; // Increasing global unordered size unordered_size++; return 0; }
/* * upon event <rbBroadcast | m> * * Given a pointer to the message array, the number of elements in the array and handle, * it packs the message, self id and the handle into a new buffer. The message is sent to the other * processes through Best Effort BroadCast */ int _consensus_based_tob_send(int *message, int count, int handle) { sprintf(log_buffer, "CONSENSUS BASED TOB INFO: Registering message \"%d\" with handle %d", message[0], handle); runtime_log(DEBUG_TOB); // Copying the message, adding CONSENSUS BASED TOB callback. int * buffer = (int*) malloc(sizeof(int) * (count + 3)); buffer[0] = handle; buffer[1] = serial_number++; buffer[2] = my_rank; copy_to_array(&buffer[3], message, count); _eager_reliable_broadcast_send(buffer, count + 3, eager_reliable_broadcast_handle); free(buffer); return 0; }
/* * upon event <cDecide |decided> */ int _consensus_based_tob_fc_decided(int *data, int size) { int res = 0; int consensus_round = ((int*) data)[0]; int set_size = size - 1; int *set = &((int*) data)[1]; sort(set, set_size); //TODO Work in Progress if (consensus_round == next_deciding_consensus_round) { perform_deliver(set, set_size); next_deciding_consensus_round++; consensus * father = consensus_set; while (father->next != NULL && father->next->round == next_deciding_consensus_round) { if (perform_deliver(father->next->decided_set, father->next->decided_set_size) == -1) res = -1; consensus * curr = father->next; father->next = father->next->next; free(curr->decided_set); free(curr); next_deciding_consensus_round++; } } else { int * new_set = (int*) malloc(sizeof(int) * set_size); copy_to_array(new_set, set, set_size); add_to_consensus_set(consensus_round, new_set, set_size); } free(data); wait = 0; if (_consensus_based_tob_new_consensus_istance() == -1) res = -1; return res; }
/* * This function is registered as callback to the Eager Realiable Broadcast subsystem. It is called when * any message is delivered by the Eager Reliable Broadcast layer for the Total Order Broadcast layer. * It posts a new event with the _consensus_based_tob_tob_deliver function as callback. */ int consensus_based_tob_rb_deliver_callback(int *data, int count, int sender) { int * buffer = (int*) malloc(sizeof(int) * count); copy_to_array(buffer, data, count); _add_event(buffer, count, _consensus_based_tob_rb_deliver); return 0; }