mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 05:16:47 +08:00
sched/cancelpt: Fix MISRA C 2012 Rule 10.4 violations
Fix violations of MISRA C:2012 Rule 10.4 (operand of unsigned and signed) in cancellation point handling code. Changed all CANCEL_FLAG_* macro definitions and their usage to use unsigned literals (1u instead of 1) to ensure consistent unsigned arithmetic when performing bitwise operations. This eliminates mixed signed/unsigned operand violations in: - CANCEL_FLAG_NONCANCELABLE - CANCEL_FLAG_CANCEL_ASYNC - CANCEL_FLAG_CANCEL_PENDING The changes affect cancellation point entry/exit logic, cancellation state management, and cancellation type handling across both kernel and libc implementations. Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
This commit is contained in:
@@ -63,9 +63,9 @@
|
|||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#define CANCEL_FLAG_NONCANCELABLE (1 << 0) /* Pthread is non-cancelable */
|
#define CANCEL_FLAG_NONCANCELABLE (1u << 0) /* Pthread is non-cancelable */
|
||||||
#define CANCEL_FLAG_CANCEL_ASYNC (1 << 1) /* Async (vs deferred) cancellation type */
|
#define CANCEL_FLAG_CANCEL_ASYNC (1u << 1) /* Async (vs deferred) cancellation type */
|
||||||
#define CANCEL_FLAG_CANCEL_PENDING (1 << 2) /* Pthread cancel is pending */
|
#define CANCEL_FLAG_CANCEL_PENDING (1u << 2) /* Pthread cancel is pending */
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
|
|||||||
@@ -106,13 +106,13 @@ bool enter_cancellation_point(void)
|
|||||||
* nesting level.
|
* nesting level.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (((tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) == 0 &&
|
if (((tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) == 0u &&
|
||||||
(tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) == 0) ||
|
(tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) == 0u) ||
|
||||||
tls->tl_cpcount > 0)
|
tls->tl_cpcount > 0)
|
||||||
{
|
{
|
||||||
/* Check if there is a pending cancellation */
|
/* Check if there is a pending cancellation */
|
||||||
|
|
||||||
if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_PENDING) != 0)
|
if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_PENDING) != 0u)
|
||||||
{
|
{
|
||||||
/* Yes... return true (if we don't exit here) */
|
/* Yes... return true (if we don't exit here) */
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ void leave_cancellation_point(void)
|
|||||||
* the type of the thread.
|
* the type of the thread.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_PENDING) != 0)
|
if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_PENDING) != 0u)
|
||||||
{
|
{
|
||||||
#ifndef CONFIG_DISABLE_PTHREAD
|
#ifndef CONFIG_DISABLE_PTHREAD
|
||||||
pthread_exit(PTHREAD_CANCELED);
|
pthread_exit(PTHREAD_CANCELED);
|
||||||
@@ -245,13 +245,13 @@ bool check_cancellation_point(void)
|
|||||||
* cancellation and will true if there is a pending cancellation.
|
* cancellation and will true if there is a pending cancellation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (((tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) == 0 &&
|
if (((tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) == 0u &&
|
||||||
(tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) == 0) ||
|
(tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) == 0u) ||
|
||||||
tls->tl_cpcount > 0)
|
tls->tl_cpcount > 0)
|
||||||
{
|
{
|
||||||
/* Check if there is a pending cancellation. If so, return true. */
|
/* Check if there is a pending cancellation. If so, return true. */
|
||||||
|
|
||||||
ret = ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_PENDING) != 0);
|
ret = ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_PENDING) != 0u);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ int task_setcancelstate(int state, FAR int *oldstate)
|
|||||||
|
|
||||||
if (oldstate != NULL)
|
if (oldstate != NULL)
|
||||||
{
|
{
|
||||||
if ((tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) != 0)
|
if ((tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) != 0u)
|
||||||
{
|
{
|
||||||
*oldstate = TASK_CANCEL_DISABLE;
|
*oldstate = TASK_CANCEL_DISABLE;
|
||||||
}
|
}
|
||||||
@@ -91,12 +91,12 @@ int task_setcancelstate(int state, FAR int *oldstate)
|
|||||||
|
|
||||||
/* Check if a cancellation was pending */
|
/* Check if a cancellation was pending */
|
||||||
|
|
||||||
if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_PENDING) != 0)
|
if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_PENDING) != 0u)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_CANCELLATION_POINTS
|
#ifdef CONFIG_CANCELLATION_POINTS
|
||||||
/* If we are using deferred cancellation? */
|
/* If we are using deferred cancellation? */
|
||||||
|
|
||||||
if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) != 0)
|
if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) != 0u)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* No.. We are using asynchronous cancellation. If the
|
/* No.. We are using asynchronous cancellation. If the
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ int task_setcanceltype(int type, FAR int *oldtype)
|
|||||||
|
|
||||||
if (oldtype != NULL)
|
if (oldtype != NULL)
|
||||||
{
|
{
|
||||||
if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) != 0)
|
if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) != 0u)
|
||||||
{
|
{
|
||||||
*oldtype = TASK_CANCEL_ASYNCHRONOUS;
|
*oldtype = TASK_CANCEL_ASYNCHRONOUS;
|
||||||
}
|
}
|
||||||
@@ -86,8 +86,8 @@ int task_setcanceltype(int type, FAR int *oldtype)
|
|||||||
* cancellation is pending, then exit now.
|
* cancellation is pending, then exit now.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_PENDING) != 0 &&
|
if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_PENDING) != 0u &&
|
||||||
(tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) == 0)
|
(tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) == 0u)
|
||||||
{
|
{
|
||||||
tls->tl_cpstate &= ~CANCEL_FLAG_CANCEL_PENDING;
|
tls->tl_cpstate &= ~CANCEL_FLAG_CANCEL_PENDING;
|
||||||
|
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ bool nxnotify_cancellation(FAR struct tcb_s *tcb)
|
|||||||
/* Check to see if this task has the non-cancelable bit set. */
|
/* Check to see if this task has the non-cancelable bit set. */
|
||||||
|
|
||||||
if ((tcb->flags & TCB_FLAG_FORCED_CANCEL) == 0 &&
|
if ((tcb->flags & TCB_FLAG_FORCED_CANCEL) == 0 &&
|
||||||
(tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) != 0)
|
(tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) != 0u)
|
||||||
{
|
{
|
||||||
/* Then we cannot cancel the thread now. Here is how this is
|
/* Then we cannot cancel the thread now. Here is how this is
|
||||||
* supposed to work:
|
* supposed to work:
|
||||||
@@ -131,7 +131,7 @@ bool nxnotify_cancellation(FAR struct tcb_s *tcb)
|
|||||||
#ifdef CONFIG_CANCELLATION_POINTS
|
#ifdef CONFIG_CANCELLATION_POINTS
|
||||||
/* Check if this task supports deferred cancellation */
|
/* Check if this task supports deferred cancellation */
|
||||||
|
|
||||||
if (!ret && (tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) == 0)
|
if (!ret && (tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) == 0u)
|
||||||
{
|
{
|
||||||
/* Then we cannot cancel the task asynchronously. */
|
/* Then we cannot cancel the task asynchronously. */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user