提交 2ada41c8 编写于 作者: L lcjh

分支优化

去除不必要分支,使用三元操作符优化简单分支
Signed-off-by: Nlcjh <120989324@qq.com>
上级 9b397173
...@@ -154,20 +154,12 @@ STATIC UINT32 ConsoleRefcountGet(const CONSOLE_CB *consoleCB) ...@@ -154,20 +154,12 @@ STATIC UINT32 ConsoleRefcountGet(const CONSOLE_CB *consoleCB)
STATIC VOID ConsoleRefcountSet(CONSOLE_CB *consoleCB, BOOL flag) STATIC VOID ConsoleRefcountSet(CONSOLE_CB *consoleCB, BOOL flag)
{ {
if (flag == TRUE) { (consoleCB->refCount) += flag ? 1 : -1;
++(consoleCB->refCount);
} else {
--(consoleCB->refCount);
}
} }
BOOL IsConsoleOccupied(const CONSOLE_CB *consoleCB) BOOL IsConsoleOccupied(const CONSOLE_CB *consoleCB)
{ {
if (ConsoleRefcountGet(consoleCB) != FALSE) { return ConsoleRefcountGet(consoleCB);
return TRUE;
} else {
return FALSE;
}
} }
STATIC INT32 ConsoleCtrlCaptureLine(CONSOLE_CB *consoleCB) STATIC INT32 ConsoleCtrlCaptureLine(CONSOLE_CB *consoleCB)
...@@ -294,10 +286,7 @@ STATIC INT32 OsConsoleFullpathToID(const CHAR *fullpath) ...@@ -294,10 +286,7 @@ STATIC INT32 OsConsoleFullpathToID(const CHAR *fullpath)
STATIC BOOL ConsoleFifoEmpty(const CONSOLE_CB *console) STATIC BOOL ConsoleFifoEmpty(const CONSOLE_CB *console)
{ {
if (console->fifoOut == console->fifoIn) { return console->fifoOut == console->fifoIn;
return TRUE;
}
return FALSE;
} }
STATIC VOID ConsoleFifoClearup(CONSOLE_CB *console) STATIC VOID ConsoleFifoClearup(CONSOLE_CB *console)
...@@ -343,10 +332,7 @@ INT32 FilepOpen(struct file *filep, const struct file_operations_vfs *fops) ...@@ -343,10 +332,7 @@ INT32 FilepOpen(struct file *filep, const struct file_operations_vfs *fops)
* corresponding to filep of /dev/console) * corresponding to filep of /dev/console)
*/ */
ret = fops->open(filep); ret = fops->open(filep);
if (ret < 0) { return (ret < 0) ? -EPERM : ret;
return -EPERM;
}
return ret;
} }
STATIC INLINE VOID UserEndOfRead(CONSOLE_CB *consoleCB, struct file *filep, STATIC INLINE VOID UserEndOfRead(CONSOLE_CB *consoleCB, struct file *filep,
...@@ -468,10 +454,7 @@ STATIC INT32 UserFilepRead(CONSOLE_CB *consoleCB, struct file *filep, const stru ...@@ -468,10 +454,7 @@ STATIC INT32 UserFilepRead(CONSOLE_CB *consoleCB, struct file *filep, const stru
/* Non-ICANON mode */ /* Non-ICANON mode */
if ((consoleCB->consoleTermios.c_lflag & ICANON) == 0) { if ((consoleCB->consoleTermios.c_lflag & ICANON) == 0) {
ret = fops->read(filep, buffer, bufLen); ret = fops->read(filep, buffer, bufLen);
if (ret < 0) { return (ret < 0) ? -EPERM : ret;
return -EPERM;
}
return ret;
} }
/* ICANON mode: store data to console buffer, read data and stored data into console fifo */ /* ICANON mode: store data to console buffer, read data and stored data into console fifo */
if (consoleCB->currentLen == 0) { if (consoleCB->currentLen == 0) {
...@@ -524,10 +507,7 @@ INT32 FilepRead(struct file *filep, const struct file_operations_vfs *fops, CHAR ...@@ -524,10 +507,7 @@ INT32 FilepRead(struct file *filep, const struct file_operations_vfs *fops, CHAR
* corresponding to filep of /dev/console) * corresponding to filep of /dev/console)
*/ */
ret = fops->read(filep, buffer, bufLen); ret = fops->read(filep, buffer, bufLen);
if (ret < 0) { return (ret < 0) ? -EPERM : ret;
return -EPERM;
}
return ret;
} }
INT32 FilepWrite(struct file *filep, const struct file_operations_vfs *fops, const CHAR *buffer, size_t bufLen) INT32 FilepWrite(struct file *filep, const struct file_operations_vfs *fops, const CHAR *buffer, size_t bufLen)
...@@ -538,10 +518,7 @@ INT32 FilepWrite(struct file *filep, const struct file_operations_vfs *fops, con ...@@ -538,10 +518,7 @@ INT32 FilepWrite(struct file *filep, const struct file_operations_vfs *fops, con
} }
ret = fops->write(filep, buffer, bufLen); ret = fops->write(filep, buffer, bufLen);
if (ret < 0) { return (ret < 0) ? -EPERM : ret;
return -EPERM;
}
return ret;
} }
INT32 FilepClose(struct file *filep, const struct file_operations_vfs *fops) INT32 FilepClose(struct file *filep, const struct file_operations_vfs *fops)
...@@ -556,10 +533,7 @@ INT32 FilepClose(struct file *filep, const struct file_operations_vfs *fops) ...@@ -556,10 +533,7 @@ INT32 FilepClose(struct file *filep, const struct file_operations_vfs *fops)
* corresponding to filep of /dev/console) * corresponding to filep of /dev/console)
*/ */
ret = fops->close(filep); ret = fops->close(filep);
if (ret < 0) { return ret < 0 ? -EPERM : ret;
return -EPERM;
}
return ret;
} }
INT32 FilepIoctl(struct file *filep, const struct file_operations_vfs *fops, INT32 cmd, unsigned long arg) INT32 FilepIoctl(struct file *filep, const struct file_operations_vfs *fops, INT32 cmd, unsigned long arg)
...@@ -570,10 +544,7 @@ INT32 FilepIoctl(struct file *filep, const struct file_operations_vfs *fops, INT ...@@ -570,10 +544,7 @@ INT32 FilepIoctl(struct file *filep, const struct file_operations_vfs *fops, INT
} }
ret = fops->ioctl(filep, cmd, arg); ret = fops->ioctl(filep, cmd, arg);
if (ret < 0) { return (ret < 0) ? -EPERM : ret;
return -EPERM;
}
return ret;
} }
INT32 FilepPoll(struct file *filep, const struct file_operations_vfs *fops, poll_table *fds) INT32 FilepPoll(struct file *filep, const struct file_operations_vfs *fops, poll_table *fds)
...@@ -588,10 +559,7 @@ INT32 FilepPoll(struct file *filep, const struct file_operations_vfs *fops, poll ...@@ -588,10 +559,7 @@ INT32 FilepPoll(struct file *filep, const struct file_operations_vfs *fops, poll
* corresponding to filep of /dev/serial) * corresponding to filep of /dev/serial)
*/ */
ret = fops->poll(filep, fds); ret = fops->poll(filep, fds);
if (ret < 0) { return (ret < 0) ? -EPERM : ret;
return -EPERM;
}
return ret;
} }
STATIC INT32 ConsoleOpen(struct file *filep) STATIC INT32 ConsoleOpen(struct file *filep)
...@@ -855,10 +823,8 @@ STATIC INT32 ConsoleGetWinSize(unsigned long arg) ...@@ -855,10 +823,8 @@ STATIC INT32 ConsoleGetWinSize(unsigned long arg)
.ws_row = DEFAULT_WINDOW_SIZE_ROW .ws_row = DEFAULT_WINDOW_SIZE_ROW
}; };
if (LOS_CopyFromKernel((VOID *)arg, sizeof(struct winsize), &kws, sizeof(struct winsize)) != 0) { return (LOS_CopyFromKernel((VOID *)arg, sizeof(struct winsize), &kws, sizeof(struct winsize)) != 0) ?
return -EFAULT; -EFAULT : LOS_OK;
}
return LOS_OK;
} }
STATIC INT32 ConsoleGetTermios(unsigned long arg) STATIC INT32 ConsoleGetTermios(unsigned long arg)
...@@ -876,11 +842,8 @@ STATIC INT32 ConsoleGetTermios(unsigned long arg) ...@@ -876,11 +842,8 @@ STATIC INT32 ConsoleGetTermios(unsigned long arg)
return -EFAULT; return -EFAULT;
} }
if (LOS_ArchCopyToUser((VOID *)arg, &consoleCB->consoleTermios, sizeof(struct termios)) != 0) { return (LOS_ArchCopyToUser((VOID *)arg, &consoleCB->consoleTermios, sizeof(struct termios)) != 0) ?
return -EFAULT; -EFAULT : LOS_OK;
} else {
return LOS_OK;
}
} }
INT32 ConsoleSetPgrp(CONSOLE_CB *consoleCB, unsigned long arg) INT32 ConsoleSetPgrp(CONSOLE_CB *consoleCB, unsigned long arg)
...@@ -893,10 +856,7 @@ INT32 ConsoleSetPgrp(CONSOLE_CB *consoleCB, unsigned long arg) ...@@ -893,10 +856,7 @@ INT32 ConsoleSetPgrp(CONSOLE_CB *consoleCB, unsigned long arg)
INT32 ConsoleGetPgrp(CONSOLE_CB *consoleCB, unsigned long arg) INT32 ConsoleGetPgrp(CONSOLE_CB *consoleCB, unsigned long arg)
{ {
if (LOS_ArchCopyToUser((VOID *)arg, &consoleCB->pgrpId, sizeof(INT32)) != 0) { return (LOS_ArchCopyToUser((VOID *)arg, &consoleCB->pgrpId, sizeof(INT32)) != 0) ? -EFAULT : LOS_OK;
return -EFAULT;
}
return LOS_OK;
} }
STATIC INT32 ConsoleIoctl(struct file *filep, INT32 cmd, unsigned long arg) STATIC INT32 ConsoleIoctl(struct file *filep, INT32 cmd, unsigned long arg)
...@@ -1201,11 +1161,7 @@ STATIC UINT32 OsConsoleBufInit(CONSOLE_CB *consoleCB) ...@@ -1201,11 +1161,7 @@ STATIC UINT32 OsConsoleBufInit(CONSOLE_CB *consoleCB)
initParam.usTaskPrio = SHELL_TASK_PRIORITY; initParam.usTaskPrio = SHELL_TASK_PRIORITY;
initParam.auwArgs[0] = (UINTPTR)consoleCB; initParam.auwArgs[0] = (UINTPTR)consoleCB;
initParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; initParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
if (consoleCB->consoleID == CONSOLE_SERIAL) { initParam.pcName = (consoleCB->consoleID == CONSOLE_SERIAL) ? "SendToSer" : "SendToTelnet";
initParam.pcName = "SendToSer";
} else {
initParam.pcName = "SendToTelnet";
}
initParam.uwResved = LOS_TASK_STATUS_DETACHED; initParam.uwResved = LOS_TASK_STATUS_DETACHED;
ret = LOS_TaskCreate(&consoleCB->sendTaskID, &initParam); ret = LOS_TaskCreate(&consoleCB->sendTaskID, &initParam);
...@@ -1429,10 +1385,7 @@ BOOL ConsoleEnable(VOID) ...@@ -1429,10 +1385,7 @@ BOOL ConsoleEnable(VOID)
if (consoleID == 0) { if (consoleID == 0) {
return FALSE; return FALSE;
} else if ((consoleID == CONSOLE_TELNET) || (consoleID == CONSOLE_SERIAL)) { } else if ((consoleID == CONSOLE_TELNET) || (consoleID == CONSOLE_SERIAL)) {
if ((OsGetSystemStatus() == OS_SYSTEM_NORMAL) && !OsPreemptable()) { return ((OsGetSystemStatus() == OS_SYSTEM_NORMAL) && !OsPreemptable()) ? FALSE : TRUE;
return FALSE;
}
return TRUE;
} }
#if defined (LOSCFG_DRIVERS_USB_SERIAL_GADGET) || defined (LOSCFG_DRIVERS_USB_ETH_SER_GADGET) #if defined (LOSCFG_DRIVERS_USB_SERIAL_GADGET) || defined (LOSCFG_DRIVERS_USB_ETH_SER_GADGET)
else if ((SerialTypeGet() == SERIAL_TYPE_USBTTY_DEV) && (userial_mask_get() == 1)) { else if ((SerialTypeGet() == SERIAL_TYPE_USBTTY_DEV) && (userial_mask_get() == 1)) {
...@@ -1468,69 +1421,43 @@ INT32 ConsoleTaskReg(INT32 consoleID, UINT32 taskID) ...@@ -1468,69 +1421,43 @@ INT32 ConsoleTaskReg(INT32 consoleID, UINT32 taskID)
return LOS_OK; return LOS_OK;
} }
LOS_SpinUnlockRestore(&g_consoleSpin, intSave); LOS_SpinUnlockRestore(&g_consoleSpin, intSave);
return g_console[consoleID - 1]->shellEntryId == taskID ? LOS_OK : LOS_NOK; return (g_console[consoleID - 1]->shellEntryId == taskID) ? LOS_OK : LOS_NOK;
} }
BOOL SetSerialNonBlock(const CONSOLE_CB *consoleCB) BOOL SetSerialNonBlock(const CONSOLE_CB *consoleCB)
{ {
INT32 ret;
if (consoleCB == NULL) { if (consoleCB == NULL) {
PRINT_ERR("%s: Input parameter is illegal\n", __FUNCTION__); PRINT_ERR("%s: Input parameter is illegal\n", __FUNCTION__);
return FALSE; return FALSE;
} }
ret = ioctl(consoleCB->fd, CONSOLE_CMD_RD_BLOCK_SERIAL, CONSOLE_RD_NONBLOCK); return ioctl(consoleCB->fd, CONSOLE_CMD_RD_BLOCK_SERIAL, CONSOLE_RD_NONBLOCK) == 0;
if (ret != 0) {
return FALSE;
}
return TRUE;
} }
BOOL SetSerialBlock(const CONSOLE_CB *consoleCB) BOOL SetSerialBlock(const CONSOLE_CB *consoleCB)
{ {
INT32 ret;
if (consoleCB == NULL) { if (consoleCB == NULL) {
PRINT_ERR("%s: Input parameter is illegal\n", __FUNCTION__); PRINT_ERR("%s: Input parameter is illegal\n", __FUNCTION__);
return TRUE; return TRUE;
} }
ret = ioctl(consoleCB->fd, CONSOLE_CMD_RD_BLOCK_SERIAL, CONSOLE_RD_BLOCK); return ioctl(consoleCB->fd, CONSOLE_CMD_RD_BLOCK_SERIAL, CONSOLE_RD_BLOCK) != 0;
if (ret != 0) {
return TRUE;
}
return FALSE;
} }
BOOL SetTelnetNonBlock(const CONSOLE_CB *consoleCB) BOOL SetTelnetNonBlock(const CONSOLE_CB *consoleCB)
{ {
INT32 ret;
if (consoleCB == NULL) { if (consoleCB == NULL) {
PRINT_ERR("%s: Input parameter is illegal\n", __FUNCTION__); PRINT_ERR("%s: Input parameter is illegal\n", __FUNCTION__);
return FALSE; return FALSE;
} }
ret = ioctl(consoleCB->fd, CONSOLE_CMD_RD_BLOCK_TELNET, CONSOLE_RD_NONBLOCK); return ioctl(consoleCB->fd, CONSOLE_CMD_RD_BLOCK_TELNET, CONSOLE_RD_NONBLOCK) == 0;
if (ret != 0) {
return FALSE;
}
return TRUE;
} }
BOOL SetTelnetBlock(const CONSOLE_CB *consoleCB) BOOL SetTelnetBlock(const CONSOLE_CB *consoleCB)
{ {
INT32 ret;
if (consoleCB == NULL) { if (consoleCB == NULL) {
PRINT_ERR("%s: Input parameter is illegal\n", __FUNCTION__); PRINT_ERR("%s: Input parameter is illegal\n", __FUNCTION__);
return TRUE; return TRUE;
} }
ret = ioctl(consoleCB->fd, CONSOLE_CMD_RD_BLOCK_TELNET, CONSOLE_RD_BLOCK); return ioctl(consoleCB->fd, CONSOLE_CMD_RD_BLOCK_TELNET, CONSOLE_RD_BLOCK) != 0;
if (ret != 0) {
return TRUE;
}
return FALSE;
} }
BOOL is_nonblock(const CONSOLE_CB *consoleCB) BOOL is_nonblock(const CONSOLE_CB *consoleCB)
...@@ -1567,11 +1494,7 @@ INT32 ConsoleUpdateFd(VOID) ...@@ -1567,11 +1494,7 @@ INT32 ConsoleUpdateFd(VOID)
} }
} }
if (g_console[consoleID - 1] == NULL) { return (g_console[consoleID - 1] != NULL) ? g_console[consoleID - 1]->fd : -1;
return -1;
}
return g_console[consoleID - 1]->fd;
} }
CONSOLE_CB *OsGetConsoleByID(INT32 consoleID) CONSOLE_CB *OsGetConsoleByID(INT32 consoleID)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册