mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
vnc_updater: use [enter|leave]_critical_section replace sched_[un]lock
sched_[un]lock can not prohibit pre-emption in smp Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
|
#include <nuttx/irq.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -181,14 +182,15 @@ static FAR struct vnc_fbupdate_s *
|
|||||||
vnc_alloc_update(FAR struct vnc_session_s *session)
|
vnc_alloc_update(FAR struct vnc_session_s *session)
|
||||||
{
|
{
|
||||||
FAR struct vnc_fbupdate_s *update;
|
FAR struct vnc_fbupdate_s *update;
|
||||||
|
irqstate_t flags;
|
||||||
|
|
||||||
/* Reserve one element from the free list. Lock the scheduler to assure
|
/* Reserve one element from the free list. Lock the scheduler to assure
|
||||||
* that the sq_remfirst() and the successful return from nxsem_wait are
|
* that the sq_remfirst() and the successful return from nxsem_wait are
|
||||||
* atomic. Of course, the scheduler will be unlocked while we wait.
|
* atomic. Of course, the scheduler will be unlocked while we wait.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sched_lock();
|
|
||||||
vnc_sem_debug(session, "Before alloc", 0);
|
vnc_sem_debug(session, "Before alloc", 0);
|
||||||
|
flags = enter_critical_section();
|
||||||
|
|
||||||
nxsem_wait_uninterruptible(&session->freesem);
|
nxsem_wait_uninterruptible(&session->freesem);
|
||||||
|
|
||||||
@@ -196,8 +198,8 @@ vnc_alloc_update(FAR struct vnc_session_s *session)
|
|||||||
|
|
||||||
update = (FAR struct vnc_fbupdate_s *)sq_remfirst(&session->updfree);
|
update = (FAR struct vnc_fbupdate_s *)sq_remfirst(&session->updfree);
|
||||||
|
|
||||||
|
leave_critical_section(flags);
|
||||||
vnc_sem_debug(session, "After alloc", 1);
|
vnc_sem_debug(session, "After alloc", 1);
|
||||||
sched_unlock();
|
|
||||||
|
|
||||||
DEBUGASSERT(update != NULL);
|
DEBUGASSERT(update != NULL);
|
||||||
return update;
|
return update;
|
||||||
@@ -220,12 +222,14 @@ vnc_alloc_update(FAR struct vnc_session_s *session)
|
|||||||
static void vnc_free_update(FAR struct vnc_session_s *session,
|
static void vnc_free_update(FAR struct vnc_session_s *session,
|
||||||
FAR struct vnc_fbupdate_s *update)
|
FAR struct vnc_fbupdate_s *update)
|
||||||
{
|
{
|
||||||
|
irqstate_t flags;
|
||||||
|
|
||||||
/* Reserve one element from the free list. Lock the scheduler to assure
|
/* Reserve one element from the free list. Lock the scheduler to assure
|
||||||
* that the sq_addlast() and the nxsem_post() are atomic.
|
* that the sq_addlast() and the nxsem_post() are atomic.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sched_lock();
|
|
||||||
vnc_sem_debug(session, "Before free", 1);
|
vnc_sem_debug(session, "Before free", 1);
|
||||||
|
flags = enter_critical_section();
|
||||||
|
|
||||||
/* Put the entry into the free list */
|
/* Put the entry into the free list */
|
||||||
|
|
||||||
@@ -235,10 +239,9 @@ static void vnc_free_update(FAR struct vnc_session_s *session,
|
|||||||
|
|
||||||
nxsem_post(&session->freesem);
|
nxsem_post(&session->freesem);
|
||||||
|
|
||||||
|
leave_critical_section(flags);
|
||||||
vnc_sem_debug(session, "After free", 0);
|
vnc_sem_debug(session, "After free", 0);
|
||||||
DEBUGASSERT(session->freesem.semcount <= CONFIG_VNCSERVER_NUPDATES);
|
DEBUGASSERT(session->freesem.semcount <= CONFIG_VNCSERVER_NUPDATES);
|
||||||
|
|
||||||
sched_unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -261,6 +264,7 @@ static FAR struct vnc_fbupdate_s *
|
|||||||
vnc_remove_queue(FAR struct vnc_session_s *session)
|
vnc_remove_queue(FAR struct vnc_session_s *session)
|
||||||
{
|
{
|
||||||
FAR struct vnc_fbupdate_s *rect;
|
FAR struct vnc_fbupdate_s *rect;
|
||||||
|
irqstate_t flags;
|
||||||
|
|
||||||
/* Reserve one element from the list of queued rectangle. Lock the
|
/* Reserve one element from the list of queued rectangle. Lock the
|
||||||
* scheduler to assure that the sq_remfirst() and the successful return
|
* scheduler to assure that the sq_remfirst() and the successful return
|
||||||
@@ -268,8 +272,8 @@ vnc_remove_queue(FAR struct vnc_session_s *session)
|
|||||||
* while we wait.
|
* while we wait.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sched_lock();
|
|
||||||
vnc_sem_debug(session, "Before remove", 0);
|
vnc_sem_debug(session, "Before remove", 0);
|
||||||
|
flags = enter_critical_section();
|
||||||
|
|
||||||
nxsem_wait_uninterruptible(&session->queuesem);
|
nxsem_wait_uninterruptible(&session->queuesem);
|
||||||
|
|
||||||
@@ -293,7 +297,7 @@ vnc_remove_queue(FAR struct vnc_session_s *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
errout:
|
errout:
|
||||||
sched_unlock();
|
leave_critical_section(flags);
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,12 +319,14 @@ errout:
|
|||||||
static void vnc_add_queue(FAR struct vnc_session_s *session,
|
static void vnc_add_queue(FAR struct vnc_session_s *session,
|
||||||
FAR struct vnc_fbupdate_s *rect)
|
FAR struct vnc_fbupdate_s *rect)
|
||||||
{
|
{
|
||||||
|
irqstate_t flags;
|
||||||
|
|
||||||
/* Lock the scheduler to assure that the sq_addlast() and the nxsem_post()
|
/* Lock the scheduler to assure that the sq_addlast() and the nxsem_post()
|
||||||
* are atomic.
|
* are atomic.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sched_lock();
|
|
||||||
vnc_sem_debug(session, "Before add", 1);
|
vnc_sem_debug(session, "Before add", 1);
|
||||||
|
flags = enter_critical_section();
|
||||||
|
|
||||||
/* Put the entry into the list of queued rectangles. */
|
/* Put the entry into the list of queued rectangles. */
|
||||||
|
|
||||||
@@ -332,10 +338,9 @@ static void vnc_add_queue(FAR struct vnc_session_s *session,
|
|||||||
|
|
||||||
nxsem_post(&session->queuesem);
|
nxsem_post(&session->queuesem);
|
||||||
|
|
||||||
|
leave_critical_section(flags);
|
||||||
vnc_sem_debug(session, "After add", 0);
|
vnc_sem_debug(session, "After add", 0);
|
||||||
DEBUGASSERT(session->queuesem.semcount <= CONFIG_VNCSERVER_NUPDATES);
|
DEBUGASSERT(session->queuesem.semcount <= CONFIG_VNCSERVER_NUPDATES);
|
||||||
|
|
||||||
sched_unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -557,6 +562,7 @@ int vnc_update_rectangle(FAR struct vnc_session_s *session,
|
|||||||
{
|
{
|
||||||
FAR struct vnc_fbupdate_s *update;
|
FAR struct vnc_fbupdate_s *update;
|
||||||
struct fb_area_s intersection;
|
struct fb_area_s intersection;
|
||||||
|
irqstate_t flags;
|
||||||
bool whupd;
|
bool whupd;
|
||||||
|
|
||||||
intersection.x = rect->x;
|
intersection.x = rect->x;
|
||||||
@@ -597,12 +603,12 @@ int vnc_update_rectangle(FAR struct vnc_session_s *session,
|
|||||||
* the framebuffer since the last whole screen update.
|
* the framebuffer since the last whole screen update.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sched_lock();
|
flags = enter_critical_section();
|
||||||
if (!change && !session->change)
|
if (!change && !session->change)
|
||||||
{
|
{
|
||||||
/* No.. ignore the client update. We have nothing new to report. */
|
/* No.. ignore the client update. We have nothing new to report. */
|
||||||
|
|
||||||
sched_unlock();
|
leave_critical_section(flags);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -668,7 +674,7 @@ int vnc_update_rectangle(FAR struct vnc_session_s *session,
|
|||||||
intersection.w, intersection.h);
|
intersection.w, intersection.h);
|
||||||
}
|
}
|
||||||
|
|
||||||
sched_unlock();
|
leave_critical_section(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Since we ignore bad rectangles and wait for update structures, there is
|
/* Since we ignore bad rectangles and wait for update structures, there is
|
||||||
|
|||||||
Reference in New Issue
Block a user