optimize code standards

This commit is contained in:
Liu_Weichao
2021-04-29 12:55:01 +08:00
parent 34383bdcde
commit b4e108d620
29 changed files with 116 additions and 142 deletions
+18 -24
View File
@@ -22,14 +22,14 @@ class Animal //parent class
public:
virtual void eat()
virtual void Eat()
{
KPrintf("eat\n");
}
void sleep()
void Sleep()
{
KPrintf("sleep\n");
}
@@ -42,7 +42,7 @@ class Fish :public Animal //subclass
public:
void eat()
void Eat()
{
KPrintf("fish eat\n");
@@ -50,33 +50,28 @@ public:
}
};
void doeat(Animal& animal)
void Doeat(Animal& animal)
{
animal.eat();
animal.Eat();
}
void mem_test2()
void MemTest2()
{
int i;
char *ptr = NULL; /* memory pointer */
for (i = 0; ; i++)
{
for (i = 0; ; i++) {
/* allocate (1<<i) bytes memory every single time */
ptr = (char *)operator new(1 << i);
/* if allocate successfully */
if (ptr != NULL)
{
if (ptr != NULL) {
KPrintf("get memory :%d byte\n", (1 << i));
/* release the memory */
operator delete(ptr);
KPrintf("free memory :%d byte\n", (1 << i));
ptr = NULL;
}
else
{
} else {
KPrintf("try to get %d byte memory failed!\n", (1 << i));
break;
//return 0;
@@ -85,17 +80,18 @@ void mem_test2()
}
void overload_test(int a)
void OverLoadTest(int a)
{
KPrintf("output is a int number: %d\n", a);
}
void overload_test(int a,int b )
void OverLoadTestDouble(int a,int b )
{
KPrintf("output is 2 int number: %d and %d\n", a,b);
}
template<typename T>
void myswap(T& a, T& b)
void MySwap(T& a, T& b)
{
T temp = a;
a = b;
@@ -104,19 +100,17 @@ void myswap(T& a, T& b)
extern "C" int cppmain(void)
{
mem_test2();
MemTest2();
class Fish fish;
doeat(fish);
Doeat(fish);
int a = 3;
int b = 5;
void overload_test(int a, int b);
overload_test(a, b);
myswap(a,b);
void OverLoadTestDouble(int a, int b);
OverLoadTestDouble(a, b);
MySwap(a,b);
KPrintf("with template the output is: %d and %d\n", a,b);
return 0;
}
+1 -1
View File
@@ -25,7 +25,7 @@
* @description: Read a PM1.0
* @return 0
*/
void Pm1_0Ps5308(void)
void Pm10Ps5308(void)
{
struct SensorQuantity *pm1_0 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM1_0, SENSOR_QUANTITY_PM);
SensorQuantityOpen(pm1_0);
@@ -26,7 +26,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
{
int ret ;
int pid ;
utask_x task ;
UtaskType task ;
task.func_entry = start_routine ;
task.func_param = arg ;
memcpy(task.name , "utask", 6);
+4 -4
View File
@@ -56,11 +56,11 @@ struct utask
int32_t stack_size;
uint8_t prio;
};
typedef struct utask utask_x;
typedef struct utask UtaskType;
typedef void DIR;
int32_t UserTaskCreate(utask_x utask);
int32_t UserTaskCreate(UtaskType utask);
x_err_t UserTaskStartup(int32_t id);
x_err_t UserTaskDelete(int32_t id);
@@ -178,8 +178,8 @@ struct utask
int32_t stack_size;
uint8_t prio;
};
typedef struct utask utask_x;
int32_t UserTaskCreate(utask_x utask);
typedef struct utask UtaskType;
int32_t UserTaskCreate(UtaskType utask);
#define UserTaskStartup StartupKTask
#define UserTaskDelete KTaskDelete
+1 -1
View File
@@ -34,7 +34,7 @@
*
* @return EOK on success; ENOMEMORY/EEMPTY on failure
*/
int32_t UserTaskCreate(utask_x utask){
int32_t UserTaskCreate(UtaskType utask){
return (int32_t) KSwitch5(KS_USER_TASK_CREATE,(uintptr_t)utask.name,(uintptr_t)utask.func_entry,(uintptr_t)utask.func_param,(uintptr_t)utask.stack_size,(uintptr_t)utask.prio);
}