int push(int d) {
  int oldTop = -1, newTop = -1;

  newTop = index_malloc();
  if(newTop == 0){
    return 0;
  }else{
    INDIR(newTop,0) = d;
    pthread_mutex_lock(&m);
    oldTop = top;
    INDIR(newTop,1) = oldTop;
    top = newTop;
    pthread_mutex_unlock(&m);
    return 1;
  }
}
inline int push(int d) {
	int oldTop = -1, newTop = -1;

	newTop = index_malloc();
	if(newTop == 0){
		return 0;
	}else{
		INDIR(newTop,0) = d;

		__VERIFIER_atomic_acquire(&m);
		oldTop = top;
		INDIR(newTop,1) = oldTop;
		top = newTop; 
		__VERIFIER_atomic_release(&m);
		return 1;
	}
}
int push(int d) {
  int oldTop = -1, newTop = -1;
  
  newTop = index_malloc();
  if(newTop == 0){
    return 0;
  }else{
    INDIR(newTop,0) = d;
    while (1) {
      oldTop = top;
      INDIR(newTop,1) = oldTop;
      if(__sync_bool_compare_and_swap(&top,oldTop,newTop)){
	return 1;
      }
      
    }
  }
}
inline int push(int d) {
	int oldTop = -1, newTop = -1, casret = -1;

	newTop = index_malloc();
	if(newTop == 0){
		return 0;
	}else{
		INDIR(newTop,0) = d;
		while (1) {
			oldTop = top;
			INDIR(newTop,1) = oldTop;
			__VERIFIER_atomic_CAS(&top,oldTop,newTop,&casret);
			if(casret==1){
				return 1;
			}

		}
	}
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: olivo/BP
int push(E d) {
	WORDT_Ptr oldTop = -1, newTop = -1;
	WORDT_Ptr chTop = -1;

#if (APRED >= 1)
	__CPROVER_predicate(s.top == 0);
	__CPROVER_predicate(newTop == 0);
	__CPROVER_predicate(s.top == oldTop);
#endif

	newTop = index_malloc();
	if(newTop == WORDT_NULL){
		assume(newTop == WORDT_NULL);
		return 0;
	}else{
		assume(!(newTop == WORDT_NULL));
		INDIR(newTop,0) = d;
		while (1) {
			oldTop = s.top;
			INDIR(newTop,1) = oldTop;
			//inlining of cas
			//atomic_begin();
			if (s.top == oldTop) {
				assume(s.top == oldTop);
				atomic_begin();
					chTop = s.top;
					s.top = newTop; 
				atomic_end();
				
				//atomic_end();
				
				unsafe_assert(chTop == oldTop);
				
				return 1;
			}else{
				assume(!(s.top == oldTop));
				//atomic_end();
			}
		}
	}
}
Exemplo n.º 6
0
Arquivo: main.c Projeto: olivo/BP
int push(E d) {
	WORDT_Ptr oldTop = -1, newTop = -1;

	newTop = index_malloc();
	if(newTop == WORDT_NULL){
#ifdef USE_BRANCHING_ASSUMES
		__CPROVER_assume(newTop == WORDT_NULL);
#endif
		return 0;
	}else{
#ifdef USE_BRANCHING_ASSUMES
		__CPROVER_assume(!(newTop == WORDT_NULL));
#endif
		INDIR(newTop,0) = d;

		//__CPROVER_atomic_begin();
		oldTop = s.top;
		INDIR(newTop,1) = oldTop;
		s.top = newTop; 
		//__CPROVER_atomic_end();
		return 1;
	}
}