Skip to content

Commit 5307609

Browse files
committed
Use class overload of new operator to not overload the new operator of the tool.
1 parent 51fa12c commit 5307609

File tree

2 files changed

+43
-50
lines changed

2 files changed

+43
-50
lines changed

libompd/src/omp-debug.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* protze@llnl.gov
99
*/
1010
/*******************************************************************************
11-
* This implements an OMPD DLL the Intel runtime library.
11+
* This implements an OMPD DLL for the LLVM OpenMP runtime library.
1212
*/
1313

1414
#define NDEBUG 1
@@ -24,39 +24,9 @@
2424
#include <stdint.h>
2525
#include <stdio.h>
2626

27-
const ompd_callbacks_t *callbacks = NULL;
2827
ompd_target_type_sizes_t type_sizes;
2928
uint64_t ompd_state;
3029

31-
// void* operator new(std::size_t size) /*throw (std::bad_alloc)*/
32-
/*{
33-
void* res;
34-
ompd_rc_t ret = callbacks->dmemory_alloc(size, &res);
35-
if (ret==ompd_rc_ok)
36-
return res;
37-
throw std::bad_alloc();
38-
}*/
39-
// void* operator new[](std::size_t size) /*throw (std::bad_alloc)*/
40-
/*{
41-
void* res;
42-
ompd_rc_t ret = callbacks->dmemory_alloc(size, &res);
43-
if (ret==ompd_rc_ok)
44-
return res;
45-
throw std::bad_alloc();
46-
}
47-
void operator delete(void* addr) throw ()
48-
{
49-
ompd_rc_t ret = callbacks->dmemory_free(addr);
50-
if (ret!=ompd_rc_ok)
51-
throw std::bad_alloc();
52-
}
53-
void operator delete[](void* addr) throw ()
54-
{
55-
ompd_rc_t ret = callbacks->dmemory_free(addr);
56-
if (ret!=ompd_rc_ok)
57-
throw std::bad_alloc();
58-
}*/
59-
6030
/* --- OMPD functions ------------------------------------------------------- */
6131

6232
/* --- 3 Initialization ----------------------------------------------------- */

libompd/src/omp-debug.h

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@
77
* Contact: ilaguna@llnl.gov
88
* protze@llnl.gov
99
*/
10-
#ifndef SRC_OMPD_INTEL_H_
11-
#define SRC_OMPD_INTEL_H_
10+
#ifndef SRC_OMP_DEBUG_H_
11+
#define SRC_OMP_DEBUG_H_
1212

1313
#ifdef __cplusplus
1414

1515
#include <cstdlib>
16-
//#include <new>
17-
// void* operator new(std::size_t size) /*throw (std::bad_alloc)*/;
18-
// void* operator new[](std::size_t size) /*throw (std::bad_alloc)*/;
19-
// void operator delete(void* addr) throw ();
20-
// void operator delete[](void* addr) throw ();
16+
#include <new>
2117

2218
extern "C" {
2319
#endif
@@ -39,47 +35,74 @@ extern "C" {
3935
* General helper functions
4036
*/
4137
ompd_rc_t initTypeSizes(ompd_address_space_context_t *context);
42-
// uint32_t getThreadLevel(ompd_context_t *context, int t);
43-
/*int getNumberOfOMPThreads(ompd_context_t *context);
44-
uint64_t getSystemThreadID(ompd_context_t *context, int t);
45-
int64_t getOmpThreadID(ompd_context_t *context);*/
4638

4739
#ifdef __cplusplus
4840
}
49-
#endif
41+
42+
static const ompd_callbacks_t *callbacks = NULL;
43+
44+
class ompdAllocatable {
45+
public:
46+
static void *operator new(std::size_t sz) {
47+
void *res;
48+
ompd_rc_t ret = callbacks->dmemory_alloc(sz, &res);
49+
if (ret == ompd_rc_ok)
50+
return res;
51+
throw std::bad_alloc();
52+
}
53+
static void *operator new[](std::size_t sz) {
54+
void *res;
55+
ompd_rc_t ret = callbacks->dmemory_alloc(sz, &res);
56+
if (ret == ompd_rc_ok)
57+
return res;
58+
throw std::bad_alloc();
59+
}
60+
void operator delete(void *addr) throw() {
61+
ompd_rc_t ret = callbacks->dmemory_free(addr);
62+
if (ret != ompd_rc_ok)
63+
throw std::bad_alloc();
64+
}
65+
void operator delete[](void *addr) throw() {
66+
ompd_rc_t ret = callbacks->dmemory_free(addr);
67+
if (ret != ompd_rc_ok)
68+
throw std::bad_alloc();
69+
}
70+
};
5071

5172
typedef struct _ompd_address_space_context_s ompd_address_space_context_t;
5273

53-
typedef struct _ompd_process_handle_s {
74+
typedef struct _ompd_process_handle_s : public ompdAllocatable {
5475
ompd_address_space_context_t *context;
5576
} ompd_process_handle_t;
5677

57-
typedef struct _ompd_address_space_handle_s {
78+
typedef struct _ompd_address_space_handle_s : public ompdAllocatable {
5879
ompd_address_space_context_t *context;
5980
ompd_device_kind_t kind;
6081
ompd_device_identifier_t id;
6182
} ompd_address_space_handle_t;
6283

63-
typedef struct _ompd_device_handle_s {
84+
typedef struct _ompd_device_handle_s : public ompdAllocatable {
6485
ompd_address_space_handle_t *ah;
6586
ompd_address_t th; /* target handle */
6687
} ompd_device_handle_t;
6788

68-
typedef struct _ompd_thread_handle_s {
89+
typedef struct _ompd_thread_handle_s : public ompdAllocatable {
6990
ompd_address_space_handle_t *ah;
7091
ompd_address_t th; /* target handle */
7192
} ompd_thread_handle_t;
7293

73-
typedef struct _ompd_parallel_handle_s {
94+
typedef struct _ompd_parallel_handle_s : public ompdAllocatable {
7495
ompd_address_space_handle_t *ah;
7596
ompd_address_t th; /* target handle */
7697
ompd_address_t lwt; /* lwt handle */
7798
} ompd_parallel_handle_t;
7899

79-
typedef struct _ompd_task_handle_s {
100+
typedef struct _ompd_task_handle_s : public ompdAllocatable {
80101
ompd_address_space_handle_t *ah;
81102
ompd_address_t th; /* target handle */
82103
ompd_address_t lwt; /* lwt handle */
83104
} ompd_task_handle_t;
84105

85-
#endif /* SRC_OMPD_INTEL_H_ */
106+
#endif
107+
108+
#endif /* SRC_OMP_DEBUG_H_ */

0 commit comments

Comments
 (0)