cache.c
//DOESN'T remove the id from the dirty list, since you might supply the id by doing so in the caller via a pop preceding the call to this function
DOESN'T remove the id from the dirty list, since you might supply the id by doing so in the caller via a pop preceding the call to this function
DOESN ' T remove the id from the dirty list since you might supply the id by doing so in the caller via a pop preceding the call to this function
bool FlushBlockToServer(cache_t* hostCache, global_block_id_t id, bool close) {
    pthread_mutex_lock(hostCache->ActivityTable->lock);
    block_list_node_t* hostingNode = findBlockNodeInAccessQueue(hostCache->ActivityTable, id);
    if (!hostingNode && close) {
        pthread_mutex_unlock(hostCache->ActivityTable->lock);
        return false;
    }
    if(!hostingNode) {
        pthread_mutex_unlock(hostCache->ActivityTable->lock);
        fprintf(stderr, "Block referenced was not found to be active in the cache. Cache is likely corrupt. \n");
        return false;
    }
    else{
        block_t* blockToFlush = hostingNode->block;
        pthread_mutex_unlock(hostCache->ActivityTable->lock);
        pthread_mutex_lock(blockToFlush->lock);
        if( !blockToFlush->dirty ) {
            fprintf(stderr, "WARN: Block referenced was found to be clean in the cache. Cache is likely corrupt. \n");
        }
        else if(!pushBlockToServer(hostingNode->block)) { 
            pthread_mutex_lock(hostCache->DirtyListLock);
            addIDToIDList( &(hostCache->DirtyList), id);
            pthread_mutex_unlock(hostCache->DirtyListLock);
        }
        pthread_mutex_unlock(blockToFlush->lock);
        return true;
    }
}
bool FlushBlockToServer ( cache_t * hostCache , global_block_id_t id , bool close ) { pthread_mutex_lock ( hostCache -> ActivityTable -> lock ) ; block_list_node_t * hostingNode = findBlockNodeInAccessQueue ( hostCache -> ActivityTable , id ) ; if ( ! hostingNode && close ) { pthread_mutex_unlock ( hostCache -> ActivityTable -> lock ) ; return false ; } if ( ! hostingNode ) { pthread_mutex_unlock ( hostCache -> ActivityTable -> lock ) ; fprintf ( stderr , " \n " ) ; return false ; } else { block_t * blockToFlush = hostingNode -> block ; pthread_mutex_unlock ( hostCache -> ActivityTable -> lock ) ; pthread_mutex_lock ( blockToFlush -> lock ) ; if ( ! blockToFlush -> dirty ) { fprintf ( stderr , " \n " ) ; } else if ( ! pushBlockToServer ( hostingNode -> block ) ) { pthread_mutex_lock ( hostCache -> DirtyListLock ) ; addIDToIDList ( & ( hostCache -> DirtyList ) , id ) ; pthread_mutex_unlock ( hostCache -> DirtyListLock ) ; } pthread_mutex_unlock ( blockToFlush -> lock ) ; return true ; } }
DOESN'T remove the id from the dirty list, since you might supply the id by doing so in the caller via a pop preceding the call to this function
DOESN ' T remove the id from the dirty list since you might supply the id by doing so in the caller via a pop preceding the call to this function
///If we could meaningfully check success here we could retry in a loop //if a push fails, might as well allow a retry later