forked from xuos/xiuos
				
			23/08/02 1.Fix ByteManager Bug; 2.Move net delay to webnet(wn_session.h) so it wont affect other net functions.
This commit is contained in:
		
							parent
							
								
									fce13fe874
								
							
						
					
					
						commit
						ee10eccb26
					
				| 
						 | 
					@ -15,108 +15,6 @@
 | 
				
			||||||
// #include <user_api.h>
 | 
					// #include <user_api.h>
 | 
				
			||||||
#include <transform.h>
 | 
					#include <transform.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pthread_mutex_t* get_memtest_mtx() {
 | 
					 | 
				
			||||||
	static pthread_mutex_t mem_test_mtx;
 | 
					 | 
				
			||||||
	return &mem_test_mtx;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern void ShowMemory();
 | 
					 | 
				
			||||||
void malloc_thread(void* size)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    int tid = GetKTaskDescriptor()->id.id;
 | 
					 | 
				
			||||||
    int* tmp = (int*)size;
 | 
					 | 
				
			||||||
	int malloc_size = *tmp;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	PrivMutexObtain(get_memtest_mtx());
 | 
					 | 
				
			||||||
    printf("TID: %d Working. size: %d\n", tid, malloc_size);
 | 
					 | 
				
			||||||
	PrivMutexAbandon(get_memtest_mtx());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    void* ptr_allocated = NULL;
 | 
					 | 
				
			||||||
    while ((ptr_allocated = malloc(malloc_size)) != NULL) {
 | 
					 | 
				
			||||||
		PrivMutexObtain(get_memtest_mtx());
 | 
					 | 
				
			||||||
        printf("\n[TID: %d]==================================================\n", tid);
 | 
					 | 
				
			||||||
        ShowMemory();
 | 
					 | 
				
			||||||
		PrivMutexAbandon(get_memtest_mtx());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	PrivMutexObtain(get_memtest_mtx());
 | 
					 | 
				
			||||||
    printf("TID: %d Exiting.\n", tid);
 | 
					 | 
				
			||||||
	PrivMutexAbandon(get_memtest_mtx());
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <xs_ktask.h>
 | 
					 | 
				
			||||||
int testMemMain()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	PrivMutexCreate(get_memtest_mtx(), NULL);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    int malloc_size = 10 * 1024;
 | 
					 | 
				
			||||||
    int tid = KTaskCreate("mem1", malloc_thread, (void*)&malloc_size, 2048, 20);
 | 
					 | 
				
			||||||
    StartupKTask(tid);
 | 
					 | 
				
			||||||
	// malloc_thread(&malloc_size);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// void* ptr_allocated[5] = { NULL };
 | 
					 | 
				
			||||||
	// ptr_allocated[0] = malloc(malloc_size);
 | 
					 | 
				
			||||||
    // printf("0x%x ==================================================\n", ptr_allocated[0]);
 | 
					 | 
				
			||||||
	// ShowMemory();
 | 
					 | 
				
			||||||
	// ptr_allocated[1] = malloc(malloc_size);
 | 
					 | 
				
			||||||
    // printf("0x%x ==================================================\n", ptr_allocated[1]);
 | 
					 | 
				
			||||||
	// ShowMemory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // malloc_size = 996;
 | 
					 | 
				
			||||||
	// ptr_allocated[2] = malloc(malloc_size);
 | 
					 | 
				
			||||||
    // printf("0x%x ==================================================\n", ptr_allocated[2]);
 | 
					 | 
				
			||||||
	// ShowMemory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// free(ptr_allocated[0]);
 | 
					 | 
				
			||||||
    // printf("==================================================\n");
 | 
					 | 
				
			||||||
	// ShowMemory();
 | 
					 | 
				
			||||||
	// ptr_allocated[0] = malloc(malloc_size);
 | 
					 | 
				
			||||||
    // printf("0x%x ==================================================\n", ptr_allocated[0]);
 | 
					 | 
				
			||||||
	// ShowMemory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// ptr_allocated[3] = malloc(malloc_size);
 | 
					 | 
				
			||||||
	// free(ptr_allocated[2]);
 | 
					 | 
				
			||||||
    // printf("0x%x ==================================================\n", ptr_allocated[3]);
 | 
					 | 
				
			||||||
	// ShowMemory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// malloc_size = 333;
 | 
					 | 
				
			||||||
	// ptr_allocated[2] = malloc(malloc_size);
 | 
					 | 
				
			||||||
	// ptr_allocated[4] = malloc(malloc_size);
 | 
					 | 
				
			||||||
    // printf("0x%x ==================================================\n", ptr_allocated[2]);
 | 
					 | 
				
			||||||
    // printf("0x%x ==================================================\n", ptr_allocated[4]);
 | 
					 | 
				
			||||||
	// ShowMemory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// free(ptr_allocated[0]);
 | 
					 | 
				
			||||||
	// free(ptr_allocated[1]);
 | 
					 | 
				
			||||||
	// free(ptr_allocated[2]);
 | 
					 | 
				
			||||||
	// free(ptr_allocated[3]);
 | 
					 | 
				
			||||||
	// free(ptr_allocated[4]);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    int malloc_size2 = 1024;
 | 
					 | 
				
			||||||
    int tid2 = KTaskCreate("mem2", malloc_thread, &malloc_size2, 2048, 20);
 | 
					 | 
				
			||||||
    StartupKTask(tid2);
 | 
					 | 
				
			||||||
	// malloc_thread(&malloc_size);
 | 
					 | 
				
			||||||
    int malloc_size3 = 127;
 | 
					 | 
				
			||||||
    int tid3 = KTaskCreate("mem3", malloc_thread, &malloc_size3, 2048, 20);
 | 
					 | 
				
			||||||
    StartupKTask(tid3);
 | 
					 | 
				
			||||||
	// malloc_thread(&malloc_size);
 | 
					 | 
				
			||||||
	int malloc_size4 = 45;
 | 
					 | 
				
			||||||
    int tid4 = KTaskCreate("mem4", malloc_thread, &malloc_size4, 2048, 20);
 | 
					 | 
				
			||||||
    StartupKTask(tid4);
 | 
					 | 
				
			||||||
	// malloc_thread(&malloc_size);
 | 
					 | 
				
			||||||
    int malloc_size5 = 16;
 | 
					 | 
				
			||||||
    int tid5 = KTaskCreate("mem5", malloc_thread, &malloc_size5, 2048, 20);
 | 
					 | 
				
			||||||
    StartupKTask(tid5);
 | 
					 | 
				
			||||||
	// malloc_thread(&malloc_size);
 | 
					 | 
				
			||||||
	MdelayKTask(5000);
 | 
					 | 
				
			||||||
    return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC) | SHELL_CMD_PARAM_NUM(0),
 | 
					 | 
				
			||||||
    testMemMain, testMemMain, list memory usage information);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern int FrameworkInit();
 | 
					extern int FrameworkInit();
 | 
				
			||||||
extern void ApplicationOtaTaskInit(void);
 | 
					extern void ApplicationOtaTaskInit(void);
 | 
				
			||||||
int main(void)
 | 
					int main(void)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -793,7 +793,7 @@ void x_free(void *pointer)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, pointer)) {
 | 
					    if (!ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, pointer)) {
 | 
				
			||||||
		CriticalAreaUnLock(lock);
 | 
							CriticalAreaUnLock(lock);
 | 
				
			||||||
		SYS_ERR("[%s] Freeing a no allocated address.\n", __func__);
 | 
							SYS_ERR("[%s] Freeing a unallocated address.\n", __func__);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue