本文整理汇总了C++中eassert函数的典型用法代码示例。如果您正苦于以下问题:C++ eassert函数的具体用法?C++ eassert怎么用?C++ eassert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了eassert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: queue_get
int queue_get(void *que,uint32_t *id,uint32_t *op,uint8_t **data,uint32_t *leng) {
queue *q = (queue*)que;
qentry *qe;
eassert(pthread_mutex_lock(&(q->lock))==0);
while (q->elements==0) {
q->freewaiting++;
eassert(pthread_cond_wait(&(q->waitfree),&(q->lock))==0);
}
qe = q->head;
q->head = qe->next;
if (q->head==NULL) {
q->tail = &(q->head);
}
q->elements--;
q->size -= qe->leng;
if (q->fullwaiting>0) {
eassert(pthread_cond_signal(&(q->waitfull))==0);
q->fullwaiting--;
}
eassert(pthread_mutex_unlock(&(q->lock))==0);
if (id) {
*id = qe->id;
}
if (op) {
*op = qe->op;
}
if (data) {
*data = qe->data;
}
if (leng) {
*leng = qe->leng;
}
free(qe);
return 0;
}
示例2: evict_lower_half
static void evict_lower_half (log_t *log)
{
ptrdiff_t size = ASIZE (log->key_and_value) / 2;
EMACS_INT median = approximate_median (log, 0, size);
ptrdiff_t i;
for (i = 0; i < size; i++)
/* Evict not only values smaller but also values equal to the median,
so as to make sure we evict something no matter what. */
if (XINT (HASH_VALUE (log, i)) <= median)
{
Lisp_Object key = HASH_KEY (log, i);
{ /* FIXME: we could make this more efficient. */
Lisp_Object tmp;
XSET_HASH_TABLE (tmp, log); /* FIXME: Use make_lisp_ptr. */
Fremhash (key, tmp);
}
eassert (EQ (log->next_free, make_number (i)));
{
int j;
eassert (VECTORP (key));
for (j = 0; j < ASIZE (key); j++)
ASET (key, j, Qnil);
}
set_hash_key_slot (log, i, key);
}
}
示例3: module_copy_string_contents
static bool
module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer,
ptrdiff_t *length)
{
MODULE_FUNCTION_BEGIN (false);
Lisp_Object lisp_str = value_to_lisp (value);
CHECK_STRING (lisp_str);
Lisp_Object lisp_str_utf8 = ENCODE_UTF_8 (lisp_str);
ptrdiff_t raw_size = SBYTES (lisp_str_utf8);
ptrdiff_t required_buf_size = raw_size + 1;
eassert (length != NULL);
if (buffer == NULL)
{
*length = required_buf_size;
return true;
}
eassert (*length >= 0);
if (*length < required_buf_size)
{
*length = required_buf_size;
xsignal0 (Qargs_out_of_range);
}
*length = required_buf_size;
memcpy (buffer, SDATA (lisp_str_utf8), raw_size + 1);
return true;
}
示例4: handle_profiler_signal
static void
handle_profiler_signal (int signal)
{
if (EQ (backtrace_top_function (), Qautomatic_gc))
/* Special case the time-count inside GC because the hash-table
code is not prepared to be used while the GC is running.
More specifically it uses ASIZE at many places where it does
not expect the ARRAY_MARK_FLAG to be set. We could try and
harden the hash-table code, but it doesn't seem worth the
effort. */
cpu_gc_count = saturated_add (cpu_gc_count, 1);
else
{
EMACS_INT count = 1;
#ifdef HAVE_ITIMERSPEC
if (profiler_timer_ok)
{
int overruns = timer_getoverrun (profiler_timer);
eassert (overruns >= 0);
count += overruns;
}
#endif
eassert (HASH_TABLE_P (cpu_log));
record_backtrace (XHASH_TABLE (cpu_log), count);
}
}
示例5: queue_tryput
int queue_tryput(void *que,uint32_t id,uint32_t op,uint8_t *data,uint32_t leng) {
queue *q = (queue*)que;
qentry *qe;
eassert(pthread_mutex_lock(&(q->lock))==0);
if (q->maxsize) {
if (leng>q->maxsize) {
eassert(pthread_mutex_unlock(&(q->lock))==0);
errno = EDEADLK;
return -1;
}
if (q->size+leng>q->maxsize) {
eassert(pthread_mutex_unlock(&(q->lock))==0);
errno = EBUSY;
return -1;
}
}
qe = malloc(sizeof(qentry));
passert(qe);
qe->id = id;
qe->op = op;
qe->data = data;
qe->leng = leng;
qe->next = NULL;
q->elements++;
q->size += leng;
*(q->tail) = qe;
q->tail = &(qe->next);
if (q->freewaiting>0) {
eassert(pthread_cond_signal(&(q->waitfree))==0);
q->freewaiting--;
}
eassert(pthread_mutex_unlock(&(q->lock))==0);
return 0;
}
示例6: queue_elements
uint32_t queue_elements(void *que) {
queue *q = (queue*)que;
uint32_t r;
eassert(pthread_mutex_lock(&(q->lock))==0);
r=q->elements;
eassert(pthread_mutex_unlock(&(q->lock))==0);
return r;
}
示例7: queue_isfull
int queue_isfull(void *que) {
queue *q = (queue*)que;
int r;
eassert(pthread_mutex_lock(&(q->lock))==0);
r = (q->maxsize>0 && q->maxsize<=q->size)?1:0;
eassert(pthread_mutex_unlock(&(q->lock))==0);
return r;
}
示例8: queue_isempty
int queue_isempty(void *que) {
queue *q = (queue*)que;
int r;
eassert(pthread_mutex_lock(&(q->lock))==0);
r=(q->elements==0)?1:0;
eassert(pthread_mutex_unlock(&(q->lock))==0);
return r;
}
示例9: record_backtrace
static void
record_backtrace (log_t *log, EMACS_INT count)
{
Lisp_Object backtrace;
ptrdiff_t index;
if (!INTEGERP (log->next_free))
/* FIXME: transfer the evicted counts to a special entry rather
than dropping them on the floor. */
evict_lower_half (log);
index = XINT (log->next_free);
/* Get a "working memory" vector. */
backtrace = HASH_KEY (log, index);
get_backtrace (backtrace);
{ /* We basically do a `gethash+puthash' here, except that we have to be
careful to avoid memory allocation since we're in a signal
handler, and we optimize the code to try and avoid computing the
hash+lookup twice. See fns.c:Fputhash for reference. */
EMACS_UINT hash;
ptrdiff_t j = hash_lookup (log, backtrace, &hash);
if (j >= 0)
{
EMACS_INT old_val = XINT (HASH_VALUE (log, j));
EMACS_INT new_val = saturated_add (old_val, count);
set_hash_value_slot (log, j, make_number (new_val));
}
else
{ /* BEWARE! hash_put in general can allocate memory.
But currently it only does that if log->next_free is nil. */
int j;
eassert (!NILP (log->next_free));
j = hash_put (log, backtrace, make_number (count), hash);
/* Let's make sure we've put `backtrace' right where it
already was to start with. */
eassert (index == j);
/* FIXME: If the hash-table is almost full, we should set
some global flag so that some Elisp code can offload its
data elsewhere, so as to avoid the eviction code.
There are 2 ways to do that, AFAICT:
- Set a flag checked in QUIT, such that QUIT can then call
Fprofiler_cpu_log and stash the full log for later use.
- Set a flag check in post-gc-hook, so that Elisp code can call
profiler-cpu-log. That gives us more flexibility since that
Elisp code can then do all kinds of fun stuff like write
the log to disk. Or turn it right away into a call tree.
Of course, using Elisp is generally preferable, but it may
take longer until we get a chance to run the Elisp code, so
there's more risk that the table will get full before we
get there. */
}
}
}
示例10: _params
ImageMask2d::ImageMask2d(Image<float> *image, Mask2d *mask2d, ExamenParams *params) :
_params(params)
{
eassert(image->getWidth() == mask2d->getWidth());
eassert(image->getHeight() == mask2d->getHeight());
_img = image;
_mask = mask2d;
eassert(_img != NULL);
eassert(_mask != NULL);
eassert(_params != NULL);
}
示例11: queue_sizeleft
uint32_t queue_sizeleft(void *que) {
queue *q = (queue*)que;
uint32_t r;
eassert(pthread_mutex_lock(&(q->lock))==0);
if (q->maxsize>0) {
r = q->maxsize-q->size;
} else {
r = 0xFFFFFFFF;
}
eassert(pthread_mutex_unlock(&(q->lock))==0);
return r;
}
示例12: approximate_median
static EMACS_INT approximate_median (log_t *log,
ptrdiff_t start, ptrdiff_t size)
{
eassert (size > 0);
if (size < 2)
return XINT (HASH_VALUE (log, start));
if (size < 3)
/* Not an actual median, but better for our application than
choosing either of the two numbers. */
return ((XINT (HASH_VALUE (log, start))
+ XINT (HASH_VALUE (log, start + 1)))
/ 2);
else
{
ptrdiff_t newsize = size / 3;
ptrdiff_t start2 = start + newsize;
EMACS_INT i1 = approximate_median (log, start, newsize);
EMACS_INT i2 = approximate_median (log, start2, newsize);
EMACS_INT i3 = approximate_median (log, start2 + newsize,
size - 2 * newsize);
return (i1 < i2
? (i2 < i3 ? i2 : (i1 < i3 ? i3 : i1))
: (i1 < i3 ? i1 : (i2 < i3 ? i3 : i2)));
}
}
示例13: makeExhaustiveTrainer
std::shared_ptr< ExhaustiveLPOModelTrainer > makeExhaustiveTrainer( const ExhaustiveLPOModel & that, const std::vector< std::shared_ptr< ImageOverSegmentation > >& ios, const std::vector< T >& gt ) {
std::string name = typeStr(that);
std::vector< VectorXf > params = that.all_params_;
const int N = ios.size(), M = params.size();
std::vector<int> oid( gt.size()+1 );
std::transform( gt.begin(), gt.end(), oid.data()+1, static_cast<int(*)(const T&)>(&no) );
std::partial_sum( oid.begin(), oid.end(), oid.begin() );
std::vector< float > avg_prop( params.size(), 0. );
std::vector< std::vector< float > > iou( params.size(), std::vector< float >(oid.back(),0.f) );
#pragma omp parallel for
for( int i=0; i<N; i++ ) {
std::vector<Proposals> s = that.generateProposals( *ios[i], params );
for( int j=0; j<M; j++ ) {
Proposals p = s[j];
SegmentationOverlap o(p.s, gt[i]);
const int no = o.nObjects();
eassert( oid[i]+no == oid[i+1] );
auto best_iou = VectorXf::Map(iou[j].data()+oid[i],no);
int n = p.p.rows();
for( int k=0; k<n; k++ )
best_iou = best_iou.array().max( o.iou( p.p.row(k) ).array() );
#pragma omp atomic
avg_prop[j] += 1.0 * n / N;
}
}
return std::make_shared<ExhaustiveLPOModelTrainerImplementation>( name, params, iou, avg_prop );
}
示例14: eassert
RowVectorXf operator*(const RowVectorXf& o, const SeedFeature& f) {
eassert( o.size() == f.static_f_.rows() );
RowVectorXf r( f.static_f_.cols() + f.dynamic_f_.cols() );
r.head(f.static_f_.cols()) = o * f.static_f_;
r.tail(f.dynamic_f_.cols()) = o * f.dynamic_f_;
return r;
}
示例15: free_before_dump
void
free_before_dump (void *ptr)
{
if (!ptr)
return;
/* Before dumping. */
if (dumped_data < (unsigned char *)ptr
&& (unsigned char *)ptr < bc_limit)
{
/* Free the block if it is allocated in the private heap. */
HeapFree (heap, 0, ptr);
}
else
{
/* Look for the big chunk. */
int i;
for (i = 0; i < blocks_number; i++)
{
if (blocks[i].address == ptr)
{
/* Reset block occupation if found. */
blocks[i].occupied = 0;
break;
}
/* What if the block is not found? We should trigger an
error here. */
eassert (i < blocks_number);
}
}
}