Skip to content

Commit 622f269

Browse files
Merge pull request #292 from insertinterestingnamehere/debug
Fix Debug Builds
2 parents c5a7831 + 23b61eb commit 622f269

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+370
-516
lines changed

configure.ac

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ AC_ARG_ENABLE([asserts],
5757
[AS_HELP_STRING([--enable-asserts],
5858
[adds sanity checks to most qthread functions])])
5959

60-
AC_ARG_ENABLE([paranoia],
61-
[AS_HELP_STRING([--enable-paranoia],
62-
[adds expensive sanity checks])])
63-
6460
AC_ARG_WITH([topology],
6561
[AS_HELP_STRING([--with-topology=[[topologylib]]],
6662
[specify which topology interface to use. Supported
@@ -225,7 +221,6 @@ AC_CACHE_SAVE
225221
## -------------------- ##
226222
AC_SEARCH_LIBS([pthread_create], [pthread], [],
227223
[AC_MSG_ERROR([Qthreads requires a working pthreads implementation.])])
228-
AC_CHECK_FUNCS([pthread_yield])
229224

230225
AC_SEARCH_LIBS([nanosleep],[rt],[],
231226
[AC_MSG_ERROR([Cannot find nanosleep])])
@@ -368,12 +363,8 @@ AS_IF([test "x$enable_omp_affinity" = xyes],
368363
[AC_DEFINE([QTHREAD_OMP_AFFINITY], [1], [Enable experimental OpenMP affinity extensions. Under development])],
369364
[enable_omp_affinity="no"])
370365

371-
AS_IF([test "x$enable_paranoia" == "xyes"],
372-
[AC_DEFINE([QTHREAD_PARANOIA], [1], [expensive sanity checks])
373-
enable_asserts=yes])
374-
375366
AS_IF([test "x$enable_asserts" != "xyes"],
376-
[AC_DEFINE([QTHREAD_NO_ASSERTS], [1], [removes sanity checks from most qthread functions])
367+
[AC_DEFINE([NDEBUG], [1], [removes sanity checks from most qthread functions])
377368
enable_asserts=no],
378369
[enable_asserts=yes])
379370

include/qt_asserts.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,10 @@
3737
* and sending a signal to itself)
3838
*/
3939

40-
#ifdef QTHREAD_NO_ASSERTS
40+
#ifdef NDEBUG
4141
#define ASSERT_ONLY(x)
4242
#define qassert(op, val) op
4343
#define qassertnot(op, val) op
44-
#ifdef assert
45-
#undef assert
46-
#endif
47-
#define assert(foo)
4844
#define qassert_ret(assertion, retval) \
4945
do { \
5046
if (!(assertion)) { return retval; } \
@@ -61,7 +57,7 @@
6157
#define qgoto(tag) \
6258
tag:
6359
#define tassert(foo)
64-
#else // ifdef QTHREAD_NO_ASSERTS
60+
#else // ifdef NDEBUG
6561
#define ASSERT_ONLY(x) x
6662
#define qassert(op, val) assert((op) == (val))
6763
#define qassertnot(op, val) assert(op != val)
@@ -78,12 +74,6 @@
7874
do { \
7975
if (!(foo)) { QTHREAD_TRAP(); } \
8076
} while (0)
81-
#endif // ifdef QTHREAD_NO_ASSERTS
82-
83-
#ifdef QTHREAD_PARANOIA
84-
#define PARANOIA(x) x
85-
#else
86-
#define PARANOIA(x)
87-
#endif
77+
#endif // ifdef NDEBUG
8878

8979
/* vim:set expandtab: */

include/qt_atomics.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ static inline int QTHREAD_TRYLOCK_TRY(qt_spin_trylock_t *x) {
151151
} \
152152
{ \
153153
pthread_condattr_t tmp_attr; \
154+
pthread_condattr_init(&tmp_attr); \
154155
qassert(pthread_condattr_setpshared(&tmp_attr, PTHREAD_PROCESS_PRIVATE), \
155156
0); \
156157
qassert(pthread_cond_init(&(c), &tmp_attr), 0); \
@@ -182,7 +183,8 @@ static inline int QTHREAD_TRYLOCK_TRY(qt_spin_trylock_t *x) {
182183
t.tv_nsec = (n.tv_usec * 1000) + 500000000; \
183184
t.tv_sec = n.tv_sec + ((t.tv_nsec >= 1000000000) ? 1 : 0); \
184185
t.tv_nsec -= ((t.tv_nsec >= 1000000000) ? 1000000000 : 0); \
185-
qassert(pthread_cond_timedwait(&(c), &(c##_lock), &t), 0); \
186+
int val = pthread_cond_timedwait(&(c), &(c##_lock), &t); \
187+
qassert(val == EINVAL || val == EPERM, 0); \
186188
} while (0)
187189
#define QTHREAD_COND_WAIT_DUO(c, m) \
188190
do { \

include/qt_initialized.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#ifndef QT_INITIALIZED_H
22
#define QT_INITIALIZED_H
33

4-
#ifndef QTHREAD_NO_ASSERTS
54
extern int qthread_library_initialized;
6-
#endif
75

86
#endif

src/ds/dictionary/dictionary_simple.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void *qt_dictionary_put_helper(qt_dictionary *dict,
3535

3636
// Handle the case when variable does not exist;
3737
// Locks become nops when qthread is no longer initialized
38-
#ifdef QTHREAD_NO_ASSERTS
38+
#ifdef NDEBUG
3939
static int qthread_library_initialized = 1;
4040
#endif
4141

@@ -98,7 +98,7 @@ static int qthread_library_initialized = 1;
9898

9999
#define GET_BUCKET(hash) ((DICT_ABS(hash)) & ((1 << BKT_POW) - 1))
100100

101-
#ifndef QTHREAD_NO_ASSERTS
101+
#ifndef NDEBUG
102102
extern int qthread_library_initialized;
103103
#endif
104104

src/mpool.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static qt_mpool_threadlocal_cache_t *qt_mpool_internal_getcache(qt_mpool pool) {
221221
{
222222
uintptr_t count_caches = (uintptr_t)TLS_GET(pool_cache_count);
223223
if (count_caches < pool->offset) {
224-
#if !defined(QTHREAD_NO_ASSERTS)
224+
#if !defined(NDEBUG)
225225
qthread_worker_id_t wkr = qthread_readstate(CURRENT_UNIQUE_WORKER);
226226
/* I don't fully understand why this is necessary. I *suspect* that
227227
* on thread 0, the initialization routine isn't happening
@@ -249,7 +249,7 @@ static qt_mpool_threadlocal_cache_t *qt_mpool_internal_getcache(qt_mpool pool) {
249249
count_caches = pool->offset;
250250
TLS_SET(pool_cache_count, count_caches);
251251
} else if (tc == NULL) {
252-
#if !defined(QTHREAD_NO_ASSERTS)
252+
#if !defined(NDEBUG)
253253
qthread_worker_id_t wkr = qthread_readstate(CURRENT_UNIQUE_WORKER);
254254
/* I don't fully understand why this is necessary. I *suspect* that
255255
* on thread 0, the initialization routine isn't happening

src/qthread.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static qt_mpool generic_rdata_pool = NULL;
196196

197197
#include "qt_profiling.h"
198198

199-
#ifndef QTHREAD_NO_ASSERTS
199+
#ifndef NDEBUG
200200
int qthread_library_initialized = 0;
201201
void *shep0arg = NULL;
202202
#endif
@@ -339,7 +339,7 @@ static void *qthread_master(void *arg) {
339339

340340
assert(me != NULL);
341341
assert(me->shepherd_id <= qlib->nshepherds);
342-
#ifndef QTHREAD_NO_ASSERTS
342+
#ifndef NDEBUG
343343
if ((shep0arg != NULL) && (my_id == 0)) {
344344
if (arg != shep0arg) {
345345
print_error("arg = %p, shep0arg = %p\n", arg, shep0arg);
@@ -620,7 +620,7 @@ int API_FUNC qthread_initialize(void) { /*{{{ */
620620
qt_internal_alignment_init();
621621
qt_hash_initialize_subsystem();
622622

623-
#ifndef QTHREAD_NO_ASSERTS
623+
#ifndef NDEBUG
624624
qthread_library_initialized = 1;
625625
MACHINE_FENCE;
626626
#endif
@@ -830,7 +830,7 @@ int API_FUNC qthread_initialize(void) { /*{{{ */
830830
#endif
831831
&(qlib->shepherds[0].workers[0]),
832832
&(qlib->mccoy_thread->rdata->context));
833-
#ifndef QTHREAD_NO_ASSERTS
833+
#ifndef NDEBUG
834834
shep0arg = &(qlib->shepherds[0].workers[0]);
835835
#endif
836836
/* this launches shepherd 0 */
@@ -1202,7 +1202,7 @@ void API_FUNC qthread_finalize(void) { /*{{{ */
12021202
qlib = NULL;
12031203
TLS_DELETE(shepherd_structs);
12041204

1205-
#ifndef QTHREAD_NO_ASSERTS
1205+
#ifndef NDEBUG
12061206
MACHINE_FENCE;
12071207
qthread_library_initialized = 0;
12081208
MACHINE_FENCE;

src/sincs/snzi.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#include "config.h"
33
#endif
44

5-
#define QTHREAD_NO_ASSERTS 1
6-
75
#include <assert.h>
86
#include <stdio.h>
97
#include <stdlib.h>

src/threadqueues/nemesis_threadqueues.c

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -197,47 +197,6 @@ void INTERNAL qthread_steal_enable(void) {}
197197

198198
void INTERNAL qthread_steal_disable(void) {}
199199

200-
#ifdef QTHREAD_PARANOIA
201-
static void sanity_check_tq(NEMESIS_queue *q) { /*{{{*/
202-
qt_threadqueue_node_t *curs;
203-
204-
assert(q);
205-
/*if (q->head != NULL) {
206-
* assert(q->tail != NULL);
207-
* }*/
208-
if (q->shadow_head) { assert(q->head != q->shadow_head); }
209-
if (atomic_load_explicit(&q->tail, memory_order_relaxed) != NULL) {
210-
if (atomic_load_explicit(&q->head, memory_order_relaxed) == NULL) {
211-
assert(q->shadow_head != NULL);
212-
}
213-
}
214-
if ((atomic_load_explicit(&q->head, memory_order_relaxed) != NULL) ||
215-
(atomic_load_explicit(&q->tail, memory_order_relaxed) != NULL)) {
216-
if (q->shadow_head) {
217-
curs = q->shadow_head;
218-
assert(curs->thread);
219-
assert(curs->thread != (void *)0x7777777777777777);
220-
while (atomic_load_explicit(&curs->next, memory_order_relaxed)) {
221-
curs = atomic_load_explicit(&curs->next, memory_order_relaxed);
222-
assert(curs->thread);
223-
assert(curs->thread != (void *)0x7777777777777777);
224-
}
225-
}
226-
if (q->head) {
227-
curs = q->head;
228-
assert(curs->thread);
229-
assert(curs->thread != (void *)0x7777777777777777);
230-
while (atomic_load_explicit(&curs->next, memory_order_relaxed)) {
231-
curs = atomic_load_explicit(&curs->next, memory_order_relaxed);
232-
assert(curs->thread);
233-
assert(curs->thread != (void *)0x7777777777777777);
234-
}
235-
}
236-
}
237-
} /*}}}*/
238-
239-
#endif /* ifdef QTHREAD_PARANOIA */
240-
241200
qthread_shepherd_id_t INTERNAL
242201
qt_threadqueue_choose_dest(qthread_shepherd_t *curr_shep) {
243202
qthread_shepherd_id_t dest_shep_id = 0;
@@ -260,8 +219,6 @@ void INTERNAL qt_threadqueue_enqueue(qt_threadqueue_t *restrict q,
260219
assert(q);
261220
assert(t);
262221

263-
PARANOIA(sanity_check_tq(&q->q));
264-
265222
node = ALLOC_TQNODE();
266223
assert(node != NULL);
267224
node->thread = t;
@@ -274,7 +231,6 @@ void INTERNAL qt_threadqueue_enqueue(qt_threadqueue_t *restrict q,
274231
} else {
275232
atomic_store_explicit(&prev->next, node, memory_order_relaxed);
276233
}
277-
PARANOIA(sanity_check_tq(&q->q));
278234
(void)qthread_incr(&(q->advisory_queuelen), 1);
279235
#ifdef QTHREAD_CONDWAIT_BLOCKING_QUEUE
280236
/* awake waiter */
@@ -310,11 +266,10 @@ qt_scheduler_get_thread(qt_threadqueue_t *q,
310266
#ifdef QTHREAD_CONDWAIT_BLOCKING_QUEUE
311267
int i;
312268
#endif /* QTHREAD_CONDWAIT_BLOCKING_QUEUE */
313-
PARANOIA(sanity_check_tq(&q->q));
269+
314270
qt_threadqueue_node_t *node = qt_internal_NEMESIS_dequeue(&q->q);
315271
qthread_t *retval;
316272

317-
PARANOIA(sanity_check_tq(&q->q));
318273
if (node == NULL) {
319274
#ifdef QTHREAD_CONDWAIT_BLOCKING_QUEUE
320275
i = num_spins_before_condwait;
@@ -345,7 +300,6 @@ qt_scheduler_get_thread(qt_threadqueue_t *q,
345300
(void)qthread_incr(&(q->advisory_queuelen), -1);
346301
retval = node->thread;
347302
FREE_TQNODE(node);
348-
PARANOIA(sanity_check_tq(&q->q));
349303
return retval;
350304
} /*}}} */
351305

@@ -361,11 +315,8 @@ void INTERNAL qt_threadqueue_filter(qt_threadqueue_t *q,
361315
atomic_init(&tmp.tail, NULL);
362316
tmp.shadow_head = NULL;
363317
tmp.nemesis_advisory_queuelen = 0;
364-
PARANOIA(sanity_check_tq(&q->q));
365318
while ((curs = qt_internal_NEMESIS_dequeue_st(&q->q))) {
366319
qthread_t *t = curs->thread;
367-
PARANOIA(sanity_check_tq(&tmp));
368-
PARANOIA(sanity_check_tq(&q->q));
369320
switch (f(t)) {
370321
case IGNORE_AND_CONTINUE: // ignore, move on
371322
prev = qt_internal_atomic_swap_ptr((void **)&(tmp.tail), curs);
@@ -395,7 +346,6 @@ void INTERNAL qt_threadqueue_filter(qt_threadqueue_t *q,
395346
}
396347
pushback:
397348
/* dequeue the rest of the queue */
398-
PARANOIA(sanity_check_tq(&tmp));
399349
if (atomic_load_explicit(&q->q.head, memory_order_relaxed)) {
400350
prev = qt_internal_atomic_swap_ptr((void **)&(tmp.tail), q->q.head);
401351
if (prev == NULL) {
@@ -423,7 +373,6 @@ void INTERNAL qt_threadqueue_filter(qt_threadqueue_t *q,
423373
memory_order_relaxed);
424374
q->q.shadow_head = NULL;
425375
q->advisory_queuelen = tmp.nemesis_advisory_queuelen;
426-
PARANOIA(sanity_check_tq(&q->q));
427376
} /*}}}*/
428377

429378
/* some place-holder functions */

0 commit comments

Comments
 (0)