Files
mars-nwe/include/nwnss/include/control.h
Mario Fetka 1808464145
Some checks failed
Source release / source-package (push) Failing after 1m17s
move to new lib
2026-06-14 21:47:50 +02:00

216 lines
6.3 KiB
C

/****************************************************************************
|
| (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc.
| All Rights Reserved.
|
| This program is free software; you can redistribute it and/or
| modify it under the terms of version 2 of the GNU General Public
| License as published by the Free Software Foundation.
|
| This program is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
| GNU General Public License for more details.
|
| You should have received a copy of the GNU General Public License
| along with this program; if not, contact Novell, Inc.
|
| To contact Novell about this file by physical or electronic mail,
| you may find current contact information at www.novell.com
|
|***************************************************************************
|
| NetWare Advance File Services (NSS) Initialization module
|
|---------------------------------------------------------------------------
|
| $Author: vandana $
| $Date: 2007-05-03 23:22:53 +0530 (Thu, 03 May 2007) $
|
| $RCSfile$
| $Revision: 1967 $
|
|---------------------------------------------------------------------------
| This module is used to:
| Implements a set of generic routines for allocating structures
| that control relationships between objects:
|
| WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
|
| This header file should ONLY be used for NSS internal development.
| This includes Semantic Agents (SA) and Loadable Storage Services (LSS).
| Any other use may cause conflicts which NSS will NOT fix.
+-------------------------------------------------------------------------*/
#ifndef _CONTROL_H_
#define _CONTROL_H_
#ifndef _QUE_H_
# include <library/que.h>
#endif
#if HISTOGRAM IS_ENABLED
#ifndef _HISTOGRAM_H_
# include <include/histogram.h>
#endif
#endif
#ifndef _ALARM_H_
# include <include/alarm.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
* Implements a set of generic routines for allocating structures
* that control relationships between objects including:
* 1. Asyncio structures of various flavors
* 2. Bonds for setting up dependecies between different objects
* 3. Worker structures
* 4. Transaction control structures
* 5. Delete single block (needs to be replaced with purge log)
*/
/*
* FixFixFix6 Timer used to see if we should give resources back to
* cache. I have no idea what it should be. Right now, I'll use
* the 5 minute rule for caching: Something should be kept cache for
* at least five minutes after you have gone to the trouble to get it.
*/
#define RESOURCE_TIMEOUT MIN2TICK(5)
/*
* Common structure to both ControlStore_s and ControlBlock_s
* First two fields correspond to Buffer_s structure (see xCache.h)
*/
typedef struct ControlHead_s
{
BYTE *space; /* Allocated space for controls */
#if NSS_DEBUG IS_ENABLED
NINT number; /* For support of buffer tracking */
#endif
STKtop_t freeList; /* Free control structures */
#if NSS_DEBUG IS_ENABLED
LONG debugPhyAddress;
#endif
void (*fnFree)(void *); /* The free function */
} ControlHead_s;
/*
* Control_s is the data structure that fakes out the user structure
* and puts a pointer at the beginning of it that is used for managing
* the freeing of the data.
*/
typedef struct Control_s
{
ControlHead_s *control;
NINT userData[1];
} Control_s;
/*
* Used to manage the initial space allocated for a particular
* data structure.
*/
typedef struct ControlStore_s
{
ControlHead_s head; /* Common control header */
CIRhead_t waiting; /* Threads and FSMs waiting for a control*/
NINT total; /* Total control structures created */
NINT size; /* Size of each control structure */
voidfunc_t initFunction; /* Function for initializing newbies */
/*
* ASSERTION: a control block is either on the someFree or noFree list.
*/
DQhead_t someFree; /* ControlBlocks with free space */
DQhead_t noFree; /* ControlBlocks with no free space */
// DQhead_t permanant; /* Queue of Control Blocks permanantly
// * allocated. They are kept around to
// * do shutdown.
// */
NINT numCacheBufs; /* How many additional buffers we have added
* if it gets very high, the next block
* it permanantly added.
*/
#if HISTOGRAM IS_ENABLED
Histogram_s histogram;
#endif
} ControlStore_s;
/* used for work stats */
extern ControlStore_s WorkControl;
extern NINT PendingWork;
typedef struct WorkInst_s
{
NINT enter;
NINT exit;
NINT reuse;
NINT yield;
NINT loop;
} WorkInst_s;
extern struct WorkInst_s WorkInst;
/*
* Used for managing cache blocks that are used for allocating control
* structures. It is inteneded that the system be configured with
* some initial number of control structures of each type and then
* only if needed do we allocate more using cache buffers (we could
* use the cache buffer structure for our control structure!)
*/
typedef struct ControlBlock_s
{
ControlHead_s head; /* Common control header */
DQlink_t link; /* Queue off of store (more or busy) */
ControlStore_s *control; /* Pointer to global controller for space*/
OneShot_s alarm; /* Alarm to check if we can free. Adds
* some hysteresis to the allocation policy.
*/
NINT numAllocated; /* Number allocated; when zero we can
* release the memory back to the cache.
*/
} ControlBlock_s;
/*
* FakeControl_s is used by routines that just care about processing
* the storage, NOT what it contains.
*/
typedef struct FakeControl_s
{
ControlHead_s *control;
Link_t link;
} FakeControl_s;
#define CONTROL_FREE(_x) \
{ \
FakeControl_s *fake = STRUCT(_x, FakeControl_s, link); \
\
fake->control->fnFree(fake); \
}
STATUS CONTROL_Startup(
ControlStore_s *control,
NINT total,
NINT size,
voidfunc_t initFunction);
void CONTROL_Shutdown(ControlStore_s *control);
void *CONTROL_get(ControlStore_s *control);
void *CONTROL_getNoAlloc(ControlStore_s *control);
void *CONTROL_getNoAllocNoWait(ControlStore_s *control);
//void CONTROL_fsmGet(ControlStore_s *control, void *fsm, voidfunc_t action);
extern CIRhead_t WorkLowWaitingListHead;
#ifdef __cplusplus
}
#endif
#endif