examples/ostest: Eliminate some warnings

This commit is contained in:
Gregory Nutt 2016-10-26 07:34:30 -06:00
parent f9d6e176e1
commit a82c0202bc

View File

@ -123,6 +123,7 @@ static int nhighpri_waiting(void)
n++; n++;
} }
} }
return n; return n;
} }
@ -142,6 +143,7 @@ static int nhighpri_running(void)
n++; n++;
} }
} }
return n; return n;
} }
@ -151,7 +153,7 @@ static int nhighpri_running(void)
static void *highpri_thread(void *parameter) static void *highpri_thread(void *parameter)
{ {
int threadno = (int)parameter; int threadno = (int)((intptr_t)parameter);
int ret; int ret;
g_highstate[threadno-1] = RUNNING; g_highstate[threadno-1] = RUNNING;
@ -246,7 +248,7 @@ static void *lowpri_thread(void *parameter)
{ {
void *retval = (void*)-1; void *retval = (void*)-1;
struct sched_param sparam; struct sched_param sparam;
int threadno = (int)parameter; int threadno = (int)((intptr_t)parameter);
int expected; int expected;
int count; int count;
int policy; int policy;
@ -289,6 +291,7 @@ static void *lowpri_thread(void *parameter)
{ {
printf(" g_highstate[%d]: %d\n", i, (int)g_highstate[i]); printf(" g_highstate[%d]: %d\n", i, (int)g_highstate[i]);
} }
printf(" I still have a count on the semaphore\n"); printf(" I still have a count on the semaphore\n");
sem_enumholders(&g_sem); sem_enumholders(&g_sem);
FFLUSH(); FFLUSH();
@ -308,6 +311,7 @@ static void *lowpri_thread(void *parameter)
{ {
printf("lowpri_thread-%d: ERROR sem_getvalue failed: %d\n", threadno, errno); printf("lowpri_thread-%d: ERROR sem_getvalue failed: %d\n", threadno, errno);
} }
printf("lowpri_thread-%d: Sem count: %d, No. highpri thread: %d\n", threadno, count, nwaiting); printf("lowpri_thread-%d: Sem count: %d, No. highpri thread: %d\n", threadno, count, nwaiting);
/* The middle priority task is running, let go of the semaphore */ /* The middle priority task is running, let go of the semaphore */
@ -380,6 +384,7 @@ static void *lowpri_thread(void *parameter)
printf(" ERROR should have been %d\n", g_lowpri); printf(" ERROR should have been %d\n", g_lowpri);
} }
} }
sem_enumholders(&g_sem); sem_enumholders(&g_sem);
printf("lowpri_thread-%d: Okay... I'm done!\n", threadno); printf("lowpri_thread-%d: Okay... I'm done!\n", threadno);
@ -422,6 +427,7 @@ void priority_inheritance(void)
printf("priority_inheritance: sched_getparam failed\n"); printf("priority_inheritance: sched_getparam failed\n");
sparam.sched_priority = PTHREAD_DEFAULT_PRIORITY; sparam.sched_priority = PTHREAD_DEFAULT_PRIORITY;
} }
my_pri = sparam.sched_priority; my_pri = sparam.sched_priority;
g_highpri = sched_get_priority_max(SCHED_FIFO); g_highpri = sched_get_priority_max(SCHED_FIFO);
@ -443,11 +449,13 @@ void priority_inheritance(void)
{ {
printf("priority_inheritance: pthread_attr_init failed, status=%d\n", status); printf("priority_inheritance: pthread_attr_init failed, status=%d\n", status);
} }
sparam.sched_priority = g_lowpri; sparam.sched_priority = g_lowpri;
status = pthread_attr_setschedparam(&attr,& sparam); status = pthread_attr_setschedparam(&attr,& sparam);
if (status != OK) if (status != OK)
{ {
printf("priority_inheritance: pthread_attr_setschedparam failed, status=%d\n", status); printf("priority_inheritance: pthread_attr_setschedparam failed, status=%d\n",
status);
} }
else else
{ {
@ -455,12 +463,14 @@ void priority_inheritance(void)
threadno, sparam.sched_priority); threadno, sparam.sched_priority);
} }
status = pthread_create(&lowpri[i], &attr, lowpri_thread, (void*)threadno); status = pthread_create(&lowpri[i], &attr, lowpri_thread,
(void*)((uintptr_t)threadno));
if (status != 0) if (status != 0)
{ {
printf("priority_inheritance: pthread_create failed, status=%d\n", status); printf("priority_inheritance: pthread_create failed, status=%d\n", status);
} }
} }
printf("priority_inheritance: Waiting...\n"); printf("priority_inheritance: Waiting...\n");
sleep(2); sleep(2);
dump_nfreeholders("priority_inheritance:"); dump_nfreeholders("priority_inheritance:");
@ -478,11 +488,13 @@ void priority_inheritance(void)
status = pthread_attr_setschedparam(&attr,& sparam); status = pthread_attr_setschedparam(&attr,& sparam);
if (status != OK) if (status != OK)
{ {
printf("priority_inheritance: pthread_attr_setschedparam failed, status=%d\n", status); printf("priority_inheritance: pthread_attr_setschedparam failed, status=%d\n",
status);
} }
else else
{ {
printf("priority_inheritance: Set medpri_thread priority to %d\n", sparam.sched_priority); printf("priority_inheritance: Set medpri_thread priority to %d\n",
sparam.sched_priority);
} }
FFLUSH(); FFLUSH();
@ -491,6 +503,7 @@ void priority_inheritance(void)
{ {
printf("priority_inheritance: pthread_create failed, status=%d\n", status); printf("priority_inheritance: pthread_create failed, status=%d\n", status);
} }
printf("priority_inheritance: Waiting...\n"); printf("priority_inheritance: Waiting...\n");
sleep(1); sleep(1);
dump_nfreeholders("priority_inheritance:"); dump_nfreeholders("priority_inheritance:");
@ -519,14 +532,17 @@ void priority_inheritance(void)
printf("priority_inheritance: Set highpri_thread-%d priority to %d\n", printf("priority_inheritance: Set highpri_thread-%d priority to %d\n",
threadno, sparam.sched_priority); threadno, sparam.sched_priority);
} }
FFLUSH(); FFLUSH();
status = pthread_create(&highpri[i], &attr, highpri_thread, (void*)threadno); status = pthread_create(&highpri[i], &attr, highpri_thread,
(void*)((uintptr_t)threadno));
if (status != 0) if (status != 0)
{ {
printf("priority_inheritance: pthread_create failed, status=%d\n", status); printf("priority_inheritance: pthread_create failed, status=%d\n", status);
} }
} }
dump_nfreeholders("priority_inheritance:"); dump_nfreeholders("priority_inheritance:");
FFLUSH(); FFLUSH();
@ -538,11 +554,13 @@ void priority_inheritance(void)
FFLUSH(); FFLUSH();
(void)pthread_join(highpri[i], &result); (void)pthread_join(highpri[i], &result);
dump_nfreeholders("priority_inheritance:"); dump_nfreeholders("priority_inheritance:");
} }
printf("priority_inheritance: Waiting for medpri_thread to complete\n"); printf("priority_inheritance: Waiting for medpri_thread to complete\n");
FFLUSH(); FFLUSH();
(void)pthread_join(medpri, &result); (void)pthread_join(medpri, &result);
dump_nfreeholders("priority_inheritance:"); dump_nfreeholders("priority_inheritance:");
for (i = 0; i < NLOWPRI_THREADS; i++) for (i = 0; i < NLOWPRI_THREADS; i++)
{ {
printf("priority_inheritance: Waiting for lowpri_thread-%d to complete\n", i+1); printf("priority_inheritance: Waiting for lowpri_thread-%d to complete\n", i+1);