Example #1
0
    static NAN_METHOD(GetRootNode)
    {
      Nan::HandleScope scope;
      Device* output = Nan::ObjectWrap::Unwrap<Device>(info.This());

      v8::Local<v8::Function> cons = Nan::New(Node::constructor());
      v8::Local<v8::Value> argv[1] = {from_pointer(&output->m_dev.get_root_node()).ToLocalChecked()};
      info.GetReturnValue().Set(Nan::NewInstance(cons, 1, argv).ToLocalChecked());
    }
Example #2
0
/**
** free() frees the memory space pointed to by ptr, which must have been returned by a previous call  to  malloc() or
** realloc().   Otherwise,  or if free(ptr) has already been called before, undefined behavior occurs.  If ptr is NULL, no opera‐
** tion is performed.
*/
extern void bitmap_heap_free(void* pointer)
{
	int32_t block=(-1);
	int32_t used;
	int lvl = caribou_lib_lock();
	/** Search each heap... */
	for(heap_num=0; heap_num < heap_count; heap_num++)
	{
		if ( (block = from_pointer(HEAP_STATE(heap_num),pointer)) >= 0 )
		{
        	used = blocks_used(HEAP_STATE(heap_num),block);
			deallocate(HEAP_STATE(heap_num),block,used);
			break;
		}
	}
	if ( block < 0 )
	{
		notify_heap_invalid_dealloc(pointer);
	}
	caribou_lib_lock_restore(lvl);
}
Example #3
0
/**
 ** @brief Return the size of memory associated with pointer.
 */
extern size_t bitmap_heap_sizeof(void* pointer)
{
	size_t rc=0;
	if ( pointer )
	{
		int lvl = caribou_lib_lock();
		for(heap_num=0; heap_num < heap_count; heap_num++)
		{
			int32_t block;
			int32_t used;
			block = from_pointer(HEAP_STATE(heap_num),pointer);
			if ( block >= 0 )
			{
				rc = blocks_used(HEAP_STATE(heap_num),block) * HEAP_BLOCK_SIZE;
				break;
			}
		}
		caribou_lib_lock_restore(lvl);
	}
	return rc;
}
Example #4
0
/**
** realloc() changes the size of the memory block pointed to by ptr to size bytes.  The contents will be unchanged to the minimum
** of  the  old and new sizes; newly allocated memory will be uninitialized.  If ptr is NULL, then the call is equivalent to mal‐
** loc(size), for all values of size; if size is equal to zero, and ptr is not NULL, then the call is  equivalent  to  free(ptr).
** Unless  ptr is NULL, it must have been returned by an earlier call to malloc() or realloc().  If the area pointed to
** was moved, a free(ptr) is done.
*/
extern void* bitmap_heap_realloc(void* pointer, size_t size)
{
	if (pointer != NULL && size > 0 )
	{
		int32_t blocks = to_blocks(size);
		int32_t block=(-1);
		int32_t used;
		int lvl = caribou_lib_lock();
		/** Search each heap... */
		for(heap_num=0; heap_num < heap_count; heap_num++)
		{
			block = from_pointer(HEAP_STATE(heap_num),pointer);
			if ( block >= 0 )
				break;
		}
		if ( block >= 0 )
		{
			used = blocks_used(HEAP_STATE(heap_num),block);
			if (blocks > used)
			{
				if (!extend(HEAP_STATE(heap_num),block,used,blocks-used))         /* attempt to extend existing block */
				{
					int32_t target;
					deallocate(HEAP_STATE(heap_num),block,used);                  /* make currently allocated blocks available to be re-allocated.. */
					#if defined(CARIBOU_MPU_ENABLED)
						heap_state->heap_current_thread = caribou_thread_current();
					#endif
					target = locate_free(HEAP_STATE(heap_num),blocks);            /* ...then attempts to locate a sequence of free blocks... */
					if (target >= 0 )
					{
						void* pTarget = allocate(HEAP_STATE(heap_num),target,blocks);	/* allocate the new blocks... */
						memmove(pTarget,pointer,used*HEAP_BLOCK_SIZE);			/* ...and move the data to the new area. */
						pointer = pTarget;
					}
					else
					{
						/* 
						 * The re-allocation failed in the current heap pool. 
						 * It may be possible to get a fit in another pool. 
						 */
						void* pTarget;
						if ( (pTarget = bitmap_heap_malloc(size)) != NULL )
						{
							memmove(pTarget,pointer,used*HEAP_BLOCK_SIZE);
							pointer = pTarget;
						}
						else
						{
							notify_heap_invalid_realloc(pointer,size);
							pointer = NULL;
						}
					}
				}
			}
			else if (blocks < used)
			{
				/* shrink the allocation */
				deallocate(HEAP_STATE(heap_num),block,used);
				allocate(HEAP_STATE(heap_num),block,blocks);
			}
		}
		else
		{
			notify_heap_invalid_realloc(pointer,size);
			pointer = NULL;
		}
		caribou_lib_lock_restore(lvl);
	}
	else if (pointer != NULL && size == 0)
	{
		bitmap_heap_free(pointer);
		pointer=NULL;
	}
	else if (pointer == NULL )
	{
		pointer = bitmap_heap_malloc(size);
	}
	return pointer;
}