|
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/kernel/batchProcessor.h#2 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef BATCHPROCESSOR_H
|
|
Packit Service |
310c69 |
#define BATCHPROCESSOR_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "kernelTypes.h"
|
|
Packit Service |
310c69 |
#include "util/funnelQueue.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Control data for managing collections of objects to be operated on
|
|
Packit Service |
310c69 |
* by a specified function. May be used when the work function is
|
|
Packit Service |
310c69 |
* lightweight enough or cache-contentious enough that it makes sense
|
|
Packit Service |
310c69 |
* to try to accumulate multiple objects and operate on them all at
|
|
Packit Service |
310c69 |
* once in one thread.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* The work function is run in one of the kernel layer's "CPU queues",
|
|
Packit Service |
310c69 |
* and care is taken to ensure that only one invocation can be running
|
|
Packit Service |
310c69 |
* or scheduled at any given time. It can loop calling nextBatchItem
|
|
Packit Service |
310c69 |
* repeatedly until there are no more objects to operate on. It should
|
|
Packit Service |
310c69 |
* also call condReschedBatchProcessor now and then, to play nicely
|
|
Packit Service |
310c69 |
* with the OS scheduler.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* Objects to operate on are manipulated through a FunnelQueueEntry
|
|
Packit Service |
310c69 |
* object which must be contained within them.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef struct batchProcessor BatchProcessor;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef void (*BatchProcessorCallback)(BatchProcessor *batch, void *closure);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Creates a batch-processor control structure.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] layer The kernel layer data, used to enqueue work items
|
|
Packit Service |
310c69 |
* @param [in] callback A function to process the accumulated objects
|
|
Packit Service |
310c69 |
* @param [in] closure A private data pointer for use by the callback
|
|
Packit Service |
310c69 |
* @param [out] batchPtr Where to store the pointer to the new object
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int makeBatchProcessor(KernelLayer *layer,
|
|
Packit Service |
310c69 |
BatchProcessorCallback callback,
|
|
Packit Service |
310c69 |
void *closure,
|
|
Packit Service |
310c69 |
BatchProcessor **batchPtr);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Adds an object to the processing queue.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* If the callback function is not currently running or scheduled to be run,
|
|
Packit Service |
310c69 |
* it gets queued up to run.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] batch The batch-processor data
|
|
Packit Service |
310c69 |
* @param [in] item The handle on the new object to add
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void addToBatchProcessor(BatchProcessor *batch, KvdoWorkItem *item);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Fetches the next object in the processing queue.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] batch The batch-processor data
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return An object pointer or NULL
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
KvdoWorkItem *nextBatchItem(BatchProcessor *batch)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Free the batch-processor data and null out the pointer.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in,out] batchPtr Where the BatchProcessor pointer is stored
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void freeBatchProcessor(BatchProcessor **batchPtr);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Yield control to the scheduler if the kernel has indicated that
|
|
Packit Service |
310c69 |
* other work needs to run on the current processor.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* The data structure is needed so that the spin lock can be
|
|
Packit Service |
310c69 |
* (conditionally) released and re-acquired.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] batch The batch-processor data
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void condReschedBatchProcessor(BatchProcessor *batch);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif // BATCHPROCESSOR_H
|