Fix wait loop and void cast (#24)

* Simplify EINTR/ECANCEL error handling

1. Add semaphore uninterruptible wait function
2 .Replace semaphore wait loop with a single uninterruptible wait
3. Replace all sem_xxx to nxsem_xxx

* Unify the void cast usage

1. Remove void cast for function because many place ignore the returned value witout cast
2. Replace void cast for variable with UNUSED macro
This commit is contained in:
Xiang Xiao
2020-01-02 10:49:34 -06:00
committed by Gregory Nutt
parent 316675f4db
commit 6a3c2aded6
1602 changed files with 6311 additions and 10874 deletions
+2 -2
View File
@@ -100,7 +100,7 @@ void NXGL_FUNCNAME(nxgl_copyrectangle, NXGLIB_SUFFIX)
if (remainder != 0)
{
NXGL_FUNCNAME(nxgl_copyrun, NXGLIB_SUFFIX)(sline, pinfo->buffer, remainder, ncols);
(void)pinfo->putrun(row, dest->pt1.x, pinfo->buffer, ncols);
pinfo->putrun(row, dest->pt1.x, pinfo->buffer, ncols);
}
else
#endif
@@ -109,7 +109,7 @@ void NXGL_FUNCNAME(nxgl_copyrectangle, NXGLIB_SUFFIX)
* the image memory.
*/
(void)pinfo->putrun(row, dest->pt1.x, sline, ncols);
pinfo->putrun(row, dest->pt1.x, sline, ncols);
}
/* Then adjust the source pointer to refer to the next line in the source
+1 -1
View File
@@ -90,6 +90,6 @@ void NXGL_FUNCNAME(nxgl_fillrectangle, NXGLIB_SUFFIX)
{
/* Draw the raster line at this row */
(void)pinfo->putrun(row, rect->pt1.x, pinfo->buffer, ncols);
pinfo->putrun(row, rect->pt1.x, pinfo->buffer, ncols);
}
}
+1 -1
View File
@@ -232,7 +232,7 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid, NXGLIB_SUFFIX)
/* Then draw the run from ix1 to ix2 at row */
ncols = ix2 - ix1 + 1;
(void)pinfo->putrun(row, ix1, pinfo->buffer, ncols);
pinfo->putrun(row, ix1, pinfo->buffer, ncols);
}
/* Add the dx/dy value to get the run positions on the next row */
+1 -1
View File
@@ -79,7 +79,7 @@ void NXGL_FUNCNAME(nxgl_getrectangle, NXGLIB_SUFFIX)
for (srcrow = rect->pt1.y; srcrow <= rect->pt2.y; srcrow++)
{
(void)pinfo->getrun(srcrow, rect->pt1.x, dline, ncols);
pinfo->getrun(srcrow, rect->pt1.x, dline, ncols);
dline += deststride;
}
}
+4 -4
View File
@@ -85,8 +85,8 @@ void NXGL_FUNCNAME(nxgl_moverectangle, NXGLIB_SUFFIX)
srcrow <= rect->pt2.y;
srcrow++, destrow++)
{
(void)pinfo->getrun(srcrow, rect->pt1.x, pinfo->buffer, ncols);
(void)pinfo->putrun(destrow, offset->x, pinfo->buffer, ncols);
pinfo->getrun(srcrow, rect->pt1.x, pinfo->buffer, ncols);
pinfo->putrun(destrow, offset->x, pinfo->buffer, ncols);
}
}
@@ -104,8 +104,8 @@ void NXGL_FUNCNAME(nxgl_moverectangle, NXGLIB_SUFFIX)
srcrow >= rect->pt1.y;
srcrow--, destrow--)
{
(void)pinfo->getrun(srcrow, rect->pt1.x, pinfo->buffer, ncols);
(void)pinfo->putrun(destrow, offset->x, pinfo->buffer, ncols);
pinfo->getrun(srcrow, rect->pt1.x, pinfo->buffer, ncols);
pinfo->putrun(destrow, offset->x, pinfo->buffer, ncols);
}
}
}
+3 -3
View File
@@ -81,7 +81,7 @@ void NXGL_FUNCNAME(nxgl_setpixel, NXGLIB_SUFFIX)
/* Read the byte that contains the pixel to be changed */
(void)pinfo->getrun(pos->y, pos->x, &pixel, 8 / NXGLIB_BITSPERPIXEL);
pinfo->getrun(pos->y, pos->x, &pixel, 8 / NXGLIB_BITSPERPIXEL);
/* Shift the color into the proper position */
@@ -128,10 +128,10 @@ void NXGL_FUNCNAME(nxgl_setpixel, NXGLIB_SUFFIX)
/* Write the modified byte back to graphics memory */
(void)pinfo->putrun(pos->y, pos->x, (FAR uint8_t *)&pixel, 8 / NXGLIB_BITSPERPIXEL);
pinfo->putrun(pos->y, pos->x, (FAR uint8_t *)&pixel, 8 / NXGLIB_BITSPERPIXEL);
#else
/* Draw a single pixel at this position raster line at this row */
(void)pinfo->putrun(pos->y, pos->x, (FAR uint8_t *)&color, 1);
pinfo->putrun(pos->y, pos->x, (FAR uint8_t *)&color, 1);
#endif
}
+1 -1
View File
@@ -90,7 +90,7 @@ void nxmu_kbdin(FAR struct nxmu_state_s *nxmu, uint8_t nch, FAR uint8_t *ch)
outmsg->ch[i] = ch[i];
}
(void)nxmu_sendclientwindow(nxmu->be.topwnd, outmsg, size);
nxmu_sendclientwindow(nxmu->be.topwnd, outmsg, size);
kmm_free(outmsg);
}
}
+2 -2
View File
@@ -150,8 +150,8 @@ void nxmu_redrawreq(FAR struct nxbe_window_s *wnd,
nxgl_rectoffset(&outmsg.rect, rect,
-wnd->bounds.pt1.x, -wnd->bounds.pt1.y);
(void)nxmu_sendclientwindow(wnd, &outmsg,
sizeof(struct nxclimsg_redraw_s));
nxmu_sendclientwindow(wnd, &outmsg,
sizeof(struct nxclimsg_redraw_s));
}
/****************************************************************************
+2 -2
View File
@@ -79,7 +79,7 @@ static inline void nxmu_disconnect(FAR struct nxmu_conn_s *conn)
/* Close the outgoing client message queue */
(void)mq_close(conn->swrmq);
mq_close(conn->swrmq);
}
/****************************************************************************
@@ -133,7 +133,7 @@ static inline void nxmu_shutdown(FAR struct nxmu_state_s *nxmu)
for (wnd = nxmu->be.topwnd; wnd; wnd = wnd->below)
{
(void)nxmu_disconnect(wnd->conn);
nxmu_disconnect(wnd->conn);
}
}
+1 -1
View File
@@ -119,7 +119,7 @@ static int nx_server(int argc, char *argv[])
/* Turn the LCD on at 75% power */
(void)dev->setpower(dev, ((3 * CONFIG_LCD_MAXPOWER + 3) / 4));
dev->setpower(dev, ((3 * CONFIG_LCD_MAXPOWER + 3) / 4));
#else /* CONFIG_NX_LCDDRIVER */
/* Initialize the frame buffer device. */
+1 -1
View File
@@ -183,5 +183,5 @@ void nxterm_showcursor(FAR struct nxterm_state_s *priv)
void nxterm_hidecursor(FAR struct nxterm_state_s *priv)
{
(void)nxterm_hidechar(priv, &priv->cursor);
nxterm_hidechar(priv, &priv->cursor);
}
+1 -12
View File
@@ -94,17 +94,6 @@ void nxterm_redraw(NXTERM handle, FAR const struct nxgl_rect_s *rect, bool more)
do
{
ret = nxterm_semwait(priv);
/* Check for errors */
if (ret < 0)
{
/* The only expected error is if the wait failed because of it
* was interrupted by a signal.
*/
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
}
}
while (ret < 0);
@@ -125,5 +114,5 @@ void nxterm_redraw(NXTERM handle, FAR const struct nxgl_rect_s *rect, bool more)
nxterm_fillchar(priv, rect, &priv->bm[i]);
}
(void)nxterm_sempost(priv);
nxterm_sempost(priv);
}
+1 -6
View File
@@ -88,11 +88,6 @@ int nxterm_resize(NXTERM handle, FAR const struct nxgl_size_s *size)
ret = nxterm_semwait(priv);
if (ret < 0)
{
/* The only expected error is if the wait failed because of it was
* interrupted by a signal or if the thread was canceled.
*/
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
return ret;
}
@@ -103,6 +98,6 @@ int nxterm_resize(NXTERM handle, FAR const struct nxgl_size_s *size)
priv->wndo.wsize.w = size->w;
priv->wndo.wsize.h = size->h;
(void)nxterm_sempost(priv);
nxterm_sempost(priv);
return true;
}
+1 -1
View File
@@ -90,7 +90,7 @@ void nxterm_unregister(FAR struct nxterm_state_s *priv)
/* Unregister the driver */
snprintf(devname, NX_DEVNAME_SIZE, NX_DEVNAME_FORMAT, priv->minor);
(void)unregister_driver(devname);
unregister_driver(devname);
/* Free the private data structure */
+6 -27
View File
@@ -452,7 +452,7 @@ static int vnc_start_server(int display)
/* Format the kernel thread arguments (ASCII.. yech) */
(void)itoa(display, str, 10);
itoa(display, str, 10);
argv[0] = str;
argv[1] = NULL;
@@ -486,8 +486,6 @@ static int vnc_start_server(int display)
static inline int vnc_wait_start(int display)
{
int ret = OK;
/* Check if there has been a session allocated yet. This is one of the
* first things that the VNC server will do with the kernel thread is
* started. But we might be here before the thread has gotten that far.
@@ -506,20 +504,10 @@ static inline int vnc_wait_start(int display)
* conditions here, but I think none that are fatal.
*/
do
{
ret = nxsem_wait(&g_fbstartup[display].fbinit);
/* The only case that an error should occur here is if the wait
* was awakened by a signal.
*/
DEBUGASSERT(ret == OK || ret == -EINTR);
}
while (ret == -EINTR);
nxsem_wait_uninterruptible(&g_fbstartup[display].fbinit);
}
return ret;
return OK;
}
/****************************************************************************
@@ -564,20 +552,11 @@ static inline int vnc_wait_connect(int display)
* conditions here, but I think none that are fatal.
*/
do
ret = nxsem_wait_uninterruptible(&g_fbstartup[display].fbconnect);
if (ret < 0)
{
ret = nxsem_wait(&g_fbstartup[display].fbconnect);
/* The only case that an error should occur here is if the wait
* was awakened by a signal.
*/
if (ret < 0 && ret != -EINTR)
{
return ret;
}
return ret;
}
while (ret == -EINTR);
/* We were awakened. A result of -EBUSY means that the negotiation
* is not complete. Why would we be awakened in that case? Some
+1 -1
View File
@@ -648,7 +648,7 @@ void vnc_key_map(FAR struct vnc_session_s *session, uint16_t keysym,
void vnc_kbdout(FAR void *arg, uint8_t nch, FAR const uint8_t *ch)
{
DEBUGASSERT(arg != NULL);
(void)nx_kbdin((NXHANDLE)arg, nch, ch);
nx_kbdin((NXHANDLE)arg, nch, ch);
}
#endif /* CONFIG_NX_KBD */
+1 -1
View File
@@ -516,6 +516,6 @@ void vnc_mouseout(FAR void *arg, nxgl_coord_t x, nxgl_coord_t y,
uint8_t buttons)
{
DEBUGASSERT(arg != NULL);
(void)nx_mousein((NXHANDLE)arg, x, y, buttons);
nx_mousein((NXHANDLE)arg, x, y, buttons);
}
#endif
+3 -42
View File
@@ -129,21 +129,8 @@ static void vnc_sem_debug(FAR struct vnc_session_s *session,
int queuecount;
int freewaiting;
int queuewaiting;
int ret;
do
{
/* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&g_errsem);
/* The only case that an error should occur here is if the wait was
* awakened by a signal.
*/
DEBUGASSERT(ret == OK || ret == -EINTR);
}
while (ret == -EINTR);
nxsem_wait_uninterruptible(&g_errsem);
/* Count structures in the list */
@@ -207,7 +194,6 @@ static FAR struct vnc_fbupdate_s *
vnc_alloc_update(FAR struct vnc_session_s *session)
{
FAR struct vnc_fbupdate_s *update;
int ret;
/* Reserve one element from the free list. Lock the scheduler to assure
* that the sq_remfirst() and the successful return from nxsem_wait are
@@ -217,19 +203,7 @@ vnc_alloc_update(FAR struct vnc_session_s *session)
sched_lock();
vnc_sem_debug(session, "Before alloc", 0);
do
{
/* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&session->freesem);
/* The only case that an error should occur here is if the wait was
* awakened by a signal.
*/
DEBUGASSERT(ret == OK || ret == -EINTR);
}
while (ret == -EINTR);
nxsem_wait_uninterruptible(&session->freesem);
/* It is reserved.. go get it */
@@ -300,7 +274,6 @@ static FAR struct vnc_fbupdate_s *
vnc_remove_queue(FAR struct vnc_session_s *session)
{
FAR struct vnc_fbupdate_s *rect;
int ret;
/* Reserve one element from the list of queued rectangle. Lock the
* scheduler to assure that the sq_remfirst() and the successful return
@@ -311,19 +284,7 @@ vnc_remove_queue(FAR struct vnc_session_s *session)
sched_lock();
vnc_sem_debug(session, "Before remove", 0);
do
{
/* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&session->queuesem);
/* The only case that an error should occur here is if the wait was
* awakened by a signal.
*/
DEBUGASSERT(ret == OK || ret == -EINTR);
}
while (ret == -EINTR);
nxsem_wait_uninterruptible(&session->queuesem);
/* It is reserved.. go get it */