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
2218extern " C" {
2319#endif
@@ -39,47 +35,74 @@ extern "C" {
3935 * General helper functions
4036 */
4137ompd_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
5172typedef 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