node_t* new_node(skey_t key, sval_t val, int initializing) { volatile node_t* node; #if GC == 1 if (unlikely(initializing)) /* for initialization AND the coupling algorithm */ { node = (volatile node_t*) ssalloc(sizeof(node_t)); } else { node = (volatile node_t*) ssmem_alloc(alloc, sizeof(node_t)); } #else node = (volatile node_t*) ssalloc(sizeof(node_t)); #endif if (node == NULL) { perror("malloc @ new_node"); exit(1); } node->key = key; node->val = val; node->left = node->right = NULL; #if defined(__tile__) /* on tilera you may have store reordering causing the pointer to a new node to become visible, before the contents of the node are visible */ MEM_BARRIER; #endif /* __tile__ */ return (node_t*) node; }
node_t* new_node(skey_t key, sval_t val, node_t *next, int initializing) { volatile node_t *node; #if GC == 1 if (unlikely(initializing)) { node = (volatile node_t *) ssalloc(sizeof(node_t)); } else { node = (volatile node_t *) ssmem_alloc(alloc, sizeof(node_t)); } #else node = (volatile node_t *) ssalloc(sizeof(node_t)); #endif if (node == NULL) { perror("malloc @ new_node"); exit(1); } node->key = key; node->val = val; node->next = next; return (node_t*) node; }
node_t* new_node(skey_t key, sval_t val, node_t* l, node_t* r, int initializing) { node_t* node; #if GC == 1 if (likely(!initializing)) /* for initialization AND the coupling algorithm */ { node = (node_t*) ssmem_alloc(alloc, sizeof(node_t)); } else { node = (node_t*) ssalloc(sizeof(node_t)); } #else node = (node_t*) ssalloc(sizeof(node_t)); #endif if (node == NULL) { perror("malloc @ new_node"); exit(1); } node->key = key; node->val = val; node->left = l; node->right = r; node->lock.to_uint64 = 0; return (node_t*) node; }
/** Setup the input buffer state to scan the given bytes. The next call to sslex() will * scan from a @e copy of @a bytes. * @param bytes the byte buffer to scan * @param len the number of bytes in the buffer pointed to by @a bytes. * * @return the newly allocated buffer state object. */ YY_BUFFER_STATE ss_scan_bytes (yyconst char * yybytes, int _yybytes_len ) { YY_BUFFER_STATE b; char *buf; yy_size_t n; int i; /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; buf = (char *) ssalloc(n ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in ss_scan_bytes()" ); for ( i = 0; i < _yybytes_len; ++i ) buf[i] = yybytes[i]; buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; b = ss_scan_buffer(buf,n ); if ( ! b ) YY_FATAL_ERROR( "bad buffer in ss_scan_bytes()" ); /* It's okay to grow etc. this buffer, and we should throw it * away when we're done. */ b->yy_is_our_buffer = 1; return b; }
/** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer * * @return the newly allocated buffer state object. */ YY_BUFFER_STATE ss_scan_buffer (char * base, yy_size_t size ) { YY_BUFFER_STATE b; if ( size < 2 || base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-1] != YY_END_OF_BUFFER_CHAR ) /* They forgot to leave room for the EOB's. */ return 0; b = (YY_BUFFER_STATE) ssalloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in ss_scan_buffer()" ); b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; b->yy_is_our_buffer = 0; b->yy_input_file = 0; b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; b->yy_at_bol = 1; b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; ss_switch_to_buffer(b ); return b; }
static chm_node_t* chm_node_new(skey_t key, sval_t val, chm_node_t* next) { volatile chm_node_t* node; #if GC == 1 node = (volatile chm_node_t*) ssmem_alloc(alloc, sizeof(chm_node_t)); #else node = (volatile chm_node_t*) ssalloc(sizeof(chm_node_t)); #endif if (node == NULL) { perror("malloc @ new_node"); exit(1); } node->key = key; node->val = val; node->next = next; #if defined(__tile__) /* on tilera you may have store reordering causing the pointer to a new node to become visible, before the contents of the node are visible */ MEM_BARRIER; #endif /* __tile__ */ return (chm_node_t*) node; }
bool_t bst_add(bst_key_t k, node_t* root, int id){ //fprintf(stderr, "bst add\n"); // node_t* pred; // node_t* curr; node_t* new_node; // operation_t* pred_op; // operation_t* curr_op; operation_t* cas_op; // search_res_t result; bst_search_result_t* my_result; while(TRUE) { //root is now a global pointer to a node, not a node my_result = bst_find(k, /*&pred, &pred_op, &curr, &curr_op, */root, root, id); if (my_result->result == FOUND) { return FALSE; } // allocate memory // new_node = new Node(k); new_node = (node_t*) ssalloc(sizeof(node_t)); new_node->key = k; new_node->op = NULL; new_node->left = NULL; new_node->right = NULL; // fprintf(stderr, "new_node address: %p, 64bit aligned: %d key address %p, left node addr: %p, right node addr: %p, op addr: %p\n", new_node, ((unsigned long)new_node & 7) == 0,&(new_node->key), &(new_node->left), &(new_node->right), &(new_node->op) // ); bool_t is_left = (my_result->result == NOT_FOUND_L); node_t* old; if (is_left) { old = my_result->curr->left; } else { old = my_result->curr->right; } // allocate memory //cas_op = new child_cas_op_t(is_left, old, new_node) cas_op = (operation_t*) ssalloc_alloc(1, sizeof(operation_t)); cas_op->child_cas_op.is_left = is_left; cas_op->child_cas_op.expected = old; cas_op->child_cas_op.update = new_node; // fprintf(stderr, "cas_op address: %p, is_left address: %p, expected addr: %p, update addr: %p\n", (unsigned long)cas_op, &(cas_op->child_cas_op.is_left), &(cas_op->child_cas_op.expected), &(cas_op->child_cas_op.update) // ); if (CAS_PTR(&(my_result->curr->op), my_result->curr_op, FLAG(cas_op, STATE_OP_CHILDCAS)) == my_result->curr_op) { // legit cast? YES!! verif bst_help_child_cas(cas_op, my_result->curr/*, root*/); return TRUE; } } }
operation_t* alloc_op() { volatile operation_t * new_op; #if GC == 1 new_op = (volatile operation_t*) ssmem_alloc(alloc, sizeof(operation_t)); #else new_op = (volatile operation_t*) ssalloc(sizeof(operation_t)); #endif if (new_op==NULL) { perror("malloc in bst create node"); exit(1); } return (operation_t*) new_op; }
/** Allocate and initialize an input buffer state. * @param file A readable stream. * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. * * @return the allocated buffer state. */ YY_BUFFER_STATE ss_create_buffer (FILE * file, int size ) { YY_BUFFER_STATE b; b = (YY_BUFFER_STATE) ssalloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in ss_create_buffer()" ); b->yy_buf_size = size; /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ b->yy_ch_buf = (char *) ssalloc(b->yy_buf_size + 2 ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in ss_create_buffer()" ); b->yy_is_our_buffer = 1; ss_init_buffer(b,file ); return b; }
int fraser_find(sl_intset_t *set, slkey_t key, val_t *val) { sl_node_t **succs; int result; /* succs = (sl_node_t **)malloc(*levelmax * sizeof(sl_node_t *)); */ succs = (sl_node_t **)ssalloc(*levelmax * sizeof(sl_node_t *)); fraser_search(set, key, NULL, succs); result = (succs[0]->key == key && !succs[0]->deleted); *val = succs[0]->val; // garbage if result = 0 /* free(succs); */ ssfree(succs); return result; }
int fraser_remove(sl_intset_t *set, slkey_t key, val_t *val, int remove_succ) { sl_node_t **succs; int result; /* succs = (sl_node_t **)malloc(*levelmax * sizeof(sl_node_t *)); */ succs = (sl_node_t **)ssalloc(*levelmax * sizeof(sl_node_t *)); fraser_search(set, key, NULL, succs); if (remove_succ) { result = (succs[0]->next[0] != NULL); // Don't remove tail key = succs[0]->key; *val = succs[0]->val; } else { result = (succs[0]->key == key); *val = succs[0]->val; } if (result == 0) goto end; /* 1. Node is logically deleted when the deleted field is not 0 */ if (succs[0]->deleted) { result = 0; goto end; } if (ATOMIC_FETCH_AND_INC_FULL(&succs[0]->deleted) == 0) { /* 2. Mark forward pointers, then search will remove the node */ mark_node_ptrs(succs[0]); /* MEM_BARRIER; */ fraser_search(set, key, NULL, NULL); } else { result = 0; } end: /* free(succs); */ ssfree(succs); return result; }
bool_t bst_add(bst_key_t k, node_t* root){ node_t* pred; node_t* curr; node_t* new_node; operation_t* pred_op; operation_t* curr_op; operation_t* cas_op; search_res_t result; while(TRUE) { result = bst_find(k, &pred, &pred_op, &curr, &curr_op, root, root); if (result == FOUND) { return FALSE; } new_node = (node_t*) ssalloc(sizeof(node_t)); new_node->key = k; new_node->op = NULL; new_node->left = NULL; new_node->right = NULL; bool_t is_left = (result == NOT_FOUND_L); node_t* old; if (is_left) { old = curr->left; } else { old = curr->right; } cas_op = (operation_t*) ssalloc_alloc(1, sizeof(operation_t)); cas_op->child_cas_op.is_left = is_left; cas_op->child_cas_op.expected = old; cas_op->child_cas_op.update = new_node; #if defined(__tile__) MEM_BARRIER; #endif if (CAS_PTR(&curr->op, curr_op, FLAG(cas_op, STATE_OP_CHILDCAS)) == curr_op) { bst_help_child_cas(cas_op, curr, root); return TRUE; } } }
queue_node_t* queue_new_node(skey_t key, sval_t val, queue_node_t* next) { #if GC == 1 queue_node_t* node = ssmem_alloc(alloc, sizeof(*node)); #else queue_node_t* node = ssalloc(sizeof(*node)); #endif node->key = key; node->val = val; node->next = next; #ifdef __tile__ MEM_BARRIER; #endif return node; }
node_t* new_node_no_init() { node_t* node; #if GC == 1 node = (node_t*) ssmem_alloc(alloc, sizeof(node_t)); #else node = (node_t*) ssalloc(sizeof(node_t)); #endif if (unlikely(node == NULL)) { perror("malloc @ new_node"); exit(1); } node->val = 0; node->lock.to_uint64 = 0; return (node_t*) node; }
node_t* create_node(skey_t k, sval_t value, int initializing) { volatile node_t* new_node; #if GC == 1 if (unlikely(initializing)) { new_node = (volatile node_t*) ssalloc_aligned(CACHE_LINE_SIZE, sizeof(node_t)); } else { new_node = (volatile node_t*) ssmem_alloc(alloc, sizeof(node_t)); } #else new_node = (volatile node_t*) ssalloc(sizeof(node_t)); #endif if (new_node == NULL) { perror("malloc in bst create node"); exit(1); } new_node->left = NULL; new_node->right = NULL; new_node->key = k; new_node->value = value; asm volatile("" ::: "memory"); return (node_t*) new_node; }
/* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ static void ssensure_buffer_stack (void) { int num_to_alloc; if (!(yy_buffer_stack)) { /* First allocation is just for 2 elements, since we don't know if this * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ num_to_alloc = 1; (yy_buffer_stack) = (struct yy_buffer_state**)ssalloc (num_to_alloc * sizeof(struct yy_buffer_state*) ); memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; (yy_buffer_stack_top) = 0; return; } if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ /* Increase the buffer to prepare for a possible push. */ int grow_size = 8 /* arbitrary grow size */; num_to_alloc = (yy_buffer_stack_max) + grow_size; (yy_buffer_stack) = (struct yy_buffer_state**)ssrealloc ((yy_buffer_stack), num_to_alloc * sizeof(struct yy_buffer_state*) ); /* zero only the new slots.*/ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; } }