/* ============================================================================= * reservation_updatePrice * -- Failure if 'price' < 0 * -- Returns TRUE on success, else FALSE * ============================================================================= */ bool_t reservation_stm::reservation_updatePrice (TM_ARGDECL reservation_t* reservationPtr, long newPrice) { if (newPrice < 0) { return FALSE; } SLOW_PATH_SHARED_WRITE(reservationPtr->price, newPrice); CHECK_RESERVATION(reservationPtr); return TRUE; }
/* ============================================================================= * reservation_updatePrice * -- Failure if 'price' < 0 * -- Returns TRUE on success, else FALSE * ============================================================================= */ bool_t reservation_updatePrice (TM_ARGDECL reservation_t* reservationPtr, int newPrice) { #ifdef reservation2 return reservationPtr->reservation_update_price(TM_ARG newPrice); #else if (newPrice < 0) { return FALSE; } TM_SHARED_WRITE(reservationPtr->price, newPrice); CHECK_RESERVATION(reservationPtr); return TRUE; #endif }
/* ============================================================================= * reservation_make * -- Returns TRUE on success, else FALSE * ============================================================================= */ bool_t reservation_stm::reservation_make (TM_ARGDECL reservation_t* reservationPtr) { long numFree = (long)SLOW_PATH_SHARED_READ(reservationPtr->numFree); if (numFree < 1) { return FALSE; } SLOW_PATH_SHARED_WRITE(reservationPtr->numUsed, ((long)SLOW_PATH_SHARED_READ(reservationPtr->numUsed) + 1)); SLOW_PATH_SHARED_WRITE(reservationPtr->numFree, (numFree - 1)); CHECK_RESERVATION(reservationPtr); return TRUE; }
/* ============================================================================= * reservation_addToTotal * -- Adds if 'num' > 0, removes if 'num' < 0; * -- Returns TRUE on success, else FALSE * ============================================================================= */ bool_t reservation_stm::reservation_addToTotal (TM_ARGDECL reservation_t* reservationPtr, long num) { long numFree = (long)SLOW_PATH_SHARED_READ(reservationPtr->numFree); if (numFree + num < 0) { return FALSE; } SLOW_PATH_SHARED_WRITE(reservationPtr->numFree, (numFree + num)); SLOW_PATH_SHARED_WRITE(reservationPtr->numTotal, ((long)SLOW_PATH_SHARED_READ(reservationPtr->numTotal) + num)); CHECK_RESERVATION(reservationPtr); return TRUE; }
/* ============================================================================= * reservation_alloc * -- Returns NULL on failure * ============================================================================= */ reservation_t* reservation_stm::reservation_alloc (TM_ARGDECL long id, long numTotal, long price) { reservation_t* reservationPtr; reservationPtr = (reservation_t*)TM_MALLOC(sizeof(reservation_t)); if (reservationPtr != NULL) { reservationPtr->id = id; reservationPtr->numUsed = 0; reservationPtr->numFree = numTotal; reservationPtr->numTotal = numTotal; reservationPtr->price = price; CHECK_RESERVATION(reservationPtr); } return reservationPtr; }
/* ============================================================================= * reservation_addToTotal * -- Adds if 'num' > 0, removes if 'num' < 0; * -- Returns TRUE on success, else FALSE * ============================================================================= */ bool_t reservation_addToTotal (TM_ARGDECL reservation_t* reservationPtr, int num) { #ifdef reservation2 return reservationPtr->reservation_addToTotal(TM_ARG num); #else int numFree = TM_SHARED_READ(reservationPtr->numFree); if (numFree + num < 0) { return FALSE; } int numTotal = TM_SHARED_READ(reservationPtr->numTotal); TM_SHARED_WRITE(reservationPtr->numTotal, numTotal + num); TM_SHARED_WRITE(reservationPtr->numFree, numFree + num); CHECK_RESERVATION(reservationPtr); return TRUE; #endif }
/* ============================================================================= * reservation_cancel * -- Returns TRUE on success, else FALSE * ============================================================================= */ bool_t reservation_cancel (TM_ARGDECL reservation_t* reservationPtr) { #ifdef reservation2 return reservationPtr->reservation_cancel(TM_ARG_ALONE); #else int numUsed = TM_SHARED_READ(reservationPtr->numUsed); if (numUsed < 1) { return FALSE; } TM_SHARED_WRITE(reservationPtr->numUsed, numUsed-1); TM_SHARED_WRITE(reservationPtr->numFree, TM_SHARED_READ(reservationPtr->numFree)+1); CHECK_RESERVATION(reservationPtr); return TRUE; #endif }