Esempio n. 1
0
static Mem_Desc * new_Mem_Desc()
{
	Mem_Desc * newbuffer = NULL;
	if (tm->freelist)
	{
		newbuffer = tm->freelist;
		tm->freelist = newbuffer->next;
		return newbuffer;
	}
	if (tm->allocatednum)
		tm->allocatednum <<=1;
	else
		tm->allocatednum = 1000;
	if ((newbuffer = (Mem_Desc *)fsl_osal_malloc_new(sizeof(Mem_Desc)*tm->allocatednum)) != NULL)
	{
		Mem_Desc *oldhead, *nb;
		fsl_osal_u32 i = 0;

		oldhead = tm->head;
		nb = newbuffer;
		tm->freelist = tm->head = tm->tail = NULL;
		for (i=0; i<(tm->allocatednum-1); i++)
		{
			if (oldhead)
			{
				COPYMEMORYDESC(nb, oldhead);
				nb->next = NULL;
				if (tm->tail)
				{
					(tm->tail)->next = nb;
					tm->tail = nb;
				}
				else
				{
					tm->head = tm->tail = nb;
				}
				oldhead = oldhead->next;
			}
			else
			{
				nb->next = tm->freelist;
				tm->freelist = nb;
			}
			nb++;
		}
		if (tm->allocatedbuffer)
		{
			fsl_osal_dealloc(tm->allocatedbuffer);
		}
		tm->allocatedbuffer = newbuffer;
		return nb;
	}
	else
	{
		return newbuffer;
	}
}
Esempio n. 2
0
fsl_osal_void deinit_memmanager()
{
	printandfree_allnonfreememory(tm);
	if (tm->allocatedbuffer)
	{
		fsl_osal_dealloc(tm->allocatedbuffer);
	}
	fsl_osal_memset(tm, 0, sizeof(Mem_Mgr));
}
/*! De-initializes and Releases the mutex object.
 *
 *	@param [in] sync_obj
 *		The mutex object
 *	@return efsl_osal_return_type_t
 *		E_FSL_OSAL_SUCCESS if success
 *		E_FSL_OSAL_INVALIDPARAM if paramter is invalid
 */
efsl_osal_return_type_t fsl_osal_mutex_destroy(fsl_osal_mutex sync_obj)
 {

 	if (pthread_mutex_destroy((pthread_mutex_t *)sync_obj) != 0)
 	{
 		LOG_ERROR("\n Error in destroying mutex.");
 		return E_FSL_OSAL_INVALIDPARAM ;
 	}

 	fsl_osal_dealloc(sync_obj);

 	return E_FSL_OSAL_SUCCESS;
 }
efsl_osal_return_type_t fsl_osal_sem_destroy(fsl_osal_sem sem_obj)
{
#ifdef ANDROID_BUILD
	/* workaround for android semaphore usage */
	fsl_osal_sem_post(sem_obj);
#endif

	if (sem_destroy((sem_t *)sem_obj) != 0)
	{
		LOG_ERROR("\n Error in destroying semaphore.");
		return E_FSL_OSAL_INVALIDPARAM ;
	}

	fsl_osal_dealloc(sem_obj);
	return E_FSL_OSAL_SUCCESS;
}
Esempio n. 5
0
fsl_osal_void dbg_free(fsl_osal_ptr mem)
{
	Mem_Desc * bt = tm->head, *btpr = NULL;
	fsl_osal_ptr ptr = mem;
	fsl_osal_s32 size = 0;
	while(bt)
	{
		if (bt->mem==mem)
		{
			size = bt->size;
#ifdef MEM_CHECK_BOARDER
			check_mem_boarder(bt);
			mem = (fsl_osal_ptr)((fsl_osal_u32)mem-PRE_SIZE);
			size -= PRE_SIZE + AFT_SIZE;
#endif
			tm->size-=bt->size;
			fsl_osal_memset(ptr, 0, size);
			fsl_osal_dealloc(mem);
			if (btpr)
			{
				btpr->next = bt->next;
				if (tm->tail==bt)
				{
					tm->tail = btpr;
				}
			}
			else  //head
			{
				tm->head = bt->next;
				if (tm->head==NULL)
				{
					tm->tail = NULL;
				}
			}
			bt->next = tm->freelist;
			tm->freelist = bt;
			return;
		}
		btpr = bt;
		bt=bt->next;
	}
	printf("%s Error memory freed pointer  = %p\n",tm->shortname, mem);
}
Esempio n. 6
0
fsl_osal_ptr dbg_malloc(fsl_osal_u32 size, fsl_osal_char * desc, fsl_osal_s32 line)
{
	Mem_Desc * bt;
	fsl_osal_ptr buf = NULL;

#ifdef MEM_CHECK_BOARDER
	fsl_osal_ptr ptr = NULL;
	fsl_osal_s32 size1 = size;

	size += PRE_SIZE + AFT_SIZE;
#endif

	if ((buf = fsl_osal_malloc_new(size)) && (bt = new_Mem_Desc()))
	{
		tm->age++;
		tm->size+=size;
		if (tm->size>tm->maxsize)
		{
			tm->maxsize = tm->size;
			//printf("%s: mem exceed %ld bytes\n", tm->shortname, tm->maxsize);
		}

#ifdef MEM_CHECK_BOARDER
		fsl_osal_memset(buf, MAGICNUMBER, PRE_SIZE);
		ptr = (fsl_osal_ptr)((fsl_osal_u32)buf + PRE_SIZE + size1);
		fsl_osal_memset(ptr, MAGICNUMBER, AFT_SIZE);
		buf = (fsl_osal_ptr)((fsl_osal_u32)buf + PRE_SIZE);
#endif

		bt->size = size;
		bt->age = tm->age;
		bt->mem = buf;
		bt->line = line;
		bt->next = NULL;

		fsl_osal_memcpy(bt->desstring, desc, STR_LEN);
		bt->desstring[STR_LEN-1] = '\0';
		//printf("age: %d, in %s:%d allocate %p, size %d.\n",bt->age, desc, bt->line, (fsl_osal_s32)buf, size);

		if (tm->tail)
		{
			(tm->tail)->next = bt;
			tm->tail = bt;
		}
		else
		{
			tm->head = tm->tail = bt;
		}
	}
	else
	{
		if (buf)
		{
			fsl_osal_dealloc(buf);
			buf = NULL;
		}
		else
		{
			printf("%s: FATAL ERROR - Can not allocate %ld bytes\n", tm->shortname, size);
		}
		printf("FATAL ERROR: Can not allocate memory for memmanager!!\n");
	}

	return buf;
}