Commit d2c0e1bc authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

#2966 use assert_zero in some of the newbrt files refs[t:2966]

git-svn-id: file:///svn/toku/tokudb@24717 c7de825b-a66e-492c-adef-691d508d4ae1
parent b09778dd
......@@ -92,6 +92,9 @@ endif
try-assert0.tdbrun: try-assert0
./$< 2> /dev/null $(INVERTER) $(SUMMARIZE_SHOULD_FAIL)
try-assert-zero.tdbrun: try-assert-zero
./$< 2> /dev/null $(INVERTER) $(SUMMARIZE_SHOULD_FAIL)
clean:
rm -rf $(TARGETS) *.check.output *.check.valgrind pwrite4g.data testdir dir.*.c
......
#include <stdio.h>
#include <toku_assert.h>
int main(void) {
int result = 42;
assert_zero(result);
return 0;
}
This diff is collapsed.
This diff is collapsed.
......@@ -108,19 +108,19 @@ int brt_loader_lock_init(BRTLOADER bl) {
void brt_loader_lock_destroy(BRTLOADER bl) {
if (bl->mutex_init) {
int r = toku_pthread_mutex_destroy(&bl->mutex); resource_assert(r == 0);
int r = toku_pthread_mutex_destroy(&bl->mutex); resource_assert_zero(r);
bl->mutex_init = FALSE;
}
}
static void brt_loader_lock(BRTLOADER bl) {
invariant(bl->mutex_init);
int r = toku_pthread_mutex_lock(&bl->mutex); resource_assert(r == 0);
int r = toku_pthread_mutex_lock(&bl->mutex); resource_assert_zero(r);
}
static void brt_loader_unlock(BRTLOADER bl) {
invariant(bl->mutex_init);
int r = toku_pthread_mutex_unlock(&bl->mutex); resource_assert(r == 0);
int r = toku_pthread_mutex_unlock(&bl->mutex); resource_assert_zero(r);
}
static int add_big_buffer(struct file_info *file) {
......@@ -155,7 +155,7 @@ static void cleanup_big_buffer(struct file_info *file) {
int brtloader_init_file_infos (struct file_infos *fi) {
int result = 0;
int r = toku_pthread_mutex_init(&fi->lock, NULL); resource_assert(r == 0);
int r = toku_pthread_mutex_init(&fi->lock, NULL); resource_assert_zero(r);
fi->n_files = 0;
fi->n_files_limit = 1;
fi->n_files_open = 0;
......@@ -172,7 +172,7 @@ void brtloader_fi_destroy (struct file_infos *fi, BOOL is_error)
// If !is_error then requires that all the temp files have been closed and destroyed
// No error codes are returned. If anything goes wrong with closing and unlinking then it's only in an is_error case, so we don't care.
{
int r = toku_pthread_mutex_destroy(&fi->lock); resource_assert(r == 0);
int r = toku_pthread_mutex_destroy(&fi->lock); resource_assert_zero(r);
if (!is_error) {
invariant(fi->n_files_open==0);
invariant(fi->n_files_extant==0);
......@@ -201,7 +201,7 @@ static int open_file_add (struct file_infos *fi,
/* out */ FIDX *idx)
{
int result = 0;
int r = toku_pthread_mutex_lock(&fi->lock); resource_assert(r==0);
int r = toku_pthread_mutex_lock(&fi->lock); resource_assert_zero(r);
if (fi->n_files >= fi->n_files_limit) {
fi->n_files_limit *=2;
XREALLOC_N(fi->n_files_limit, fi->file_infos);
......@@ -221,13 +221,13 @@ static int open_file_add (struct file_infos *fi,
fi->n_files_extant++;
fi->n_files_open++;
}
r = toku_pthread_mutex_unlock(&fi->lock); resource_assert(r==0);
r = toku_pthread_mutex_unlock(&fi->lock); resource_assert_zero(r);
return result;
}
int brtloader_fi_reopen (struct file_infos *fi, FIDX idx, const char *mode) {
int result = 0;
int r = toku_pthread_mutex_lock(&fi->lock); resource_assert(r==0);
int r = toku_pthread_mutex_lock(&fi->lock); resource_assert_zero(r);
int i = idx.idx;
invariant(i>=0 && i<fi->n_files);
invariant(!fi->file_infos[i].is_open);
......@@ -241,14 +241,14 @@ int brtloader_fi_reopen (struct file_infos *fi, FIDX idx, const char *mode) {
//add_big_buffer(&fi->file_infos[i]);
fi->n_files_open++;
}
r = toku_pthread_mutex_unlock(&fi->lock); resource_assert(r==0);
r = toku_pthread_mutex_unlock(&fi->lock); resource_assert_zero(r);
return result;
}
int brtloader_fi_close (struct file_infos *fi, FIDX idx)
{
int result = 0;
{ int r2 = toku_pthread_mutex_lock(&fi->lock); resource_assert(r2==0); }
{ int r2 = toku_pthread_mutex_lock(&fi->lock); resource_assert_zero(r2); }
invariant(idx.idx >=0 && idx.idx < fi->n_files);
if (fi->file_infos[idx.idx].is_open) {
invariant(fi->n_files_open>0); // loader-cleanup-test failure
......@@ -261,13 +261,13 @@ int brtloader_fi_close (struct file_infos *fi, FIDX idx)
result = errno;
} else
result = EINVAL;
{ int r2 = toku_pthread_mutex_unlock(&fi->lock); resource_assert(r2==0); }
{ int r2 = toku_pthread_mutex_unlock(&fi->lock); resource_assert_zero(r2); }
return result;
}
int brtloader_fi_unlink (struct file_infos *fi, FIDX idx) {
int result = 0;
{ int r2 = toku_pthread_mutex_lock(&fi->lock); resource_assert(r2==0); }
{ int r2 = toku_pthread_mutex_lock(&fi->lock); resource_assert_zero(r2); }
int id = idx.idx;
invariant(id >=0 && id < fi->n_files);
if (fi->file_infos[id].is_extant) { // must still exist
......@@ -282,7 +282,7 @@ int brtloader_fi_unlink (struct file_infos *fi, FIDX idx) {
fi->file_infos[id].fname = NULL;
} else
result = EINVAL;
{ int r2 = toku_pthread_mutex_unlock(&fi->lock); resource_assert(r2==0); }
{ int r2 = toku_pthread_mutex_unlock(&fi->lock); resource_assert_zero(r2); }
return result;
}
......@@ -639,11 +639,11 @@ static void brt_loader_set_panic(BRTLOADER bl, int error, BOOL callback) {
// One of the tests uses this.
FILE *toku_bl_fidx2file (BRTLOADER bl, FIDX i) {
{ int r2 = toku_pthread_mutex_lock(&bl->file_infos.lock); resource_assert(r2==0); }
{ int r2 = toku_pthread_mutex_lock(&bl->file_infos.lock); resource_assert_zero(r2); }
invariant(i.idx >=0 && i.idx < bl->file_infos.n_files);
invariant(bl->file_infos.file_infos[i.idx].is_open);
FILE *result=bl->file_infos.file_infos[i.idx].file;
{ int r2 = toku_pthread_mutex_unlock(&bl->file_infos.lock); resource_assert(r2==0); }
{ int r2 = toku_pthread_mutex_unlock(&bl->file_infos.lock); resource_assert_zero(r2); }
return result;
}
......@@ -780,9 +780,9 @@ int loader_write_row(DBT *key, DBT *val, FIDX data, FILE *dataf, u_int64_t *data
// we have a chance to handle the errors because when we close we can delete all the files.
if ((r=bl_write_dbt(key, dataf, dataoff, bl))) return r;
if ((r=bl_write_dbt(val, dataf, dataoff, bl))) return r;
{ int r2 = toku_pthread_mutex_lock(&bl->file_infos.lock); resource_assert(r2==0); }
{ int r2 = toku_pthread_mutex_lock(&bl->file_infos.lock); resource_assert_zero(r2); }
bl->file_infos.file_infos[data.idx].n_rows++;
{ int r2 = toku_pthread_mutex_unlock(&bl->file_infos.lock); resource_assert(r2==0); }
{ int r2 = toku_pthread_mutex_unlock(&bl->file_infos.lock); resource_assert_zero(r2); }
return 0;
}
......@@ -1006,7 +1006,7 @@ static void enqueue_for_extraction (BRTLOADER bl) {
*enqueue_me = bl->primary_rowset;
zero_rowset(&bl->primary_rowset);
int r = queue_enq(bl->primary_rowset_queue, (void*)enqueue_me, 1, NULL);
resource_assert(r==0);
resource_assert_zero(r);
}
static int loader_do_put(BRTLOADER bl,
......@@ -1050,7 +1050,8 @@ static int finish_extractor (BRTLOADER bl) {
{
void *toku_pthread_retval;
int r = toku_pthread_join(bl->extractor_thread, &toku_pthread_retval);
resource_assert(r==0 && toku_pthread_retval==NULL);
resource_assert_zero(r);
invariant(toku_pthread_retval == NULL);
bl->extractor_live = FALSE;
BL_TRACE(blt_join_on_extractor);
}
......@@ -1485,7 +1486,7 @@ static int update_progress (int N,
{
// Need a lock here because of cilk and also the various pthreads.
// Must protect the increment and the call to the poll_function.
{ int r = toku_pthread_mutex_lock(&update_progress_lock); resource_assert(r == 0); }
{ int r = toku_pthread_mutex_lock(&update_progress_lock); resource_assert_zero(r); }
bl->progress+=N;
int result;
......@@ -1498,7 +1499,7 @@ static int update_progress (int N,
} else {
result = bl->progress_callback_result;
}
{ int r = toku_pthread_mutex_unlock(&update_progress_lock); resource_assert(r == 0); }
{ int r = toku_pthread_mutex_unlock(&update_progress_lock); resource_assert_zero(r); }
return result;
}
......@@ -1663,9 +1664,9 @@ int toku_merge_some_files_using_dbufio (const BOOL to_q, FIDX dest_data, QUEUE q
}
dataoff[i] = 0;
{ int r2 = toku_pthread_mutex_lock(&bl->file_infos.lock); resource_assert(r2==0); }
{ int r2 = toku_pthread_mutex_lock(&bl->file_infos.lock); resource_assert_zero(r2); }
n_rows += bl->file_infos.file_infos[srcs_fidxs[i].idx].n_rows;
{ int r2 = toku_pthread_mutex_unlock(&bl->file_infos.lock); resource_assert(r2==0); }
{ int r2 = toku_pthread_mutex_unlock(&bl->file_infos.lock); resource_assert_zero(r2); }
}
}
u_int64_t n_rows_done = 0;
......@@ -1740,7 +1741,6 @@ int toku_merge_some_files_using_dbufio (const BOOL to_q, FIDX dest_data, QUEUE q
} else {
fprintf(stderr, "%s:%d r=%d errno=%d bfs=%p mini=%d\n", __FILE__, __LINE__, r, errno, bfs, mini);
dbufio_print(bfs);
// lazy_assert(0);
result = r;
break;
}
......@@ -2602,7 +2602,7 @@ static int loader_do_i (BRTLOADER bl,
int r2 = toku_pthread_join(bl->fractal_threads[which_db], &toku_pthread_retval);
invariant(fta.bl==bl); // this is a gratuitous assertion to make sure that the fta struct is still live here. A previous bug but that struct into a C block statement.
BL_TRACE(blt_join_on_fractal);
resource_assert(r2==0);
resource_assert_zero(r2);
invariant(toku_pthread_retval==NULL);
invariant(bl->fractal_threads_live[which_db]);
bl->fractal_threads_live[which_db] = FALSE;
......
......@@ -163,24 +163,24 @@ struct cachetable {
// Lock the cachetable
static inline void cachefiles_lock(CACHETABLE ct) {
int r = toku_pthread_mutex_lock(&ct->cachefiles_mutex); assert(r == 0);
int r = toku_pthread_mutex_lock(&ct->cachefiles_mutex); resource_assert_zero(r);
}
// Unlock the cachetable
static inline void cachefiles_unlock(CACHETABLE ct) {
int r = toku_pthread_mutex_unlock(&ct->cachefiles_mutex); assert(r == 0);
int r = toku_pthread_mutex_unlock(&ct->cachefiles_mutex); resource_assert_zero(r);
}
// Lock the cachetable
static inline void cachetable_lock(CACHETABLE ct __attribute__((unused))) {
int r = toku_pthread_mutex_lock(ct->mutex); assert(r == 0);
int r = toku_pthread_mutex_lock(ct->mutex); resource_assert_zero(r);;
cachetable_lock_taken++;
}
// Unlock the cachetable
static inline void cachetable_unlock(CACHETABLE ct __attribute__((unused))) {
cachetable_lock_released++;
int r = toku_pthread_mutex_unlock(ct->mutex); assert(r == 0);
int r = toku_pthread_mutex_unlock(ct->mutex); resource_assert_zero(r);
}
// Wait for cache table space to become available
......@@ -282,8 +282,8 @@ int toku_create_cachetable(CACHETABLE *result, long size_limit, LSN UU(initial_l
ct->logger = logger;
toku_init_workers(&ct->wq, &ct->threadpool);
ct->mutex = workqueue_lock_ref(&ct->wq);
int r = toku_pthread_mutex_init(&ct->openfd_mutex, NULL); assert(r == 0);
r = toku_pthread_mutex_init(&ct->cachefiles_mutex, 0); assert(r == 0);
int r = toku_pthread_mutex_init(&ct->openfd_mutex, NULL); resource_assert_zero(r);
r = toku_pthread_mutex_init(&ct->cachefiles_mutex, 0); resource_assert_zero(r);
toku_minicron_setup(&ct->checkpointer, 0, checkpoint_thread, ct); // default is no checkpointing
r = toku_leaflock_create(&ct->leaflock_pool); assert(r==0);
r = toku_omt_create(&ct->reserved_filenums); assert(r==0);
......@@ -354,8 +354,7 @@ int toku_cachefile_of_iname_in_env (CACHETABLE ct, const char *iname_in_env, CAC
//Cachefile is closing, wait till finished.
assert(extant->closefd_waiting==0); //Single client thread (any more and this needs to be re-analyzed).
extant->closefd_waiting++;
int rwait = toku_pthread_cond_wait(&extant->closefd_wait, ct->mutex);
assert(rwait == 0);
int rwait = toku_pthread_cond_wait(&extant->closefd_wait, ct->mutex); resource_assert_zero(rwait);
restarted = TRUE;
goto restart; //Restart and verify that it is not found in the second loop.
}
......@@ -534,7 +533,7 @@ int toku_cachetable_openfd_with_filenum (CACHEFILE *cfptr, CACHETABLE ct, int fd
return r;
}
r = toku_pthread_mutex_lock(&ct->openfd_mutex); // purpose is to make this function single-threaded
assert(r==0);
resource_assert_zero(r);
cachetable_lock(ct);
cachefiles_lock(ct);
for (extant = ct->cachefiles; extant; extant=extant->next) {
......@@ -544,8 +543,8 @@ int toku_cachetable_openfd_with_filenum (CACHEFILE *cfptr, CACHETABLE ct, int fd
if (extant->is_closing) {
// if another thread is closing this file, wait until the close is fully complete
cachefiles_unlock(ct); //Cannot hold cachefiles lock over the cond_wait
r = toku_pthread_cond_wait(&extant->openfd_wait, ct->mutex);
assert(r == 0);
r = toku_pthread_cond_wait(&extant->openfd_wait, ct->mutex);
resource_assert_zero(r);
cachefiles_lock(ct);
goto try_again; // other thread has closed this file, go create a new cachefile
}
......@@ -608,8 +607,8 @@ int toku_cachetable_openfd_with_filenum (CACHEFILE *cfptr, CACHETABLE ct, int fd
newcf->for_local_checkpoint = ZERO_LSN;
newcf->checkpoint_state = CS_NOT_IN_PROGRESS;
r = toku_pthread_cond_init(&newcf->openfd_wait, NULL); assert(r == 0);
r = toku_pthread_cond_init(&newcf->closefd_wait, NULL); assert(r == 0);
r = toku_pthread_cond_init(&newcf->openfd_wait, NULL); resource_assert_zero(r);
r = toku_pthread_cond_init(&newcf->closefd_wait, NULL); resource_assert_zero(r);
*cfptr = newcf;
r = 0;
}
......@@ -617,7 +616,7 @@ int toku_cachetable_openfd_with_filenum (CACHEFILE *cfptr, CACHETABLE ct, int fd
cachefiles_unlock(ct);
{
int rm = toku_pthread_mutex_unlock(&ct->openfd_mutex);
assert (rm == 0);
resource_assert_zero(rm);
}
cachetable_unlock(ct);
return r;
......@@ -808,7 +807,7 @@ int toku_cachefile_close (CACHEFILE *cfp, char **error_string, BOOL oplsn_valid,
assert(cf->refcount == 1); // toku_cachetable_openfd() is single-threaded
assert(!cf->next_in_checkpoint); //checkpoint cannot run on a closing file
assert(!cf->for_checkpoint); //checkpoint cannot run on a closing file
rs = toku_pthread_cond_signal(&cf->openfd_wait); assert(rs == 0);
rs = toku_pthread_cond_signal(&cf->openfd_wait); resource_assert_zero(rs);
}
if (cf->closefd_waiting > 0) {
int rs;
......@@ -819,9 +818,9 @@ int toku_cachefile_close (CACHEFILE *cfp, char **error_string, BOOL oplsn_valid,
{
int rd;
rd = toku_pthread_cond_destroy(&cf->openfd_wait);
assert(rd == 0);
resource_assert_zero(rd);
rd = toku_pthread_cond_destroy(&cf->closefd_wait);
assert(rd == 0);
resource_assert_zero(rd);
}
if (cf->fname_in_env) toku_free(cf->fname_in_env);
......@@ -860,20 +859,20 @@ int toku_cachefile_close (CACHEFILE *cfp, char **error_string, BOOL oplsn_valid,
if (cf->refcount > 0) {
int rs;
assert(cf->refcount == 1); // toku_cachetable_openfd() is single-threaded
rs = toku_pthread_cond_signal(&cf->openfd_wait); assert(rs == 0);
rs = toku_pthread_cond_signal(&cf->openfd_wait); resource_assert_zero(rs);
}
if (cf->closefd_waiting > 0) {
int rs;
assert(cf->closefd_waiting == 1);
rs = toku_pthread_cond_signal(&cf->closefd_wait); assert(rs == 0);
rs = toku_pthread_cond_signal(&cf->closefd_wait); resource_assert_zero(rs);
}
// we can destroy the condition variables because if there was another thread waiting, it was already signalled
{
int rd;
rd = toku_pthread_cond_destroy(&cf->openfd_wait);
assert(rd == 0);
resource_assert_zero(rd);
rd = toku_pthread_cond_destroy(&cf->closefd_wait);
assert(rd == 0);
resource_assert_zero(rd);
}
rwlock_write_lock(&cf->fdlock, ct->mutex); //Just make sure we can get it.
cachetable_unlock(ct);
......@@ -1869,12 +1868,12 @@ toku_cachetable_close (CACHETABLE *ctp) {
}
assert(ct->size_writing == 0);
rwlock_destroy(&ct->pending_lock);
r = toku_pthread_mutex_destroy(&ct->openfd_mutex); assert(r == 0);
r = toku_pthread_mutex_destroy(&ct->openfd_mutex); resource_assert_zero(r);
cachetable_unlock(ct);
toku_destroy_workers(&ct->wq, &ct->threadpool);
r = toku_leaflock_destroy(&ct->leaflock_pool); assert(r==0);
r = toku_leaflock_destroy(&ct->leaflock_pool); assert_zero(r);
toku_omt_destroy(&ct->reserved_filenums);
r = toku_pthread_mutex_destroy(&ct->cachefiles_mutex); assert(r == 0);
r = toku_pthread_mutex_destroy(&ct->cachefiles_mutex); resource_assert_zero(r);
toku_free(ct->table);
toku_free(ct->env_dir);
toku_free(ct);
......
......@@ -50,8 +50,8 @@ toku_thread_create(struct toku_thread_pool *pool, struct toku_thread **toku_thre
} else {
memset(thread, 0, sizeof *thread);
thread->pool = pool;
r = toku_pthread_cond_init(&thread->wait, NULL); invariant(r == 0);
r = toku_pthread_create(&thread->tid, NULL, toku_thread_run_internal, thread); invariant(r == 0);
r = toku_pthread_cond_init(&thread->wait, NULL); resource_assert_zero(r);
r = toku_pthread_create(&thread->tid, NULL, toku_thread_run_internal, thread); resource_assert_zero(r);
*toku_thread_return = thread;
}
return r;
......@@ -64,7 +64,7 @@ toku_thread_run(struct toku_thread *thread, void *(*f)(void *arg), void *arg) {
thread->f = f;
thread->arg = arg;
toku_thread_pool_unlock(thread->pool);
r = toku_pthread_cond_signal(&thread->wait); invariant(r == 0);
r = toku_pthread_cond_signal(&thread->wait); resource_assert_zero(r);
}
static void
......@@ -76,14 +76,14 @@ toku_thread_destroy(struct toku_thread *thread) {
toku_thread_pool_lock(pool);
toku_list_remove(&thread->free_link);
toku_thread_pool_unlock(pool);
r = toku_pthread_cond_destroy(&thread->wait); invariant(r == 0);
r = toku_pthread_cond_destroy(&thread->wait); resource_assert_zero(r);
toku_free(thread);
}
static void
toku_thread_ask_exit(struct toku_thread *thread) {
thread->doexit = 1;
int r = toku_pthread_cond_signal(&thread->wait); invariant(r == 0);
int r = toku_pthread_cond_signal(&thread->wait); resource_assert_zero(r);
}
static void *
......@@ -93,13 +93,13 @@ toku_thread_run_internal(void *arg) {
int r;
toku_thread_pool_lock(pool);
while (1) {
r = toku_pthread_cond_signal(&pool->wait_free); invariant(r == 0);
r = toku_pthread_cond_signal(&pool->wait_free); resource_assert_zero(r);
void *(*thread_f)(void *); void *thread_arg; int doexit;
while (1) {
thread_f = thread->f; thread_arg = thread->arg; doexit = thread->doexit; // make copies of these variables to make helgrind happy
if (thread_f || doexit)
break;
r = toku_pthread_cond_wait(&thread->wait, &pool->lock); invariant(r == 0);
r = toku_pthread_cond_wait(&thread->wait, &pool->lock); resource_assert_zero(r);
}
toku_thread_pool_unlock(pool);
if (thread_f)
......@@ -121,10 +121,10 @@ toku_thread_pool_create(struct toku_thread_pool **pool_return, int max_threads)
r = errno;
} else {
memset(pool, 0, sizeof *pool);
r = toku_pthread_mutex_init(&pool->lock, NULL); invariant(r == 0);
r = toku_pthread_mutex_init(&pool->lock, NULL); resource_assert_zero(r);
toku_list_init(&pool->free_threads);
toku_list_init(&pool->all_threads);
r = toku_pthread_cond_init(&pool->wait_free, NULL); invariant(r == 0);
r = toku_pthread_cond_init(&pool->wait_free, NULL); resource_assert_zero(r);
pool->cur_threads = 0;
pool->max_threads = max_threads;
*pool_return = pool;
......@@ -135,12 +135,12 @@ toku_thread_pool_create(struct toku_thread_pool **pool_return, int max_threads)
static void
toku_thread_pool_lock(struct toku_thread_pool *pool) {
int r = toku_pthread_mutex_lock(&pool->lock); invariant(r == 0);
int r = toku_pthread_mutex_lock(&pool->lock); resource_assert_zero(r);
}
static void
toku_thread_pool_unlock(struct toku_thread_pool *pool) {
int r = toku_pthread_mutex_unlock(&pool->lock); invariant(r == 0);
int r = toku_pthread_mutex_unlock(&pool->lock); resource_assert_zero(r);
}
void
......@@ -169,8 +169,8 @@ toku_thread_pool_destroy(struct toku_thread_pool **poolptr) {
// cleanup
int r;
r = toku_pthread_cond_destroy(&pool->wait_free); invariant(r == 0);
r = toku_pthread_mutex_destroy(&pool->lock); invariant(r == 0);
r = toku_pthread_cond_destroy(&pool->wait_free); resource_assert_zero(r);
r = toku_pthread_mutex_destroy(&pool->lock); resource_assert_zero(r);
toku_free(pool);
}
......@@ -183,7 +183,7 @@ toku_thread_pool_add(struct toku_thread_pool *pool) {
pool->cur_threads += 1;
toku_list_push(&pool->all_threads, &thread->all_link);
toku_list_push(&pool->free_threads, &thread->free_link);
r = toku_pthread_cond_signal(&pool->wait_free); invariant(r == 0);
r = toku_pthread_cond_signal(&pool->wait_free); resource_assert_zero(r);
}
return r;
}
......@@ -204,7 +204,7 @@ toku_thread_pool_get_one(struct toku_thread_pool *pool, int dowait, struct toku_
break;
}
pool->get_blocks++;
r = toku_pthread_cond_wait(&pool->wait_free, &pool->lock); invariant(r == 0);
r = toku_pthread_cond_wait(&pool->wait_free, &pool->lock); resource_assert_zero(r);
}
if (r == 0) {
struct toku_list *list = toku_list_pop_head(&pool->free_threads);
......
......@@ -28,28 +28,28 @@ struct workset {
static inline void
workset_init(struct workset *ws) {
int r;
r = toku_pthread_mutex_init(&ws->lock, NULL); invariant(r == 0);
r = toku_pthread_mutex_init(&ws->lock, NULL); resource_assert_zero(r);
toku_list_init(&ws->worklist);
ws->refs = 1; // the calling thread gets a reference
r = toku_pthread_cond_init(&ws->worker_wait, NULL); invariant(r == 0);
r = toku_pthread_cond_init(&ws->worker_wait, NULL); resource_assert_zero(r);
}
static inline void
workset_destroy(struct workset *ws) {
invariant(toku_list_empty(&ws->worklist));
int r;
r = toku_pthread_cond_destroy(&ws->worker_wait); invariant(r == 0);
r = toku_pthread_mutex_destroy(&ws->lock); invariant(r == 0);
r = toku_pthread_cond_destroy(&ws->worker_wait); resource_assert_zero(r);
r = toku_pthread_mutex_destroy(&ws->lock); resource_assert_zero(r);
}
static inline void
workset_lock(struct workset *ws) {
int r = toku_pthread_mutex_lock(&ws->lock); invariant(r == 0);
int r = toku_pthread_mutex_lock(&ws->lock); resource_assert_zero(r);
}
static inline void
workset_unlock(struct workset *ws) {
int r = toku_pthread_mutex_unlock(&ws->lock); invariant(r == 0);
int r = toku_pthread_mutex_unlock(&ws->lock); resource_assert_zero(r);
}
// Put work in the workset. Assume the workset is already locked.
......@@ -92,7 +92,7 @@ static inline void
workset_release_ref(struct workset *ws) {
workset_lock(ws);
if (--ws->refs == 0) {
int r = toku_pthread_cond_broadcast(&ws->worker_wait); invariant(r == 0);
int r = toku_pthread_cond_broadcast(&ws->worker_wait); resource_assert_zero(r);
}
workset_unlock(ws);
}
......@@ -102,7 +102,7 @@ static inline void
workset_join(struct workset *ws) {
workset_lock(ws);
while (ws->refs != 0) {
int r = toku_pthread_cond_wait(&ws->worker_wait, &ws->lock); invariant(r == 0);
int r = toku_pthread_cond_wait(&ws->worker_wait, &ws->lock); resource_assert_zero(r);
}
workset_unlock(ws);
}
......
......@@ -4,6 +4,7 @@
/* This version will complain if NDEBUG is set. */
/* It evaluates the argument and then calls a function toku_do_assert() which takes all the hits for the branches not taken. */
#include <stdint.h>
#include "c_dialects.h"
#include "errno.h"
......@@ -13,8 +14,10 @@ C_BEGIN
#error NDEBUG should not be set
#endif
void toku_do_assert(int /*expr*/,const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/, int/*errno*/) __attribute__((__visibility__("default")));
void toku_do_assert_fail(const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/, int/*errno*/) __attribute__((__visibility__("default"))) __attribute__((__noreturn__));
void toku_do_assert(int,const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/, int/*errno*/) __attribute__((__visibility__("default")));
void toku_do_assert_zero_fail(uintptr_t/*expr*/, const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/, int/*errno*/) __attribute__((__visibility__("default"))) __attribute__((__noreturn__));
// Define GCOV if you want to get test-coverage information that ignores the assert statements.
// #define GCOV
......@@ -22,9 +25,11 @@ void toku_do_assert(int,const char*/*expr_as_string*/,const char */*fun*/,const
extern void (*do_assert_hook)(void); // Set this to a function you want called after printing the assertion failure message but before calling abort(). By default this is NULL.
#if defined(GCOV) || TOKU_WINDOWS
#define assert(expr) toku_do_assert((expr) != 0, #expr, __FUNCTION__, __FILE__, __LINE__, errno)
#define assert(expr) toku_do_assert((expr) != 0, #expr, __FUNCTION__, __FILE__, __LINE__, errno)
#define assert_zero(expr) toku_do_assert((expr) == 0, #expr, __FUNCTION__, __FILE__, __LINE__, errno)
#else
#define assert(expr) ((expr) ? (void)0 : toku_do_assert_fail(#expr, __FUNCTION__, __FILE__, __LINE__, errno))
#define assert(expr) ((expr) ? (void)0 : toku_do_assert_fail(#expr, __FUNCTION__, __FILE__, __LINE__, errno))
#define assert_zero(expr) ((expr) == 0 ? (void)0 : toku_do_assert_zero_fail((uintptr_t)(expr), #expr, __FUNCTION__, __FILE__, __LINE__, errno))
#endif
#ifdef GCOV
......@@ -35,9 +40,12 @@ extern void (*do_assert_hook)(void); // Set this to a function you want called a
#define WHEN_NOT_GCOV(x) x
#endif
#define lazy_assert(a) assert(a) // indicates code is incomplete
#define invariant(a) assert(a) // indicates a code invariant that must be true
#define resource_assert(a) assert(a) // indicates resource must be available, otherwise unrecoverable
#define lazy_assert(a) assert(a) // indicates code is incomplete
#define lazy_assert_zero(a) assert_zero(a) // indicates code is incomplete
#define invariant(a) assert(a) // indicates a code invariant that must be true
#define invariant_zero(a) assert_zero(a) // indicates a code invariant that must be true
#define resource_assert(a) assert(a) // indicates resource must be available, otherwise unrecoverable
#define resource_assert_zero(a) assert_zero(a) // indicates resource must be available, otherwise unrecoverable
C_END
......
......@@ -19,42 +19,56 @@ static void *backtrace_pointers[N_POINTERS];
void (*do_assert_hook)(void) = NULL;
void toku_do_assert_fail (const char* expr_as_string,const char *function,const char*file,int line, int caller_errno)
{
fprintf(stderr, "%s:%d %s: Assertion `%s' failed (errno=%d)\n", file,line,function,expr_as_string, caller_errno);
static void toku_do_backtrace_abort(void) __attribute__((noreturn));
// backtrace
static void
toku_do_backtrace_abort(void) {
// backtrace
#if !TOKU_WINDOWS
int n = backtrace(backtrace_pointers, N_POINTERS);
fprintf(stderr, "Backtrace: (Note: toku_do_assert=0x%p)\n", toku_do_assert); fflush(stderr);
backtrace_symbols_fd(backtrace_pointers, n, fileno(stderr));
int n = backtrace(backtrace_pointers, N_POINTERS);
fprintf(stderr, "Backtrace: (Note: toku_do_assert=0x%p)\n", toku_do_assert); fflush(stderr);
backtrace_symbols_fd(backtrace_pointers, n, fileno(stderr));
#endif
fflush(stderr);
fflush(stderr);
#if TOKU_WINDOWS
//Following commented methods will not always end the process (could hang).
//They could be unacceptable for other reasons as well (popups,
//flush buffers before quitting, etc)
// abort()
// assert(FALSE) (assert.h assert)
// raise(SIGABRT)
// divide by 0
// null dereference
// _exit
// exit
// ExitProcess
TerminateProcess(GetCurrentProcess(), 134); //Only way found so far to unconditionally
//Terminate the process
//Following commented methods will not always end the process (could hang).
//They could be unacceptable for other reasons as well (popups,
//flush buffers before quitting, etc)
// abort()
// assert(FALSE) (assert.h assert)
// raise(SIGABRT)
// divide by 0
// null dereference
// _exit
// exit
// ExitProcess
TerminateProcess(GetCurrentProcess(), 134); //Only way found so far to unconditionally
//Terminate the process
#endif
if (do_assert_hook) do_assert_hook();
if (do_assert_hook) do_assert_hook();
abort();
}
void
toku_do_assert_fail (const char *expr_as_string, const char *function, const char *file, int line, int caller_errno) {
fprintf(stderr, "%s:%d %s: Assertion `%s' failed (errno=%d)\n", file, line, function, expr_as_string, caller_errno);
toku_do_backtrace_abort();
}
abort();
void
toku_do_assert_zero_fail (uintptr_t expr, const char *expr_as_string, const char *function, const char *file, int line, int caller_errno) {
fprintf(stderr, "%s:%d %s: Assertion `%s == 0' failed (errno=%d) (%s=%"PRIuPTR")\n", file, line, function, expr_as_string, caller_errno, expr_as_string, expr);
toku_do_backtrace_abort();
}
void toku_do_assert(int expr,const char* expr_as_string,const char *function,const char*file,int line, int caller_errno) {
if (expr==0) {
toku_do_assert_fail(expr_as_string, function, file, line, caller_errno);
}
void
toku_do_assert(int expr, const char *expr_as_string, const char *function, const char* file, int line, int caller_errno) {
if (expr == 0)
toku_do_assert_fail(expr_as_string, function, file, line, caller_errno);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment