Blame source/vdo/kernel/batchProcessor.h

Packit Service cbade1
/*
Packit Service cbade1
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service cbade1
 *
Packit Service cbade1
 * This program is free software; you can redistribute it and/or
Packit Service cbade1
 * modify it under the terms of the GNU General Public License
Packit Service cbade1
 * as published by the Free Software Foundation; either version 2
Packit Service cbade1
 * of the License, or (at your option) any later version.
Packit Service cbade1
 * 
Packit Service cbade1
 * This program is distributed in the hope that it will be useful,
Packit Service cbade1
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service cbade1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service cbade1
 * GNU General Public License for more details.
Packit Service cbade1
 * 
Packit Service cbade1
 * You should have received a copy of the GNU General Public License
Packit Service cbade1
 * along with this program; if not, write to the Free Software
Packit Service cbade1
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service cbade1
 * 02110-1301, USA. 
Packit Service cbade1
 *
Packit Service cbade1
 * $Id: //eng/vdo-releases/aluminum/src/c++/vdo/kernel/batchProcessor.h#2 $
Packit Service cbade1
 */
Packit Service cbade1
Packit Service cbade1
#ifndef BATCHPROCESSOR_H
Packit Service cbade1
#define BATCHPROCESSOR_H
Packit Service cbade1
Packit Service cbade1
#include "kernelTypes.h"
Packit Service cbade1
#include "util/funnelQueue.h"
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Control data for managing collections of objects to be operated on
Packit Service cbade1
 * by a specified function. May be used when the work function is
Packit Service cbade1
 * lightweight enough or cache-contentious enough that it makes sense
Packit Service cbade1
 * to try to accumulate multiple objects and operate on them all at
Packit Service cbade1
 * once in one thread.
Packit Service cbade1
 *
Packit Service cbade1
 * The work function is run in one of the kernel layer's "CPU queues",
Packit Service cbade1
 * and care is taken to ensure that only one invocation can be running
Packit Service cbade1
 * or scheduled at any given time. It can loop calling nextBatchItem
Packit Service cbade1
 * repeatedly until there are no more objects to operate on. It should
Packit Service cbade1
 * also call condReschedBatchProcessor now and then, to play nicely
Packit Service cbade1
 * with the OS scheduler.
Packit Service cbade1
 *
Packit Service cbade1
 * Objects to operate on are manipulated through a FunnelQueueEntry
Packit Service cbade1
 * object which must be contained within them.
Packit Service cbade1
 **/
Packit Service cbade1
typedef struct batchProcessor BatchProcessor;
Packit Service cbade1
Packit Service cbade1
typedef void (*BatchProcessorCallback)(BatchProcessor *batch, void *closure);
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Creates a batch-processor control structure.
Packit Service cbade1
 *
Packit Service cbade1
 * @param [in]  layer     The kernel layer data, used to enqueue work items
Packit Service cbade1
 * @param [in]  callback  A function to process the accumulated objects
Packit Service cbade1
 * @param [in]  closure   A private data pointer for use by the callback
Packit Service cbade1
 * @param [out] batchPtr  Where to store the pointer to the new object
Packit Service cbade1
 *
Packit Service cbade1
 * @return   UDS_SUCCESS or an error code
Packit Service cbade1
 **/
Packit Service cbade1
int makeBatchProcessor(KernelLayer             *layer,
Packit Service cbade1
                       BatchProcessorCallback   callback,
Packit Service cbade1
                       void                    *closure,
Packit Service cbade1
                       BatchProcessor         **batchPtr);
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Adds an object to the processing queue.
Packit Service cbade1
 *
Packit Service cbade1
 * 

If the callback function is not currently running or scheduled to be run,

Packit Service cbade1
 * it gets queued up to run.
Packit Service cbade1
 *
Packit Service cbade1
 * @param [in] batch  The batch-processor data
Packit Service cbade1
 * @param [in] item   The handle on the new object to add
Packit Service cbade1
 **/
Packit Service cbade1
void addToBatchProcessor(BatchProcessor *batch, KvdoWorkItem *item);
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Fetches the next object in the processing queue.
Packit Service cbade1
 *
Packit Service cbade1
 * @param [in]  batch  The batch-processor data
Packit Service cbade1
 *
Packit Service cbade1
 * @return   An object pointer or NULL
Packit Service cbade1
 **/
Packit Service cbade1
KvdoWorkItem *nextBatchItem(BatchProcessor *batch)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Free the batch-processor data and null out the pointer.
Packit Service cbade1
 *
Packit Service cbade1
 * @param [in,out] batchPtr  Where the BatchProcessor pointer is stored
Packit Service cbade1
 **/
Packit Service cbade1
void freeBatchProcessor(BatchProcessor **batchPtr);
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Yield control to the scheduler if the kernel has indicated that
Packit Service cbade1
 * other work needs to run on the current processor.
Packit Service cbade1
 *
Packit Service cbade1
 * The data structure is needed so that the spin lock can be
Packit Service cbade1
 * (conditionally) released and re-acquired.
Packit Service cbade1
 *
Packit Service cbade1
 * @param [in]  batch  The batch-processor data
Packit Service cbade1
 **/
Packit Service cbade1
void condReschedBatchProcessor(BatchProcessor *batch);
Packit Service cbade1
Packit Service cbade1
#endif // BATCHPROCESSOR_H