FAPI TM, WLS_LIB and ODULOW documentation
[o-du/phy.git] / wls_lib / testapp / pool.h
1 /******************************************************************************
2 *
3 *   Copyright (c) 2019 Intel.
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 *
17 *******************************************************************************/
18
19 #ifndef _POOL_API_H_
20 #define _POOL_API_H_
21
22 #ifdef __KERNEL__
23 #include <linux/mutex.h>
24 #endif
25 #include <pthread.h>
26 #include "ttypes.h"
27
28
29 typedef struct _POOL_
30 {
31     unsigned char*      StoragePtr;     // The pointer to the storage where blocks are located
32     unsigned int      BlockNum;       // The number of blocks in storage
33     unsigned int      BlockSize;      // The size of block in bytes
34
35     unsigned long long*     FreePtr;        // The pointer to the storage with free object indexes
36     volatile unsigned long long     FreePut;        // PUT index used to put the new item to 'free' storage
37     volatile unsigned long long     FreeGet;        // GET index used to get the new free item from 'free' storage
38
39     unsigned long long*     UsedPtr;        // The pointer to the storage with 'Used' object indexes
40     volatile unsigned long long     UsedPut;        // PUT index used to put the new item to 'already used' storage
41     volatile unsigned long long     UsedGet;        // GET index used to get the item from 'already used' storage
42 #ifdef __KERNEL__
43     struct mutex lock;
44 #else
45     pthread_mutex_t lock;
46 #endif
47 }POOL, *PPOOL;
48
49
50 unsigned int PoolInit (PPOOL pPool, void * pStorage, unsigned int nBlockNum, unsigned int nBlockSize, unsigned long long* pFreePtr, unsigned long long* pUsedPtr);
51 void*  PoolAlloc(PPOOL pPool);
52 unsigned int PoolFree(PPOOL pPool, void * pBlock);
53 unsigned int PoolGetFreeNum(PPOOL pPool);
54 unsigned int PoolGetAllocNum(PPOOL pPool);
55
56 #endif //_POOL_API_H_