Skip to content

Commit b63ea4f

Browse files
committed
Add storage stuff back to dummy handles.
1 parent 74cceed commit b63ea4f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

source/mock/ur_mock_helpers.hpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,39 @@
1313
#pragma once
1414

1515
#include "ur_api.h"
16+
1617
#include <atomic>
1718
#include <cstddef>
1819
#include <string>
1920
#include <unordered_map>
21+
#include <vector>
2022

2123
namespace mock {
2224

2325
struct dummy_handle_t_ {
24-
dummy_handle_t_() {}
25-
std::atomic<size_t> refCounter = 1;
26+
dummy_handle_t_(size_t DataSize = 0)
27+
: MStorage(DataSize), MData(MStorage.data()) {}
28+
dummy_handle_t_(unsigned char *Data) : MData(Data) {}
29+
std::atomic<size_t> MRefCounter = 1;
30+
std::vector<unsigned char> MStorage;
31+
unsigned char *MData = nullptr;
2632
};
2733

2834
using dummy_handle_t = dummy_handle_t_ *;
2935

30-
// Allocates a dummy handle of type T with support for reference counting.
31-
// The handle has to be deallocated using 'releaseDummyHandle'.
32-
template <class T> inline T createDummyHandle() {
33-
dummy_handle_t DummyHandlePtr = new dummy_handle_t_();
36+
// Allocates a dummy handle of type T with support of reference counting.
37+
// Takes optional 'Size' parameter which can be used to allocate additional
38+
// memory. The handle has to be deallocated using 'releaseDummyHandle'.
39+
template <class T> inline T createDummyHandle(size_t Size = 0) {
40+
dummy_handle_t DummyHandlePtr = new dummy_handle_t_(Size);
3441
return reinterpret_cast<T>(DummyHandlePtr);
3542
}
3643

3744
// Decrement reference counter for the handle and deallocates it if the
3845
// reference counter becomes zero
3946
template <class T> inline void releaseDummyHandle(T Handle) {
4047
auto DummyHandlePtr = reinterpret_cast<dummy_handle_t>(Handle);
41-
const size_t NewValue = --DummyHandlePtr->refCounter;
48+
const size_t NewValue = --DummyHandlePtr->MRefCounter;
4249
if (NewValue == 0) {
4350
delete DummyHandlePtr;
4451
}
@@ -47,7 +54,7 @@ template <class T> inline void releaseDummyHandle(T Handle) {
4754
// Increment reference counter for the handle
4855
template <class T> inline void retainDummyHandle(T Handle) {
4956
auto DummyHandlePtr = reinterpret_cast<dummy_handle_t>(Handle);
50-
++DummyHandlePtr->refCounter;
57+
++DummyHandlePtr->MRefCounter;
5158
}
5259

5360
struct callbacks_t {

0 commit comments

Comments
 (0)