mirror of
https://github.com/apache/nuttx.git
synced 2026-05-21 13:13:08 +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
|
||||
****************************************************************************/
|
||||
|
||||
#define CANCEL_FLAG_NONCANCELABLE (1 << 0) /* Pthread is non-cancelable */
|
||||
#define CANCEL_FLAG_CANCEL_ASYNC (1 << 1) /* Async (vs deferred) cancellation type */
|
||||
#define CANCEL_FLAG_CANCEL_PENDING (1 << 2) /* Pthread cancel is pending */
|
||||
#define CANCEL_FLAG_NONCANCELABLE (1u << 0) /* Pthread is non-cancelable */
|
||||
#define CANCEL_FLAG_CANCEL_ASYNC (1u << 1) /* Async (vs deferred) cancellation type */
|
||||
#define CANCEL_FLAG_CANCEL_PENDING (1u << 2) /* Pthread cancel is pending */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
|
||||
@@ -106,13 +106,13 @@ bool enter_cancellation_point(void)
|
||||
* nesting level.
|
||||
*/
|
||||
|
||||
if (((tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) == 0 &&
|
||||
(tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) == 0) ||
|
||||
if (((tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) == 0u &&
|
||||
(tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) == 0u) ||
|
||||
tls->tl_cpcount > 0)
|
||||
{
|
||||
/* 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) */
|
||||
|
||||
@@ -194,7 +194,7 @@ void leave_cancellation_point(void)
|
||||
* 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
|
||||
pthread_exit(PTHREAD_CANCELED);
|
||||
@@ -245,13 +245,13 @@ bool check_cancellation_point(void)
|
||||
* cancellation and will true if there is a pending cancellation.
|
||||
*/
|
||||
|
||||
if (((tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) == 0 &&
|
||||
(tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) == 0) ||
|
||||
if (((tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) == 0u &&
|
||||
(tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) == 0u) ||
|
||||
tls->tl_cpcount > 0)
|
||||
{
|
||||
/* 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;
|
||||
|
||||
@@ -71,7 +71,7 @@ int task_setcancelstate(int state, FAR int *oldstate)
|
||||
|
||||
if (oldstate != NULL)
|
||||
{
|
||||
if ((tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) != 0)
|
||||
if ((tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) != 0u)
|
||||
{
|
||||
*oldstate = TASK_CANCEL_DISABLE;
|
||||
}
|
||||
@@ -91,12 +91,12 @@ int task_setcancelstate(int state, FAR int *oldstate)
|
||||
|
||||
/* 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
|
||||
/* 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
|
||||
{
|
||||
/* No.. We are using asynchronous cancellation. If the
|
||||
|
||||
@@ -63,7 +63,7 @@ int task_setcanceltype(int type, FAR int *oldtype)
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -86,8 +86,8 @@ int task_setcanceltype(int type, FAR int *oldtype)
|
||||
* cancellation is pending, then exit now.
|
||||
*/
|
||||
|
||||
if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_PENDING) != 0 &&
|
||||
(tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) == 0)
|
||||
if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_PENDING) != 0u &&
|
||||
(tls->tl_cpstate & CANCEL_FLAG_NONCANCELABLE) == 0u)
|
||||
{
|
||||
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. */
|
||||
|
||||
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
|
||||
* supposed to work:
|
||||
@@ -131,7 +131,7 @@ bool nxnotify_cancellation(FAR struct tcb_s *tcb)
|
||||
#ifdef CONFIG_CANCELLATION_POINTS
|
||||
/* 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. */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user