This commit is contained in:
Andy Ritger
2022-06-28 08:00:06 -07:00
parent 965db98552
commit 94eaea9726
37 changed files with 556 additions and 353 deletions

View File

@@ -33,6 +33,7 @@ extern "C" {
#include "nvtypes.h"
#include "nvmisc.h"
#include "nvport/nvport.h"
#include "utils/nvassert.h"
/**
* @defgroup NV_CONTAINERS_LIST List
@@ -190,29 +191,29 @@ struct IntrusiveList
#define listInsertNew(pList, pNext) \
CONT_CAST_ELEM(pList, \
listInsertNew_IMPL(&(pList)->real, \
CONT_CHECK_ARG(pList, pNext)))
CONT_CHECK_ARG(pList, pNext)), listIsValid_IMPL)
#define listAppendNew(pList) \
CONT_CAST_ELEM(pList, listAppendNew_IMPL(&(pList)->real))
CONT_CAST_ELEM(pList, listAppendNew_IMPL(&(pList)->real), listIsValid_IMPL)
#define listPrependNew(pList) \
CONT_CAST_ELEM(pList, listPrependNew_IMPL(&(pList)->real))
CONT_CAST_ELEM(pList, listPrependNew_IMPL(&(pList)->real), listIsValid_IMPL)
#define listInsertValue(pList, pNext, pValue) \
CONT_CAST_ELEM(pList, \
listInsertValue_IMPL(&(pList)->real, \
CONT_CHECK_ARG(pList, pNext), \
CONT_CHECK_ARG(pList, pValue)))
CONT_CHECK_ARG(pList, pValue)), listIsValid_IMPL)
#define listAppendValue(pList, pValue) \
CONT_CAST_ELEM(pList, \
listAppendValue_IMPL(&(pList)->real, \
CONT_CHECK_ARG(pList, pValue)))
CONT_CHECK_ARG(pList, pValue)), listIsValid_IMPL)
#define listPrependValue(pList, pValue) \
CONT_CAST_ELEM(pList, \
listPrependValue_IMPL(&(pList)->real, \
CONT_CHECK_ARG(pList, pValue)))
CONT_CHECK_ARG(pList, pValue)), listIsValid_IMPL)
#define listInsertExisting(pList, pNext, pValue) \
listInsertExisting_IMPL(&(pList)->real, \
@@ -249,30 +250,30 @@ struct IntrusiveList
#define listFindByValue(pList, pValue) \
CONT_CAST_ELEM(pList, \
listFindByValue_IMPL(&(pList)->real, \
CONT_CHECK_ARG(pList, pValue)))
CONT_CHECK_ARG(pList, pValue)), listIsValid_IMPL)
#define listHead(pList) \
CONT_CAST_ELEM(pList, listHead_IMPL(&((pList)->real).base))
CONT_CAST_ELEM(pList, listHead_IMPL(&((pList)->real).base), listIsValid_IMPL)
#define listTail(pList) \
CONT_CAST_ELEM(pList, listTail_IMPL(&((pList)->real).base))
CONT_CAST_ELEM(pList, listTail_IMPL(&((pList)->real).base), listIsValid_IMPL)
#define listNext(pList, pValue) \
CONT_CAST_ELEM(pList, \
listNext_IMPL(&((pList)->real).base, \
CONT_CHECK_ARG(pList, pValue)))
CONT_CHECK_ARG(pList, pValue)), listIsValid_IMPL)
#define listPrev(pList, pValue) \
CONT_CAST_ELEM(pList, \
listPrev_IMPL(&((pList)->real).base, \
CONT_CHECK_ARG(pList, pValue)))
CONT_CHECK_ARG(pList, pValue)), listIsValid_IMPL)
#define listIterAll(pList) \
listIterRange(pList, listHead(pList), listTail(pList))
#define listIterRange(pList, pFirst, pLast) \
CONT_ITER_RANGE(pList, &listIterRange_IMPL, \
CONT_CHECK_ARG(pList, pFirst), CONT_CHECK_ARG(pList, pLast))
CONT_CHECK_ARG(pList, pFirst), CONT_CHECK_ARG(pList, pLast), listIsValid_IMPL)
#define listIterNext(pIt) \
listIterNext_IMPL(&((pIt)->iter))
@@ -324,6 +325,8 @@ listNodeToValue(ListBase *pList, ListNode *pNode)
return (NvU8*)pNode - pList->nodeOffset;
}
NvBool listIsValid_IMPL(void *pMap);
#ifdef __cplusplus
}
#endif

View File

@@ -192,12 +192,12 @@ struct IntrusiveMap
mapKey_IMPL(&((pMap)->real).base, pValue)
#define mapInsertNew(pMap, key) \
CONT_CAST_ELEM(pMap, mapInsertNew_IMPL(&(pMap)->real, key))
CONT_CAST_ELEM(pMap, mapInsertNew_IMPL(&(pMap)->real, key), mapIsValid_IMPL)
#define mapInsertValue(pMap, key, pValue) \
CONT_CAST_ELEM(pMap, \
mapInsertValue_IMPL(&(pMap)->real, key, \
CONT_CHECK_ARG(pMap, pValue)))
CONT_CHECK_ARG(pMap, pValue)), mapIsValid_IMPL)
#define mapInsertExisting(pMap, key, pValue) \
mapInsertExisting_IMPL(&(pMap)->real, key, \
@@ -221,32 +221,32 @@ struct IntrusiveMap
contDispatchVoid_STUB())
#define mapFind(pMap, key) \
CONT_CAST_ELEM(pMap, mapFind_IMPL(&((pMap)->real).base, key))
CONT_CAST_ELEM(pMap, mapFind_IMPL(&((pMap)->real).base, key), mapIsValid_IMPL)
#define mapFindGEQ(pMap, keyMin) \
CONT_CAST_ELEM(pMap, \
mapFindGEQ_IMPL(&((pMap)->real).base, keyMin))
mapFindGEQ_IMPL(&((pMap)->real).base, keyMin), mapIsValid_IMPL)
#define mapFindLEQ(pMap, keyMax) \
CONT_CAST_ELEM(pMap, \
mapFindLEQ_IMPL(&((pMap)->real).base, keyMax))
mapFindLEQ_IMPL(&((pMap)->real).base, keyMax), mapIsValid_IMPL)
#define mapNext(pMap, pValue) \
CONT_CAST_ELEM(pMap, \
mapNext_IMPL(&((pMap)->real).base, \
CONT_CHECK_ARG(pMap, pValue)))
CONT_CHECK_ARG(pMap, pValue)), mapIsValid_IMPL)
#define mapPrev(pMap, pValue) \
CONT_CAST_ELEM(pMap, \
mapPrev_IMPL(&((pMap)->real).base, \
CONT_CHECK_ARG(pMap, pValue)))
CONT_CHECK_ARG(pMap, pValue)), mapIsValid_IMPL)
#define mapIterAll(pMap) \
mapIterRange(pMap, mapFindGEQ(pMap, 0), mapFindLEQ(pMap, NV_U64_MAX))
#define mapIterRange(pMap, pFirst, pLast) \
CONT_ITER_RANGE(pMap, &mapIterRange_IMPL, \
CONT_CHECK_ARG(pMap, pFirst), CONT_CHECK_ARG(pMap, pLast))
CONT_CHECK_ARG(pMap, pFirst), CONT_CHECK_ARG(pMap, pLast), mapIsValid_IMPL)
#define mapIterNext(pIt) \
mapIterNext_IMPL(&((pIt)->iter))
@@ -293,6 +293,8 @@ mapNodeToValue(MapBase *pMap, MapNode *pNode)
return (NvU8*)pNode - pMap->nodeOffset;
}
NvBool mapIsValid_IMPL(void *pMap);
#ifdef __cplusplus
}
#endif

View File

@@ -157,35 +157,35 @@ struct MultimapBase
#define multimapFindSubmap(pMultimap, submapKey) \
CONT_CAST_ELEM(&(pMultimap)->type.map, \
multimapFindSubmap_IMPL(&(pMultimap)->real.base, submapKey))
multimapFindSubmap_IMPL(&(pMultimap)->real.base, submapKey), multimapIsValid_IMPL)
#define multimapFindSubmapLEQ(pMultimap, submapKey) \
CONT_CAST_ELEM(&(pMultimap)->type.map, \
multimapFindSubmapLEQ_IMPL(&(pMultimap)->real.base, submapKey))
multimapFindSubmapLEQ_IMPL(&(pMultimap)->real.base, submapKey), multimapIsValid_IMPL)
#define multimapFindSubmapGEQ(pMultimap, submapKey) \
CONT_CAST_ELEM(&(pMultimap)->type.map, \
multimapFindSubmapGEQ_IMPL(&(pMultimap)->real.base, submapKey))
multimapFindSubmapGEQ_IMPL(&(pMultimap)->real.base, submapKey), multimapIsValid_IMPL)
#define multimapCountSubmapItems(pMultimap, pSubmap) \
mapCount(pSubmap)
#define multimapInsertItemNew(pMultimap, submapKey, itemKey) \
CONT_CAST_ELEM(pMultimap, \
multimapInsertItemNew_IMPL(&(pMultimap)->real.base, submapKey, itemKey))
multimapInsertItemNew_IMPL(&(pMultimap)->real.base, submapKey, itemKey), multimapIsValid_IMPL)
#define multimapInsertItemValue(pMultimap, submapKey, itemKey, pValue) \
CONT_CAST_ELEM(pMultimap, \
multimapInsertItemValue_IMPL(&(pMultimap)->real.base, \
submapKey, itemKey, pValue))
submapKey, itemKey, pValue), multimapIsValid_IMPL)
#define multimapInsertSubmap(pMultimap, submapKey) \
CONT_CAST_ELEM(&(pMultimap)->type.map, \
multimapInsertSubmap_IMPL(&(pMultimap)->real.base, submapKey))
multimapInsertSubmap_IMPL(&(pMultimap)->real.base, submapKey), multimapIsValid_IMPL)
#define multimapFindItem(pMultimap, submapKey, itemKey) \
CONT_CAST_ELEM(pMultimap, \
multimapFindItem_IMPL(&(pMultimap)->real.base, submapKey, itemKey))
multimapFindItem_IMPL(&(pMultimap)->real.base, submapKey, itemKey), multimapIsValid_IMPL)
#define multimapRemoveItem(pMultimap, pValue) \
multimapRemoveItem_IMPL(&(pMultimap)->real.base, pValue)
@@ -198,17 +198,17 @@ struct MultimapBase
#define multimapNextItem(pMultimap, pValue) \
CONT_CAST_ELEM(pMultimap, \
multimapNextItem_IMPL(&(pMultimap)->real.base, pValue))
multimapNextItem_IMPL(&(pMultimap)->real.base, pValue), multimapIsValid_IMPL)
#define multimapPrevItem(pMultimap, pValue) \
CONT_CAST_ELEM(pMultimap, \
multimapPrevItem_IMPL(&(pMultimap)->real.base, pValue))
multimapPrevItem_IMPL(&(pMultimap)->real.base, pValue), multimapIsValid_IMPL)
#define multimapFirstItem(pMultimap) \
CONT_CAST_ELEM(pMultimap, multimapFirstItem_IMPL(&(pMultimap)->real.base))
CONT_CAST_ELEM(pMultimap, multimapFirstItem_IMPL(&(pMultimap)->real.base), multimapIsValid_IMPL)
#define multimapLastItem(pMultimap) \
CONT_CAST_ELEM(pMultimap, multimapLastItem_IMPL(&(pMultimap)->real.base))
CONT_CAST_ELEM(pMultimap, multimapLastItem_IMPL(&(pMultimap)->real.base), multimapIsValid_IMPL)
#define multimapItemIterAll(pMultimap) \
multimapItemIterRange(pMultimap, \
@@ -216,7 +216,7 @@ struct MultimapBase
#define multimapItemIterRange(pMultimap, pFirst, pLast) \
CONT_ITER_RANGE(pMultimap, multimapItemIterRange_IMPL, \
CONT_CHECK_ARG(pMultimap, pFirst), CONT_CHECK_ARG(pMultimap, pLast))
CONT_CHECK_ARG(pMultimap, pFirst), CONT_CHECK_ARG(pMultimap, pLast), multimapIsValid_IMPL)
#define multimapSubmapIterItems(pMultimap, pSubmap) \
multimapItemIterRange(pMultimap, \
@@ -289,6 +289,9 @@ multimapNodeToValue(MultimapBase *pBase, MultimapNode *pNode)
return (NvU8*)pNode - pBase->multimapNodeOffset;
}
NvBool multimapIsValid_IMPL(void *pMap);
#ifdef __cplusplus
}
#endif

View File

@@ -107,7 +107,7 @@ typedef enum
CONT_CHECK_ARG(pQueue, pElements), numElements)
#define queuePeek(pQueue) \
CONT_CAST_ELEM(pQueue, circularQueuePeek_IMPL(&((pQueue)->real)))
CONT_CAST_ELEM(pQueue, circularQueuePeek_IMPL(&((pQueue)->real)), circularQueueIsValid_IMPL)
#define queuePop(pQueue) \
circularQueuePop_IMPL(&((pQueue)->real))
@@ -136,6 +136,9 @@ void circularQueuePop_IMPL(Queue *pQueue);
NvBool circularQueuePopAndCopy_IMPL(Queue *pQueue, void *pCopyTo);
NvBool circularQueuePopAndCopyNonManaged_IMPL(Queue *pQueue, QueueContext *pCtx,
void *pCopyTo);
NvBool circularQueueIsValid_IMPL(void *pQueue);
#ifdef __cplusplus
}
#endif

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2015-2015 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-FileCopyrightText: Copyright (c) 2015-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -103,7 +103,7 @@ typename T::ElemType *CONT_CHECK_ARG(T *pCont, typename T::ElemType *pValue)
}
template <class T>
typename T::ElemType *CONT_CAST_ELEM(T *pCont, void *pValue)
typename T::ElemType *CONT_CAST_ELEM(T *pCont, void *pValue, ...)
{
return (typename T::ElemType *)pValue;
}
@@ -114,7 +114,8 @@ typename T::IterType CONT_ITER_RANGE
T *pCont,
It (*pFunc)(typename T::ContType *, void *, void *),
void *pFirst,
void *pLast
void *pLast,
...
)
{
typename T::IterType temp;
@@ -128,7 +129,8 @@ typename T::IterType CONT_ITER_RANGE_INDEX
T *pCont,
It (*pFunc)(typename T::ContType *, NvU64, NvU64),
NvU64 first,
NvU64 last
NvU64 last,
...
)
{
typename T::IterType temp;
@@ -155,31 +157,42 @@ typename T::IterType CONT_ITER_RANGE_INDEX
//
#if NV_TYPEOF_SUPPORTED
#define CONT_CAST_ELEM(pCont, ret) ((typeof((pCont)->elem))(ret))
#define CONT_CAST_ELEM(pCont, ret, validfunc) ((typeof((pCont)->elem))(ret))
//
// The dummy contId prevents compilers from warning about incompatible
// function casts. This is safe since we know the two return structures
// are identical (modulo alpha-conversion).
//
#define CONT_ITER_RANGE(pCont, pFunc, pFirst, pLast) \
#define CONT_ITER_RANGE(pCont, pFunc, pFirst, pLast, validfunc) \
(((typeof(*(pCont)->iter)(*)(void *, void *, void *))contId(pFunc))( \
pCont, pFirst, pLast))
#define CONT_ITER_RANGE_INDEX(pCont, pFunc, first, last) \
#define CONT_ITER_RANGE_INDEX(pCont, pFunc, first, last, validfunc) \
(((typeof(*(pCont)->iter)(*)(void *, NvU64, NvU64))contId(pFunc))( \
pCont, first, last))
#else
#define CONT_CAST_ELEM(pCont, ret) ((pCont)->vtable->checkRet(ret))
// Actual implementations
#define CONT_CAST_ELEM2(pCont, ret) ((pCont)->vtable->checkRet(ret))
#define CONT_ITER_RANGE(pCont, pFunc, pFirst, pLast) \
#define CONT_ITER_RANGE2(pCont, pFunc, pFirst, pLast) \
((pCont)->vtable->iterRange(&(pCont)->real.base, pFirst, pLast))
#define CONT_ITER_RANGE_RANGE(pCont, pFunc, first, last) \
#define CONT_ITER_RANGE_RANGE2(pCont, pFunc, first, last) \
((pCont)->vtable->iterRangeIndex(&(pCont)->real.base, first, last))
// Calls validfunc() first to initialize vtable
#define CONT_CAST_ELEM(pCont, ret, validfunc) \
(validfunc((pCont)) ? CONT_CAST_ELEM2(pCont, ret) : CONT_CAST_ELEM2(pCont, NULL))
#define CONT_ITER_RANGE(pCont, pFunc, pFirst, pLast, validfunc) \
(validfunc((pCont)) ? CONT_ITER_RANGE2(pCont, pFunc, pFirst, pLast) : CONT_ITER_RANGE2(pCont, NULL, NULL, NULL))
#define CONT_ITER_RANGE_INDEX(pCont, pFunc, first, last, validfunc) \
(validfunc((pCont)) ? CONT_ITER_RANGE_INDEX2(pCont, pFunc, first, last) : CONT_ITER_RANGE_INDEX2(pCont, NULL, 0, 0))
#endif
#endif
@@ -223,6 +236,8 @@ typename T::IterType CONT_ITER_RANGE_INDEX
#define CONT_VTABLE_INIT(contType, pCont) \
((pCont)->vtable = &g_##contType##_VTABLE)
#define CONT_VTABLE_VALID(pCont) ((pCont)->vtable != NULL)
#endif
enum CONT_KIND