Skip to content

Commit

Permalink
Adjust print messages from example tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
shengwen-tw committed Jan 25, 2024
1 parent e5a2736 commit a42c7a1
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion user/tasks/examples/fifo-ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "uart.h"

#define TEST_STR "fifo: hello world\n\r"
#define TEST_STR "[fifo example] hello world\n\r"
#define LEN strlen(TEST_STR)

void fifo_task1(void)
Expand Down
5 changes: 3 additions & 2 deletions user/tasks/examples/mqueue-ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void message_queue_task1(void)
{
setprogname("mqueue-ex-1");

char *str = "mqueue: greeting";
char *str = "greeting!";

struct mq_attr attr = {
.mq_maxmsg = 100,
Expand Down Expand Up @@ -56,7 +56,8 @@ void message_queue_task2(void)
mq_receive(mqdes_print, str, MSG_SIZE_MAX, &msg_prio);

/* Print received message */
printf("received message \"%s\", priority = %d\n\r", str, msg_prio);
printf("[mqueue example] received \"%s\" with priority %d\n\r", str,
msg_prio);
}
}

Expand Down
8 changes: 4 additions & 4 deletions user/tasks/examples/mutex-ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ void mutex_task1(void)
pthread_mutex_lock(&mutex);

if (my_cnt == BUFFER_SIZE) {
printf("[task 1] buffer is full. producer is waiting...\n\r");
printf("[mutex task 1] buffer is full, wait for consumer\n\r");
pthread_cond_wait(&cond_producer, &mutex);
}

/* Produce an item and add it to the buffer */
my_buffer[my_cnt++] = item;
printf("[task 1] produced item %d\n\r", item);
printf("[mutex task 1] produced item %d\n\r", item);
item++;

/* Signal to consumers that an item is available */
Expand All @@ -65,13 +65,13 @@ void mutex_task2(void)
pthread_mutex_lock(&mutex);

if (my_cnt == 0) {
printf("[task 2] buffer is empty. consumer is waiting...\n\r");
printf("[mutex task 2] buffer is empty, wait for producer\n\r");
pthread_cond_wait(&cond_consumer, &mutex);
}

/* Consume an item from the buffer */
int item = my_buffer[--my_cnt];
printf("[task 2] consumed item %d\n\r", item);
printf("[mutex task 2] consumed item %d\n\r", item);

/* Signal to producers that there is space in the buffer */
pthread_cond_signal(&cond_producer);
Expand Down
2 changes: 1 addition & 1 deletion user/tasks/examples/poll-ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void poll_task2(void)
ssize_t rbytes = read(fifo_fd, buffer, sizeof(buffer) - 1);
buffer[rbytes] = '\0';

printf("received %d bytes\n\r", rbytes);
printf("[poll example] %d bytes is read from the fifo\n\r", rbytes);

fds[0].revents = 0;
}
Expand Down
17 changes: 10 additions & 7 deletions user/tasks/examples/priority-inversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void mutex_task_high(void)
#endif
pthread_mutex_init(&mutex, &attr);

printf("[mutex high] attempt to lock the mutex in 5 seconds.\n\r");
printf("[mutex task high] attempt to lock the mutex in 5 seconds\n\r");

sleep(5);

Expand All @@ -35,8 +35,8 @@ void mutex_task_high(void)
pthread_mutex_lock(&mutex);

printf(
"[mutex high] highest-priority thread locked the mutex "
"successfully.\n\r");
"[mutex task high] mutex is locked by the highest-priority "
"thread\n\r");

/* End the critical section */
pthread_mutex_unlock(&mutex);
Expand All @@ -53,12 +53,15 @@ void mutex_task_median(void)
struct timespec start_time, curr_time;

/* Occupy the CPU to block the lowest-prioiry thread after 3 seconds */
printf("[mutex median] block the lowest-priority thread in 3 seconds.\n\r");
printf(
"[mutex task median] block the lowest-priority thread in 3 "
"seconds\n\r");
sleep(3);

/* Occupy the CPU for 10 seconds */
printf(
"[mutex median] block the lowest-priority thread for 10 seconds.\n\r");
"[mutex task median] block the lowest-priority thread for 10 "
"seconds\n\r");

clock_gettime(CLOCK_MONOTONIC, &start_time);

Expand All @@ -84,8 +87,8 @@ void mutex_task_low(void)
pthread_mutex_lock(&mutex);

printf(
"[mutex low] lowest-priority thread locked the mutex "
"successfully.\n\r");
"[mutex task low] mutex is locked by the lowest-priority "
"thread\n\r");

/* Simulate some works */
sleep(2);
Expand Down
6 changes: 3 additions & 3 deletions user/tasks/examples/pthread-ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
void *my_thread(void *arg)
{
for (int i = 0; i < 10; i++) {
printf("hello new thread.\n\r");
printf("[pthread example] printing from the new thread\n\r");
sleep(1);
}

Expand All @@ -23,8 +23,8 @@ void pthread_task(void)
setprogname("pthread-ex");

printf(
"a new thread will be created and"
" canceled after 10 seconds.\n\r");
"[pthread example] a new thread will be created and"
" canceled after 10 seconds\n\r");

pthread_attr_t attr;
struct sched_param param;
Expand Down
4 changes: 2 additions & 2 deletions user/tasks/examples/semaphore.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void semaphore_task1(void)
while (1) {
sleep(1);
sem_post(&sem_print);
printf("[semaphore 1] posted semaphore.\n\r");
printf("[semaphore task 1] semaphore increased\n\r");
}
}

Expand All @@ -25,7 +25,7 @@ void semaphore_task2(void)

while (1) {
sem_wait(&sem_print);
printf("[semaphore 2] received semaphore.\n\r");
printf("[semaphore task 2] semaphore decreased\n\r");
}
}

Expand Down
4 changes: 2 additions & 2 deletions user/tasks/examples/signal-ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static int task1_pid;

void sig_handler(int signum)
{
printf("received signal %d.\n\r", signum);
printf("[SIGUSR1 handler] signal number is %d\n\r", signum);
}

void signal_task1(void)
Expand All @@ -36,7 +36,7 @@ void signal_task1(void)
sigwait(&set, &sig);

/* Print after the signal arrived */
printf("signal %d is captured.\n\r", sig);
printf("[signal example] signal %d is captured\n\r", sig);

/* Sleep */
while (1) {
Expand Down
2 changes: 1 addition & 1 deletion user/tasks/examples/timer-ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

void timer_callback(union sigval sv)
{
printf("timer: time's up.\n\r");
printf("[timer handler] time's up!\n\r");
}

void timer_task(void)
Expand Down

0 comments on commit a42c7a1

Please sign in to comment.