Ejemplo n.º 1
0
int main()
{
    {
        std::unique_ptr<B> bptr(new B);
        std::unique_ptr<A> aptr(new A);
        testAssign(aptr, bptr);
    }
    assert(A::count == 0);
    assert(B::count == 0);
    {
        Deleter<B> del(42);
        std::unique_ptr<B, Deleter<B> > bptr(new B, std::move(del));
        std::unique_ptr<A, Deleter<A> > aptr(new A);
        testAssign(aptr, bptr);
        checkDeleter(aptr, bptr, 42, 0);
    }
    assert(A::count == 0);
    assert(B::count == 0);
    {
        CDeleter<A> adel(6);
        CDeleter<B> bdel(42);
        std::unique_ptr<B, CDeleter<B>&> bptr(new B, bdel);
        std::unique_ptr<A, CDeleter<A>&> aptr(new A, adel);
        testAssign(aptr, bptr);
        checkDeleter(aptr, bptr, 42, 42);
    }
    assert(A::count == 0);
    assert(B::count == 0);
}
Ejemplo n.º 2
0
    blob binary_writer::get_current_buffer()
    {
        if (_buffers.size() == 1)
        {
            return _current_offset > 0 ? _buffers[0].range(0, _current_offset) : _buffers[0];
        }
        else
        {
            std::shared_ptr<char> bptr(new char[_total_size]);
            blob bb(bptr, _total_size);
            const char* ptr = bb.data();

            for (int i = 0; i < static_cast<int>(_buffers.size()); i++)
            {
                size_t len = (size_t)_buffers[i].length();
                if (_current_offset > 0 && i + 1 == (int)_buffers.size())
                {
                    len = _current_offset;
                }

                memcpy((void*)ptr, (const void*)_buffers[i].data(), len);
                ptr += _buffers[i].length();
            }
            return bb;
        }
    }
Ejemplo n.º 3
0
/*!\fn void WRATHglGet(GLenum, bool*)
  Overloaded C++ version of glGet* family
  of functions in GL. Equivalent to
  glGetBooleanv(v, ptr).

  \param v GL enumeration to fetch
  \param ptr address to write values to.
 */
inline
void
WRATHglGet(GLenum v, bool *ptr)
{
  GLboolean bptr( *ptr?GL_TRUE:GL_FALSE);
  glGetBooleanv(v, &bptr);
  *ptr=(bptr==GL_FALSE)?
    false:
    true;
}
Ejemplo n.º 4
0
/* only need to run this during conversion since
 * m_map_blender_to_gameobject is freed after conversion */
void KX_BlenderSceneConverter::UnregisterGameObject(KX_GameObject *gameobject) 
{
	Object *bobp = gameobject->GetBlenderObject();
	if (bobp) {
		CHashedPtr bptr(bobp);
		KX_GameObject **gobp = m_map_blender_to_gameobject[bptr];
		if (gobp && *gobp == gameobject) {
			// also maintain m_map_blender_to_gameobject if the gameobject
			// being removed is matching the blender object
			m_map_blender_to_gameobject.remove(bptr);
		}
	}
}
Ejemplo n.º 5
0
unsigned long
minixfs_count_free_inodes ()
{
  unsigned long bitmap_count;

  /*spin_lock (&global_lock);*/

  bitmap_count = count_free (bptr (I_MAP_BOFFS),
			     sblock->s_imap_blocks << log2_block_size);

  /*spin_unlock (&global_lock);*/

  return bitmap_count;
}
Ejemplo n.º 6
0
ino_t
minixfs_new_inode (void)
{
  char *bh = bptr (I_MAP_BOFFS);
  ino_t inum;
  unsigned long bits = sblock->s_ninodes;

  spin_lock (&global_lock);

 repeat:
  inum = find_first_zero_bit ((unsigned long *) bh, bits);
  if (inum < bits)
    {
      assert (sblock_info->s_free_inodes_count > 0);
      minixfs_debug ("eligible bit found at position %Lu", inum);

      if (set_bit (inum, bh))
	{
	  /* shouldn't happen */
	  minixfs_warning ("bit already set for inode %Lu", inum);
	  goto repeat;
	}
      record_global_poke (bh);
    }
  else
    {
      assert (sblock_info->s_free_inodes_count == 0);
      minixfs_debug ("no more free inodes");
      inum = 0;
      goto sync_out;
    }

  if (inum < MINIXFS_FIRST_INO)
    {
      minixfs_error ("reserved inode");
      inum = 0;
      goto sync_out;
    }

  sblock_info->s_free_inodes_count--;

 sync_out:
  spin_unlock (&global_lock);
  alloc_sync (0);

  return inum;
}
Ejemplo n.º 7
0
    blob binary_writer::get_buffer() const
    {
        if (_data.size() == 1)
        {
            return _data[0];
        }
        else
        {
            std::shared_ptr<char> bptr((char*)malloc(_total_size));
            blob bb(bptr, _total_size);
            const char* ptr = bb.data();

            for (int i = 0; i < static_cast<int>(_data.size()); i++)
            {
                memcpy((void*)ptr, (const void*)_data[i].data(), (size_t)_data[i].length());
                ptr += _data[i].length();
            }
            return bb;
        }
    }
Ejemplo n.º 8
0
/* Free node NP; the on disk copy has already been synced with
   diskfs_node_update (where NP->dn_stat.st_mode was 0).  Its
   mode used to be OLD_MODE.  */
void
diskfs_free_node (struct node *np, mode_t old_mode)
{
  char *bh;
  ino_t inum = np->cache_id;
  block_t imap_block;

  assert (!diskfs_readonly);

  spin_lock (&global_lock);

  if (inum < MINIXFS_FIRST_INO || inum > sblock->s_ninodes)
    {
      minixfs_error ("trying to free a reserved or nonexistent inode: %Lu",
		     inum);
      spin_unlock (&global_lock);
      return;
    }

  minixfs_debug ("freeing inode %Lu", inum);

  imap_block = inum >> LOG2_BITS_PER_BLOCK;
  if (imap_block >= sblock->s_imap_blocks) 
    {
      minixfs_error ("nonexistent imap in superblock: %u", imap_block);
      spin_unlock (&global_lock);
      return;
    }
  
  bh = bptr (I_MAP_BOFFS + imap_block);
  if (! clear_bit (inum & (BITS_PER_BLOCK - 1), bh))
    minixfs_warning ("bit already cleared for inode %Lu", inum);
  else
    {
      record_global_poke (bh);
      sblock_info->s_free_inodes_count++;
    }

  spin_unlock (&global_lock);
  alloc_sync (0);
}
Ejemplo n.º 9
0
    blob binary_writer::get_buffer()
    {
        commit();
        if (_buffers.size() == 1)
        {
            return _buffers[0];
        }
        else
        {
            std::shared_ptr<char> bptr(new char[_total_size]);
            blob bb(bptr, _total_size);
            const char* ptr = bb.data();

            for (int i = 0; i < static_cast<int>(_buffers.size()); i++)
            {
                memcpy((void*)ptr, (const void*)_buffers[i].data(), (size_t)_buffers[i].length());
                ptr += _buffers[i].length();
            }
            return bb;
        }
    }
Ejemplo n.º 10
0
    void TripleBandLinearOp::axpyb(const Array& a,
                                   const TripleBandLinearOp& x,
                                   const TripleBandLinearOp& y,
                                   const Array& b) {
        const Size size = mesher_->layout()->size();

        Real *diag(diag_.get());
        Real *lower(lower_.get());
        Real *upper(upper_.get());

        const Real *y_diag (y.diag_.get());
        const Real *y_lower(y.lower_.get());
        const Real *y_upper(y.upper_.get());

        if (a.empty()) {
            if (b.empty()) {
                //#pragma omp parallel for
                for (Size i=0; i < size; ++i) {
                    diag[i]  = y_diag[i];
                    lower[i] = y_lower[i];
                    upper[i] = y_upper[i];
                }
            }
            else {
                Array::const_iterator bptr(b.begin());
                const Size binc = (b.size() > 1) ? 1 : 0;
                //#pragma omp parallel for
                for (Size i=0; i < size; ++i) {
                    diag[i]  = y_diag[i] + bptr[i*binc];
                    lower[i] = y_lower[i];
                    upper[i] = y_upper[i];
                }
            }
        }
        else if (b.empty()) {
            Array::const_iterator aptr(a.begin());
            const Size ainc = (a.size() > 1) ? 1 : 0;

            const Real *x_diag (x.diag_.get());
            const Real *x_lower(x.lower_.get());
            const Real *x_upper(x.upper_.get());

            //#pragma omp parallel for
            for (Size i=0; i < size; ++i) {
                const Real s = aptr[i*ainc];
                diag[i]  = y_diag[i]  + s*x_diag[i];
                lower[i] = y_lower[i] + s*x_lower[i];
                upper[i] = y_upper[i] + s*x_upper[i];
            }
        }
        else {
            Array::const_iterator bptr(b.begin());
            const Size binc = (b.size() > 1) ? 1 : 0;

            Array::const_iterator aptr(a.begin());
            const Size ainc = (a.size() > 1) ? 1 : 0;

            const Real *x_diag (x.diag_.get());
            const Real *x_lower(x.lower_.get());
            const Real *x_upper(x.upper_.get());

            //#pragma omp parallel for
            for (Size i=0; i < size; ++i) {
                const Real s = aptr[i*ainc];
                diag[i]  = y_diag[i]  + s*x_diag[i] + bptr[i*binc];
                lower[i] = y_lower[i] + s*x_lower[i];
                upper[i] = y_upper[i] + s*x_upper[i];
            }
        }
    }