示例#1
0
/*
 * [lyj] Disable the interpretation of "deleted" field.
 */
void fraser_insert(sl_intset_t *set, uint32_t v, bool lin)
{
    sl_node_t *NEW, *new_next, *pred, *succ, *succs[LEVELMAX], *preds[LEVELMAX];
    uint32_t i;
    uint32_t status;
   // uint32_t attempts = 0;
    NEW = sl_new_simple_node(v, get_rand_level(), lin);
retry:
    fraser_search(set, v, preds, succs);
    for (i = 0; i < NEW->toplevel; i++)
        NEW->nexts[i] = succs[i];
    /* Node is visible once inserted at lowest level */
    if (!ATOMIC_CAS_MB(&preds[0]->nexts[0], succs[0], NEW))
        goto retry;
    
//retry_HTM:
    status = _xbegin();
    if(status == _XBEGIN_STARTED)
    {
        for (i = 1; i < NEW->toplevel; i++) {
            if(preds[i]->nexts[i] == succs[i])
                preds[i]->nexts[i] = NEW;
            else
                _xabort(66);
        }
        _xend();
        return;
    }/*else
    {
        if ((status & _XABORT_EXPLICIT) && _XABORT_CODE(status) == 66) {
        }
        else if (++attempts < MAX_ATTEMPT_NUM) {
            goto retry_HTM;
        }
    }*/
    
    for (i = 1; i < NEW->toplevel; i++) {
        while (1) {
            pred = preds[i];
            succ = succs[i];
            /* Update the forward pointer if it is stale */
            new_next = NEW->nexts[i];
            if ((new_next != succ) &&
                (!ATOMIC_CAS_MB(&NEW->nexts[i], unset_mark((uint32_t)new_next), succ)))
                break;
            /* Give up if pointer is marked */
            /* We retry the search if the CAS fails */
            if (ATOMIC_CAS_MB(&pred->nexts[i], succ, NEW))
                break;
            fraser_search(set, v, preds, succs);
        }
    }
}
示例#2
0
/*
 * [lyj] Disable the modification of the "deleted" field.
 */
int fraser_remove(sl_intset_t *set, uint32_t val)
{
    sl_node_t *succs[LEVELMAX];
    fraser_search(set, val, NULL, succs);
    if (succs[0]->val == val) {
        /* Mark forward pointers, then search will remove the node */
        int iMarkIt = mark_node_ptrs(succs[0]);
        fraser_search(set, val, NULL, NULL);
        if (iMarkIt)
            sl_delete_node(succs[0]);
        return iMarkIt;
    }
    return 0;
}
示例#3
0
  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;
}
示例#4
0
sval_t
fraser_remove(sl_intset_t *set, skey_t key)
{
  UPDATE_TRY();

  sl_node_t* succs[FRASER_MAX_MAX_LEVEL];
  sval_t result = 0;

  PARSE_START_TS(2);
  int found = fraser_search_no_cleanup_succs(set, key, succs);
  PARSE_END_TS(2, lat_parsing_rem++);

  if (!found)
    {
      return false;
    }

  sl_node_t* node_del = succs[0];
  int my_delete = mark_node_ptrs(node_del);

  if (my_delete)
    {
      result = node_del->val;
      fraser_search(set, key, NULL, NULL);
#if GC == 1
      ssmem_free(alloc, (void*) succs[0]);
#endif
    }
  return result;
}
示例#5
0
int fraser_find(sl_intset_t *set, val_t val) {
  sl_node_t **succs;
  int result;

  succs = (sl_node_t **)malloc(levelmax * sizeof(sl_node_t *));
  fraser_search(set, val, NULL, succs);
  result = (succs[0]->val == val && !succs[0]->deleted);
  free(succs);
  return result;
}
示例#6
0
int fraser_remove(sl_intset_t *set, val_t val) {
  sl_node_t **succs;
  int result;

  succs = (sl_node_t **)malloc(levelmax * sizeof(sl_node_t *));
  fraser_search(set, val, NULL, succs);
  result = (succs[0]->val == 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;
  }
  ATOMIC_FETCH_AND_INC_FULL(&succs[0]->deleted);
  /* 2. Mark forward pointers, then search will remove the node */
  mark_node_ptrs(succs[0]);
  fraser_search(set, val, NULL, NULL);    
end:
  free(succs);

  return result;
}
示例#7
0
int fraser_find(sl_intset_t *set, val_t val) {
  sl_node_t **succs;
  int result;

#ifdef DEBUG
  printf("++> fraser_find\n");
  IO_FLUSH;
#endif

  succs = (sl_node_t **)malloc(levelmax * sizeof(sl_node_t *));
  fraser_search(set, val, NULL, succs);
  result = (succs[0]->val == val && !succs[0]->deleted);
  free(succs);
  return result;
}
示例#8
0
  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;
}
示例#9
0
sval_t
prioritySL_deleteMin(sl_intset_t *set)
{
  sval_t result = 0;
  sl_node_t *node;
  PARSE_START_TS(4);
  node = GET_UNMARKED(set->head->next[0]);
  while(node->next[0]!=NULL)
  {
    if (!IS_MARKED(node->next[node->toplevel-1]))
    {
      int my_delete = mark_node_ptrs(node);
      if (my_delete)
      {
        result = node->val;
        fraser_search(set, node->key, NULL, NULL);
        break;
      }
    }
    node = GET_UNMARKED(node->next[0]);
  }
  PARSE_END_TS(4, lat_parsing_cleaner++);
  return result;
}
示例#10
0
int naive_delete_min(sl_intset_t *set, val_t *val, thread_data_t *d) {
  sl_node_t *first;
  int result;

  first = set->head;

  while(1) {
    do {
      first = (sl_node_t*)unset_mark((uintptr_t)first->next[0]);
    } while(first->next[0] && first->deleted);
   if (ATOMIC_FETCH_AND_INC_FULL(&first->deleted) != 0) {
     d->nb_collisions++;
   } else {
     break;
   }
  }

  result = (first->next[0] != NULL);
  if (!result) {
    return 1;
  }
  
  *val = (first->val);
  mark_node_ptrs(first);

  // unsigned int *seed = &d->seed2;
  // *seed = _MarsagliaXOR(*seed);
  // if (*seed % (d->nb_threads) == 0) {
  //   fraser_search(set, first->val, NULL, NULL);    
  // }

  if (!first->next[0]->deleted)
     fraser_search(set, first->val, NULL, NULL);    

  return result; 
}