#ifndef VF_MUTEX_H
#define VF_MUTEX_H
#include "bool.h"
#include "vf_cleanup_debt.h"
struct vf_mutex;
/*@
predicate vf_mutex(struct vf_mutex *mutex ; predicate () p);
@*/
/*@
predicate vf_mutex_held(
struct vf_mutex *mutex,
predicate () p,
int threadId,
real frac);
@*/
/*@
predicate vf_mutex_create_ghost_arg(predicate() p) = true;
@*/
struct vf_mutex *vf_mutex_create();
/*@ requires
vf_mutex_create_ghost_arg(?p)
&*& p()
&*& vf_cleanup_debt(?debtCount);
@*/
/*@ ensures
result == 0 ?
p() &*& vf_cleanup_debt(debtCount)
:
vf_mutex(result, p) &*& vf_cleanup_debt(debtCount + 1);
@*/
void vf_mutex_dispose(struct vf_mutex *mutex);
//@ requires vf_mutex(mutex, ?p) &*& vf_cleanup_debt(?debtCount);
//@ ensures p() &*& vf_cleanup_debt(debtCount - 1);
void vf_mutex_lock(struct vf_mutex *mutex);
//@ requires [?frac]vf_mutex(mutex, ?p);
//@ ensures p() &*& vf_mutex_held(mutex, p, currentThread, frac);
void vf_mutex_unlock(struct vf_mutex *mutex);
//@ requires vf_mutex_held(mutex, ?p, currentThread, ?frac) &*& p();
//@ ensures [frac]vf_mutex(mutex, p);
#endif