mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
426170b064
As discussed in #2725, this commit renames a number of stacksize constants to better convey their intended usage. In addition, constants for thread priority are given a `THREAD_` prefix. Changes are: * KERNEL_CONF_STACKSIZE_PRINTF renamed to THREAD_EXTRA_STACKSIZE_PRINTF * KERNEL_CONF_STACKSIZE_DEFAULT renamed to THREAD_STACKSIZE_DEFAULT * KERNEL_CONF_STACKSIZE_IDLE renamed to THREAD_STACKSIZE_IDLE * KERNEL_CONF_STACKSIZE_MAIN renamed to THREAD_STACKSIZE_MAIN * Move thread stacksizes from kernel.h to thread.h, since the prefix changed * PRIORITY_MIN renamed to THREAD_PRIORITY_MIN * PRIORITY_IDLE renamed to THREAD_PRIORITY_IDLE * PRIORITY_MAIN renamed to THREAD_PRIORITY_MAIN * Move thread priorities from kernel.h to thread.h since the prefix has changed * MINIMUM_STACK_SIZE renamed to THREAD_STACKSIZE_MINIMUM for consistency
75 lines
1.7 KiB
C
75 lines
1.7 KiB
C
/*
|
|
* Copyright (C) 2014 Hamburg University of Applied Siences (HAW)
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
* directory for more details.
|
|
*/
|
|
|
|
/**
|
|
* @ingroup tests
|
|
* @{
|
|
*
|
|
* @file
|
|
* @brief simple test application for atomic mutex unlocking and sleeping
|
|
*
|
|
* @author Martin Landsmann <martin.landsmann@haw-hamburg.de>
|
|
*
|
|
* @}
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include "thread.h"
|
|
#include "mutex.h"
|
|
|
|
static mutex_t mutex = MUTEX_INIT;
|
|
static volatile int indicator, count;
|
|
static kernel_pid_t main_pid;
|
|
|
|
static char stack[THREAD_STACKSIZE_MAIN];
|
|
static void *second_thread(void *arg)
|
|
{
|
|
(void) arg;
|
|
while (1) {
|
|
mutex_lock(&mutex);
|
|
thread_wakeup(main_pid);
|
|
indicator--;
|
|
mutex_unlock_and_sleep(&mutex);
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
indicator = 0;
|
|
count = 0;
|
|
|
|
main_pid = thread_getpid();
|
|
|
|
kernel_pid_t second_pid = thread_create(stack,
|
|
sizeof(stack),
|
|
THREAD_PRIORITY_MAIN - 1,
|
|
CREATE_WOUT_YIELD | CREATE_STACKTEST,
|
|
second_thread,
|
|
NULL,
|
|
"second_thread");
|
|
|
|
while (1) {
|
|
mutex_lock(&mutex);
|
|
thread_wakeup(second_pid);
|
|
indicator++;
|
|
count++;
|
|
|
|
if (indicator > 1 || indicator < -1) {
|
|
printf("Error, threads did not sleep properly. [indicator: %d]\n", indicator);
|
|
return -1;
|
|
}
|
|
|
|
if ((count % 100000) == 0) {
|
|
printf("Still alive alternated [count: %dk] times.\n", count / 1000);
|
|
}
|
|
|
|
mutex_unlock_and_sleep(&mutex);
|
|
}
|
|
}
|