|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/dirtyLists.h#1 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef DIRTY_LISTS_H
|
|
Packit Service |
310c69 |
#define DIRTY_LISTS_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "ringNode.h"
|
|
Packit Service |
310c69 |
#include "types.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* A collection of lists of dirty elements ordered by age. An element is always
|
|
Packit Service |
310c69 |
* placed on the oldest list in which it was dirtied (moving between lists or
|
|
Packit Service |
310c69 |
* removing altogether is cheap). Whenever the current period is advanced, any
|
|
Packit Service |
310c69 |
* elements older than the maxium age are expired. If an element is to be added
|
|
Packit Service |
310c69 |
* with a dirty age older than the maximum age, it is expired immediately.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef struct dirtyLists DirtyLists;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* A function which will be called with a ring of dirty elements which have
|
|
Packit Service |
310c69 |
* been expired. All of the expired elements must be removed from the ring
|
|
Packit Service |
310c69 |
* before this function returns.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param expired The list of expired elements
|
|
Packit Service |
310c69 |
* @param context The context for the callback
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef void DirtyCallback(RingNode *expired, void *context);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Construct a new set of dirty lists.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] maximumAge The age at which an element will be expired
|
|
Packit Service |
310c69 |
* @param [in] callback The function to call when a set of elements have
|
|
Packit Service |
310c69 |
* expired
|
|
Packit Service |
310c69 |
* @param [in] context The context for the callback
|
|
Packit Service |
310c69 |
* @param [out] dirtyListsPtr A pointer to hold the new DirtyLists
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int makeDirtyLists(BlockCount maximumAge,
|
|
Packit Service |
310c69 |
DirtyCallback *callback,
|
|
Packit Service |
310c69 |
void *context,
|
|
Packit Service |
310c69 |
DirtyLists **dirtyListsPtr)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Free a set of dirty lists and null out the pointer to them.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dirtyListsPtr A pointer to the dirty lists to be freed
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void freeDirtyLists(DirtyLists **dirtyListsPtr);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Set the current period. This function should only be called once.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dirtyLists The dirtyLists
|
|
Packit Service |
310c69 |
* @param period The current period
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void setCurrentPeriod(DirtyLists *dirtyLists, SequenceNumber period);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Add an element to the dirty lists.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dirtyLists The DirtyLists receiving the element
|
|
Packit Service |
310c69 |
* @param node The RingNode of the element to add
|
|
Packit Service |
310c69 |
* @param oldPeriod The period in which the element was previous dirtied,
|
|
Packit Service |
310c69 |
* or 0 if it was not dirty
|
|
Packit Service |
310c69 |
* @param newPeriod The period in which the element has now been dirtied,
|
|
Packit Service |
310c69 |
* or 0 if it does not hold a lock
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void addToDirtyLists(DirtyLists *dirtyLists,
|
|
Packit Service |
310c69 |
RingNode *node,
|
|
Packit Service |
310c69 |
SequenceNumber oldPeriod,
|
|
Packit Service |
310c69 |
SequenceNumber newPeriod);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Advance the current period. If the current period is greater than the number
|
|
Packit Service |
310c69 |
* of lists, expire the oldest lists.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dirtyLists The DirtyLists to advance
|
|
Packit Service |
310c69 |
* @param period The new current period
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void advancePeriod(DirtyLists *dirtyLists, SequenceNumber period);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Flush all dirty lists. This will cause the period to be advanced past the
|
|
Packit Service |
310c69 |
* current period.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dirtyLists The dirtyLists to flush
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void flushDirtyLists(DirtyLists *dirtyLists);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif // DIRTY_LISTS_H
|