Skip to content

Commit 5c1d82a

Browse files
Begin using qvi_new_rc() and qvi_delete(). (#89)
Signed-off-by: Samuel K. Gutierrez <[email protected]>
1 parent c8b5d8e commit 5c1d82a

File tree

3 files changed

+49
-83
lines changed

3 files changed

+49
-83
lines changed

src/qvi-bbuff.cc

+21-28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode: C++; c-basic-offset:4; indent-tabs-mode:nil -*- */
22
/*
3-
* Copyright (c) 2020-2022 Triad National Security, LLC
3+
* Copyright (c) 2020-2024 Triad National Security, LLC
44
* All rights reserved.
55
*
66
* Copyright (c) 2020-2021 Lawrence Livermore National Security, LLC
@@ -16,8 +16,10 @@
1616

1717
#include "qvi-common.h"
1818
#include "qvi-bbuff.h"
19+
#include "qvi-utils.h"
1920

2021
struct qvi_bbuff_s {
22+
int qvim_rc = QV_ERR_INTERNAL;
2123
/** Current capacity of buffer. */
2224
size_t capacity = 0;
2325
/** Amount of data already stored. */
@@ -29,45 +31,36 @@ struct qvi_bbuff_s {
2931
/** Minimum growth in bytes for resizes, etc. */
3032
min_growth = 256
3133
} constants;
34+
/** Constructor */
35+
qvi_bbuff_s(void)
36+
{
37+
capacity = min_growth;
38+
data = calloc(capacity, sizeof(byte_t));
39+
if (!data) {
40+
qvim_rc = QV_ERR_OOR;
41+
return;
42+
}
43+
qvim_rc = QV_SUCCESS;
44+
}
45+
/** Destructor */
46+
~qvi_bbuff_s(void)
47+
{
48+
if (data) free(data);
49+
}
3250
};
3351

3452
int
3553
qvi_bbuff_new(
3654
qvi_bbuff_t **buff
3755
) {
38-
int rc = QV_SUCCESS;
39-
40-
qvi_bbuff_t *ibuff = qvi_new qvi_bbuff_t();
41-
if (!ibuff) {
42-
rc = QV_ERR_OOR;
43-
goto out;
44-
}
45-
46-
ibuff->capacity = ibuff->min_growth;
47-
ibuff->data = calloc(ibuff->capacity, sizeof(byte_t));
48-
if (!ibuff->data) {
49-
rc = QV_ERR_OOR;
50-
goto out;
51-
}
52-
out:
53-
if (rc != QV_SUCCESS) {
54-
qvi_bbuff_free(&ibuff);
55-
}
56-
*buff = ibuff;
57-
return rc;
56+
return qvi_new_rc(buff);
5857
}
5958

6059
void
6160
qvi_bbuff_free(
6261
qvi_bbuff_t **buff
6362
) {
64-
if (!buff) return;
65-
qvi_bbuff_t *ibuff = *buff;
66-
if (!ibuff) goto out;
67-
if (ibuff->data) free(ibuff->data);
68-
delete ibuff;
69-
out:
70-
*buff = nullptr;
63+
qvi_delete(buff);
7164
}
7265

7366
void *

src/qvi-bind.cc

+20-38
Original file line numberDiff line numberDiff line change
@@ -16,61 +16,43 @@
1616

1717
#include "qvi-common.h" // IWYU pragma: keep
1818
#include "qvi-bind.h"
19+
#include "qvi-utils.h"
1920

2021
using qvi_bind_bitmap_stack_t = std::stack<hwloc_cpuset_t>;
2122

2223
// Type definition
2324
struct qvi_bind_stack_s {
25+
int qvim_rc = QV_SUCCESS;
2426
/** Initialized task instance. */
2527
qvi_task_t *task = nullptr;
2628
/** Client RMI instance. */
2729
qvi_rmi_client_t *rmi = nullptr;
2830
/** The bind stack. */
29-
qvi_bind_bitmap_stack_t *stack = nullptr;
31+
qvi_bind_bitmap_stack_t stack;
32+
/** Constructor */
33+
qvi_bind_stack_s(void) = default;
34+
/** Destructor */
35+
~qvi_bind_stack_s(void)
36+
{
37+
while (!stack.empty()) {
38+
hwloc_bitmap_free(stack.top());
39+
stack.pop();
40+
}
41+
}
3042
};
3143

3244
int
3345
qvi_bind_stack_new(
3446
qvi_bind_stack_t **bstack
3547
) {
36-
int rc = QV_SUCCESS;
37-
38-
qvi_bind_stack_t *ibstack = qvi_new qvi_bind_stack_t();
39-
if (!ibstack) {
40-
rc = QV_ERR_OOR;
41-
goto out;
42-
}
43-
44-
ibstack->stack = qvi_new qvi_bind_bitmap_stack_t();
45-
if (!ibstack->stack) {
46-
rc = QV_ERR_OOR;
47-
}
48-
out:
49-
if (rc != QV_SUCCESS) {
50-
qvi_bind_stack_free(&ibstack);
51-
}
52-
*bstack = ibstack;
53-
return rc;
48+
return qvi_new_rc(bstack);
5449
}
5550

5651
void
5752
qvi_bind_stack_free(
5853
qvi_bind_stack_t **bstack
5954
) {
60-
if (!bstack) return;
61-
qvi_bind_stack_t *ibstack = *bstack;
62-
if (!ibstack) goto out;
63-
if (ibstack->stack) {
64-
while (!ibstack->stack->empty()) {
65-
hwloc_cpuset_t bitm = ibstack->stack->top();
66-
hwloc_bitmap_free(bitm);
67-
ibstack->stack->pop();
68-
}
69-
}
70-
delete ibstack->stack;
71-
delete ibstack;
72-
out:
73-
*bstack = nullptr;
55+
qvi_delete(bstack);
7456
}
7557

7658
int
@@ -91,7 +73,7 @@ qvi_bind_stack_init(
9173
);
9274
if (rc != QV_SUCCESS) goto out;
9375

94-
bstack->stack->push(current_bind);
76+
bstack->stack.push(current_bind);
9577
out:
9678
if (rc != QV_SUCCESS) {
9779
hwloc_bitmap_free(current_bind);
@@ -119,7 +101,7 @@ qvi_bind_push(
119101
);
120102
if (rc != QV_SUCCESS) goto out;
121103
// Push bitmap onto stack.
122-
bstack->stack->push(bitmap_copy);
104+
bstack->stack.push(bitmap_copy);
123105
out:
124106
if (rc != QV_SUCCESS) {
125107
hwloc_bitmap_free(bitmap_copy);
@@ -131,13 +113,13 @@ int
131113
qvi_bind_pop(
132114
qvi_bind_stack_t *bstack
133115
) {
134-
hwloc_bitmap_free(bstack->stack->top());
135-
bstack->stack->pop();
116+
hwloc_bitmap_free(bstack->stack.top());
117+
bstack->stack.pop();
136118

137119
return qvi_rmi_task_set_cpubind_from_cpuset(
138120
bstack->rmi,
139121
qvi_task_task_id(bstack->task),
140-
bstack->stack->top()
122+
bstack->stack.top()
141123
);
142124
}
143125

src/qvi-task.cc

+8-17
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,36 @@
1616

1717
#include "qvi-common.h" // IWYU pragma: keep
1818
#include "qvi-task.h"
19+
#include "qvi-utils.h"
1920

2021
static const int qvi_task_id_invalid = -1;
2122

2223
struct qvi_task_s {
24+
int qvim_rc = QV_SUCCESS;
2325
/** Task ID */
2426
qvi_task_id_t task_id = {};
2527
/** Global task ID */
2628
int64_t gid = qvi_task_id_invalid;
2729
/** Node-local task ID */
2830
int lid = qvi_task_id_invalid;
31+
/** Constructor */
32+
qvi_task_s(void) = default;
33+
/** Destructor */
34+
~qvi_task_s(void) = default;
2935
};
3036

3137
int
3238
qvi_task_new(
3339
qvi_task_t **task
3440
) {
35-
int rc = QV_SUCCESS;
36-
37-
qvi_task_t *itask = qvi_new qvi_task_t();
38-
if (!itask) {
39-
rc = QV_ERR_OOR;
40-
}
41-
if (rc != QV_SUCCESS) {
42-
qvi_task_free(&itask);
43-
}
44-
*task = itask;
45-
return rc;
41+
return qvi_new_rc(task);
4642
}
4743

4844
void
4945
qvi_task_free(
5046
qvi_task_t **task
5147
) {
52-
if (!task) return;
53-
qvi_task_t *itask = *task;
54-
if (!itask) goto out;
55-
delete itask;
56-
out:
57-
*task = nullptr;
48+
qvi_delete(task);
5849
}
5950

6051
int

0 commit comments

Comments
 (0)