[LTP] [PATCH 2/6] sched_football: Use atomic for ball
John Stultz
jstultz@google.com
Wed Apr 24 00:57:59 CEST 2024
Use atomic type for the ball value, as we don't have any locking
going on.
Cc: kernel-team@android.com
Cc: Darren Hart <darren@os.amperecomputing.com>
Signed-off-by: John Stultz <jstultz@google.com>
---
testcases/realtime/func/sched_football/sched_football.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/testcases/realtime/func/sched_football/sched_football.c b/testcases/realtime/func/sched_football/sched_football.c
index 1e205219d..359c96703 100644
--- a/testcases/realtime/func/sched_football/sched_football.c
+++ b/testcases/realtime/func/sched_football/sched_football.c
@@ -71,7 +71,7 @@
#define DEF_GAME_LENGTH 5
/* Here's the position of the ball */
-volatile int the_ball;
+static atomic_t the_ball;
static int players_per_team = 0;
static int game_length = DEF_GAME_LENGTH;
@@ -122,7 +122,7 @@ void *thread_offense(void *arg)
{
atomic_inc(&players_ready);
while (1) {
- the_ball++; /* move the ball ahead one yard */
+ atomic_inc(&the_ball); /* move the ball ahead one yard */
}
return NULL;
}
@@ -138,16 +138,16 @@ int referee(int game_length)
now = start;
/* Start the game! */
- the_ball = 0;
+ atomic_set(0, &the_ball);
/* Watch the game */
while ((now.tv_sec - start.tv_sec) < game_length) {
sleep(1);
gettimeofday(&now, NULL);
}
+ final_ball = atomic_get(&the_ball);
/* Blow the whistle */
printf("Game Over!\n");
- final_ball = the_ball;
printf("Final ball position: %d\n", final_ball);
return final_ball != 0;
}
--
2.44.0.769.g3c40516874-goog
More information about the ltp
mailing list