Node *insertPass2(int Num, int NumBlanks, int NumFAI) { Node** new_nodes = (Node**) malloc (NumFAI*sizeof(Node*)); Node* list_iter = InsertAfter->Next; for (int i=0; i < NumFAI; i++) { new_nodes[i] = createSingleNode(Num + i, NumBlanks); if (list_iter != NULL) { NVM_STR2(new_nodes[i]->Next, list_iter, sizeof(list_iter)*8); } else break; list_iter = list_iter->Next; } NVM_BEGIN_DURABLE(); for (int i=0; i < NumFAI; i++) { NVM_STR2(InsertAfter->Next, new_nodes[i], sizeof(InsertAfter->Next)*8); if (new_nodes[i]->Next != NULL) InsertAfter = new_nodes[i]->Next; else { InsertAfter = new_nodes[i]; break; } } NVM_END_DURABLE(); return InsertAfter; }
Node *insertPass1(int Num, int NumBlanks, int NumFAI) { Node *node = createSingleNode(Num, NumBlanks); // In pass 1, the new node is the last node in the list node->Next = NULL; NVM_BEGIN_DURABLE(); #ifdef _FORCE_FAIL if (Num == randval){ // printf ("num exiting is %i\n", Num); exit(0); } #endif if (!SLL) { SLL = node; InsertAfter = node; } else { InsertAfter->Next = node; InsertAfter = node; } NVM_END_DURABLE(); return node; }
void initialize() { void * rgn_root = NVM_GetRegionRoot(queue_rgn_id); if (rgn_root) { Q = (queue_t *)rgn_root; Q->head_lock = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(Q->head_lock, NULL); Q->tail_lock = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(Q->tail_lock, NULL); fprintf(stderr, "Found queue at %p\n", Q); traverse(); } else { node_t * node = #if defined(_USE_MALLOC) (node_t *) malloc(sizeof(node_t)); #else (node_t *) nvm_alloc(sizeof(node_t), queue_rgn_id); #endif assert(node); NVM_STR2(node->val, -1, sizeof(int)*8); // dummy value NVM_STR2(node->next, NULL, sizeof(node_t*)*8); #if defined(_USE_MALLOC) Q = (queue_t *) malloc(sizeof(queue_t)); #else Q = (queue_t *) nvm_alloc(sizeof(queue_t), queue_rgn_id); #endif assert(Q); fprintf(stderr, "Created Q at %p\n", Q); Q->head_lock = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(Q->head_lock, NULL); Q->tail_lock = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(Q->tail_lock, NULL); NVM_BEGIN_DURABLE(); NVM_STR2(Q->head, node, sizeof(node_t*)*8); NVM_STR2(Q->tail, node, sizeof(node_t*)*8); NVM_SetRegionRoot(queue_rgn_id, Q); NVM_END_DURABLE(); } }
Node *insertPass1(int Num, int NumBlanks, int NumFAI) { Node *node = createSingleNode(Num, NumBlanks); // In pass 1, the new node is the last node in the list NVM_STR2(node->Next, NULL, sizeof(node->Next) * 8); NVM_BEGIN_DURABLE(); if (!SLL) { NVM_STR2(SLL, node, sizeof(SLL) * 8); // write-once InsertAfter = node; } else { NVM_STR2(InsertAfter->Next, node, sizeof(InsertAfter->Next) * 8); InsertAfter = node; } NVM_END_DURABLE(); return node; }
Node *insertPass2(int Num, int NumBlanks, int NumFAI) { Node** new_nodes = (Node**) malloc (NumFAI*sizeof(Node*)); Node* list_iter = InsertAfter->Next; for (int i=0; i < NumFAI; i++) { #ifdef _FORCE_FAIL if (Num == randval){ // printf ("num exiting is %i\n", Num); exit(0); } #endif new_nodes[i] = createSingleNode(Num + i, NumBlanks); if (list_iter != NULL) { new_nodes[i]->Next = list_iter; } else break; list_iter = list_iter->Next; } // Atlas failure-atomic region NVM_BEGIN_DURABLE(); for (int i=0; i < NumFAI; i++) { InsertAfter->Next = new_nodes[i]; if (new_nodes[i]->Next != NULL) InsertAfter = new_nodes[i]->Next; else { InsertAfter = new_nodes[i]; break; } } NVM_END_DURABLE(); return InsertAfter; }