Skip to content

Commit 3a337a0

Browse files
committed
POSIX code/demo update.
This was the version we loaded to freertos.org before 2019 Op1 meeting. This version of the code has: - updated POSIX internal data structure. - updated util functions. - new atomic.h - POSIX code optimization with atomic. This version also: - fixed pthread_cond_timedwait() thread count underflow. https://sourceforge.net/p/freertos/bugs/197/ - pthread_cond_timedwait() mutex release and count semaphore take is not "atomic" in our implementation.
1 parent 7fc9c91 commit 3a337a0

File tree

1,189 files changed

+39250
-305601
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,189 files changed

+39250
-305601
lines changed

FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/FreeRTOS_Plus_POSIX_with_actor.sln

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28010.2050
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RTOSDemo", "WIN32.vcxproj", "{C686325E-3261-42F7-AEB1-DDE5280E1CEB}"
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RTOS_POSIX_Demo", "WIN32.vcxproj", "{C686325E-3261-42F7-AEB1-DDE5280E1CEB}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -19,4 +19,7 @@ Global
1919
GlobalSection(SolutionProperties) = preSolution
2020
HideSolutionNode = FALSE
2121
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {18112148-F9F0-43E0-B713-B146289BDEF3}
24+
EndGlobalSection
2225
EndGlobal

FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/WIN32.vcxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<PropertyGroup Label="Globals">
1414
<ProjectGuid>{C686325E-3261-42F7-AEB1-DDE5280E1CEB}</ProjectGuid>
1515
<ProjectName>RTOS_POSIX_Demo</ProjectName>
16-
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
1716
</PropertyGroup>
1817
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
1918
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
@@ -132,7 +131,6 @@
132131
</Bscmake>
133132
</ItemDefinitionGroup>
134133
<ItemGroup>
135-
<ClCompile Include="..\..\..\FreeRTOS\Source\croutine.c" />
136134
<ClCompile Include="..\..\..\FreeRTOS\Source\event_groups.c" />
137135
<ClCompile Include="..\..\..\FreeRTOS\Source\list.c" />
138136
<ClCompile Include="..\..\..\FreeRTOS\Source\portable\MemMang\heap_4.c" />

FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/WIN32.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@
9090
<ClCompile Include="..\..\..\FreeRTOS\Source\portable\MSVC-MingW\port.c">
9191
<Filter>lib\FreeRTOS\Portable\MSVC-W</Filter>
9292
</ClCompile>
93-
<ClCompile Include="..\..\..\FreeRTOS\Source\croutine.c">
94-
<Filter>lib\FreeRTOS</Filter>
95-
</ClCompile>
9693
<ClCompile Include="..\..\..\FreeRTOS\Source\event_groups.c">
9794
<Filter>lib\FreeRTOS</Filter>
9895
</ClCompile>

FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/FreeRTOS_POSIX.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Amazon FreeRTOS+POSIX V1.0.0
2+
* Amazon FreeRTOS POSIX V1.1.0
33
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
*
55
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -35,7 +35,7 @@
3535

3636
/* FreeRTOS+POSIX platform-specific configuration headers. */
3737
#include "FreeRTOS_POSIX_portable.h"
38-
#include "portable/FreeRTOS_POSIX_portable_default.h"
38+
#include "FreeRTOS_POSIX_portable_default.h"
3939

4040
/* FreeRTOS includes. */
4141
#include "FreeRTOS.h"
Lines changed: 72 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Amazon FreeRTOS+POSIX V1.0.0
2+
* Amazon FreeRTOS POSIX V1.1.0
33
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
*
55
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -32,64 +32,98 @@
3232
*/
3333

3434
/* Amazon FreeRTOS includes. */
35-
#include "aws_doubly_linked_list.h"
35+
#include "iot_doubly_linked_list.h"
3636

3737
/**
3838
* @brief Mutex attribute object.
3939
*/
40-
typedef struct pthread_mutexattr_internal
41-
{
42-
int iType; /**< Mutex type. */
43-
} pthread_mutexattr_internal_t;
40+
#if posixconfigENABLE_PTHREAD_MUTEXATTR_T == 1
41+
typedef struct pthread_mutexattr_internal
42+
{
43+
int iType; /**< Mutex type. */
44+
} pthread_mutexattr_internal_t;
45+
#endif
46+
47+
#if posixconfigENABLE_PTHREAD_MUTEX_T == 1
4448

4549
/**
4650
* @brief Mutex.
4751
*/
48-
typedef struct pthread_mutex_internal
49-
{
50-
BaseType_t xIsInitialized; /**< Set to pdTRUE if this mutex is initialized, pdFALSE otherwise. */
51-
StaticSemaphore_t xMutex; /**< FreeRTOS mutex. */
52-
TaskHandle_t xTaskOwner; /**< Owner; used for deadlock detection and permission checks. */
53-
pthread_mutexattr_internal_t xAttr; /**< Mutex attributes. */
54-
} pthread_mutex_internal_t;
52+
typedef struct pthread_mutex_internal
53+
{
54+
BaseType_t xIsInitialized; /**< Set to pdTRUE if this mutex is initialized, pdFALSE otherwise. */
55+
StaticSemaphore_t xMutex; /**< FreeRTOS mutex. */
56+
TaskHandle_t xTaskOwner; /**< Owner; used for deadlock detection and permission checks. */
57+
pthread_mutexattr_internal_t xAttr; /**< Mutex attributes. */
58+
} pthread_mutex_internal_t;
5559

5660
/**
5761
* @brief Compile-time initializer of pthread_mutex_internal_t.
5862
*/
59-
#define FREERTOS_POSIX_MUTEX_INITIALIZER \
60-
( &( ( pthread_mutex_internal_t ) \
61-
{ \
62-
.xIsInitialized = pdFALSE, \
63-
.xMutex = { { 0 } }, \
64-
.xTaskOwner = NULL, \
65-
.xAttr = { .iType = 0 } \
66-
} \
67-
) \
63+
#define FREERTOS_POSIX_MUTEX_INITIALIZER \
64+
( ( ( pthread_mutex_internal_t ) \
65+
{ \
66+
.xIsInitialized = pdFALSE, \
67+
.xMutex = { { 0 } }, \
68+
.xTaskOwner = NULL, \
69+
.xAttr = { .iType = 0 } \
70+
} \
71+
) \
6872
)
73+
#endif /* if posixconfigENABLE_PTHREAD_MUTEX_T == 1 */
74+
75+
#if posixconfigENABLE_PTHREAD_COND_T == 1
6976

7077
/**
7178
* @brief Condition variable.
7279
*/
73-
typedef struct pthread_cond_internal
74-
{
75-
BaseType_t xIsInitialized; /**< Set to pdTRUE if this condition variable is initialized, pdFALSE otherwise. */
76-
StaticSemaphore_t xCondMutex; /**< Prevents concurrent accesses to iWaitingThreads. */
77-
StaticSemaphore_t xCondWaitSemaphore; /**< Threads block on this semaphore in pthread_cond_wait. */
78-
int iWaitingThreads; /**< The number of threads currently waiting on this condition variable. */
79-
} pthread_cond_internal_t;
80+
typedef struct pthread_cond_internal
81+
{
82+
BaseType_t xIsInitialized; /**< Set to pdTRUE if this condition variable is initialized, pdFALSE otherwise. */
83+
StaticSemaphore_t xCondWaitSemaphore; /**< Threads block on this semaphore in pthread_cond_wait. */
84+
unsigned iWaitingThreads; /**< The number of threads currently waiting on this condition variable. */
85+
} pthread_cond_internal_t;
8086

8187
/**
8288
* @brief Compile-time initializer of pthread_cond_internal_t.
8389
*/
84-
#define FREERTOS_POSIX_COND_INITIALIZER \
85-
( &( ( pthread_cond_internal_t ) \
86-
{ \
87-
.xIsInitialized = pdFALSE, \
88-
.xCondMutex = { { 0 } }, \
89-
.xCondWaitSemaphore = { { 0 } },\
90-
.iWaitingThreads = 0 \
91-
} \
92-
) \
90+
91+
#define FREERTOS_POSIX_COND_INITIALIZER \
92+
( ( ( pthread_cond_internal_t ) \
93+
{ \
94+
.xIsInitialized = pdFALSE, \
95+
.xCondWaitSemaphore = { { 0 } }, \
96+
.iWaitingThreads = 0 \
97+
} \
98+
) \
9399
)
94100

101+
#endif /* if posixconfigENABLE_PTHREAD_COND_T == 1 */
102+
103+
#if posixconfigENABLE_SEM_T == 1
104+
105+
/**
106+
* @brief Semaphore type.
107+
*/
108+
typedef struct
109+
{
110+
StaticSemaphore_t xSemaphore; /**< FreeRTOS semaphore. */
111+
int value; /**< POSIX semaphore count. */
112+
} sem_internal_t;
113+
#endif /* if posixconfigENABLE_SEM_T == 1 */
114+
115+
#if posixconfigENABLE_PTHREAD_BARRIER_T == 1
116+
117+
/**
118+
* @brief Barrier object.
119+
*/
120+
typedef struct pthread_barrier_internal
121+
{
122+
unsigned uThreadCount; /**< Current number of threads that have entered barrier. */
123+
unsigned uThreshold; /**< The count argument of pthread_barrier_init. */
124+
StaticSemaphore_t xThreadCountSemaphore; /**< Prevents more than uThreshold threads from exiting pthread_barrier_wait at once. */
125+
StaticEventGroup_t xBarrierEventGroup; /**< FreeRTOS event group that blocks to wait on threads entering barrier. */
126+
} pthread_barrier_internal_t;
127+
#endif /* if posixconfigENABLE_PTHREAD_BARRIER_T == 1 */
128+
95129
#endif /* _FREERTOS_POSIX_INTERNAL_H_ */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Amazon FreeRTOS POSIX V1.1.0
3+
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
* this software and associated documentation files (the "Software"), to deal in
7+
* the Software without restriction, including without limitation the rights to
8+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
* the Software, and to permit persons to whom the Software is furnished to do so,
10+
* subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*
22+
* http://aws.amazon.com/freertos
23+
* http://www.FreeRTOS.org
24+
*/
25+
26+
#ifndef _FREERTOS_POSIX_INTERNAL_TYPES_H_
27+
#define _FREERTOS_POSIX_INTERNAL_TYPES_H_
28+
29+
#include "FreeRTOS_POSIX_internal.h"
30+
31+
/*
32+
* sys/types.h defines a POSIX type when posixconfigENABLE_PTHREAD_<TYPE>_T
33+
* is not defined AND when posixconfigENABLE_PTHREAD_<TYPE>_T is set to 1.
34+
* FreeRTOS_POSIX_internal.h defines internal type ONLY when
35+
* posixconfigENABLE_PTHREAD_<TYPE>_T is set to 1.
36+
* #else part below is to have a type defined, so the code compiles, when
37+
* posixconfigENABLE_PTHREAD_<TYPE>_T is not defined.
38+
*/
39+
#if posixconfigENABLE_PTHREAD_MUTEX_T == 1
40+
typedef pthread_mutex_internal_t PthreadMutexType_t;
41+
#else
42+
typedef void * PthreadMutexType_t;
43+
#endif
44+
45+
#if posixconfigENABLE_PTHREAD_COND_T == 1
46+
typedef pthread_cond_internal_t PthreadCondType_t;
47+
#else
48+
typedef void * PthreadCondType_t;
49+
#endif
50+
51+
#if posixconfigENABLE_SEM_T == 1
52+
typedef sem_internal_t PosixSemType_t;
53+
#else
54+
typedef void * PosixSemType_t;
55+
#endif
56+
57+
#if posixconfigENABLE_PTHREAD_MUTEXATTR_T == 1
58+
typedef struct pthread_mutexattr
59+
{
60+
uint32_t ulpthreadMutexAttrStorage;
61+
} PthreadMutexAttrType_t;
62+
#else
63+
typedef void * PthreadMutexAttrType_t;
64+
#endif
65+
66+
#if posixconfigENABLE_PTHREAD_ATTR_T == 1
67+
typedef struct pthread_attr
68+
{
69+
uint32_t ulpthreadAttrStorage;
70+
} PthreadAttrType_t;
71+
#else
72+
typedef void * PthreadAttrType_t;
73+
#endif
74+
75+
#if posixconfigENABLE_PTHREAD_BARRIER_T == 1
76+
typedef pthread_barrier_internal_t PthreadBarrierType_t;
77+
#else
78+
typedef void * PthreadBarrierType_t;
79+
#endif
80+
81+
#endif /* _FREERTOS_POSIX_INTERNAL_TYPES_H_ */

FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/FreeRTOS_POSIX_portable_default.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Amazon FreeRTOS+POSIX V1.0.0
2+
* Amazon FreeRTOS POSIX V1.1.0
33
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
*
55
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -32,21 +32,25 @@
3232
#define _FREERTOS_POSIX_PORTABLE_DEFAULT_H_
3333

3434
/**
35-
* @brief The FreeRTOS task name given to pthreads.
35+
* @name The FreeRTOS task name given to pthreads.
3636
*/
37+
/**@{ */
3738
#ifndef posixconfigPTHREAD_TASK_NAME
38-
#define posixconfigPTHREAD_TASK_NAME "pthread"
39+
#define posixconfigPTHREAD_TASK_NAME "pthread" /**< Task name. */
3940
#endif
41+
/**@} */
4042

4143
/**
42-
* @brief the FreeRTOS timer name given to POSIX timers.
44+
* @name the FreeRTOS timer name given to POSIX timers.
4345
*/
46+
/**@{ */
4447
#ifndef posixconfigTIMER_NAME
45-
#define posixconfigTIMER_NAME "timer"
48+
#define posixconfigTIMER_NAME "timer" /**< Timer name. */
4649
#endif
50+
/**@} */
4751

4852
/**
49-
* @defgroup Defaults for POSIX message queue implementation.
53+
* @name Defaults for POSIX message queue implementation.
5054
*/
5155
/**@{ */
5256
#ifndef posixconfigMQ_MAX_MESSAGES
@@ -59,7 +63,7 @@
5963
/**@} */
6064

6165
/**
62-
* @defgroup POSIX implementation-dependent constants usually defined in limits.h.
66+
* @name POSIX implementation-dependent constants usually defined in limits.h.
6367
*
6468
* They are defined here to provide portability between platforms.
6569
*/
@@ -71,12 +75,12 @@
7175
#define NAME_MAX 64 /**< Maximum number of bytes in a filename (not including terminating null). */
7276
#endif
7377
#ifndef SEM_VALUE_MAX
74-
#define SEM_VALUE_MAX 0xFFFFU /**< Maximum value of a sem_t. */
78+
#define SEM_VALUE_MAX 0x7FFFU /**< Maximum value of a sem_t. */
7579
#endif
7680
/**@} */
7781

7882
/**
79-
* @defgroup Enable typedefs of POSIX types.
83+
* @name Enable typedefs of POSIX types.
8084
*
8185
* Set these values to 1 or 0 to enable or disable the typedefs, respectively.
8286
* These typedefs should only be disabled if they conflict with system typedefs.
@@ -130,8 +134,11 @@
130134
#ifndef posixconfigENABLE_ITIMERSPEC
131135
#define posixconfigENABLE_ITIMERSPEC 1 /**< struct itimerspec in time.h */
132136
#endif
133-
#ifndef posixconfigENABLE_TM
134-
#define posixconfigENABLE_TM 1 /**< struct tm in time.h */
137+
#ifndef posixconfigENABLE_SEM_T
138+
#define posixconfigENABLE_SEM_T 1 /**< struct sem_t in semaphore.h */
139+
#endif
140+
#ifndef posixconfigENABLE_PTHREAD_BARRIER_T
141+
#define posixconfigENABLE_PTHREAD_BARRIER_T 1 /**< pthread_barrier_t in sys/types.h */
135142
#endif
136143
/**@} */
137144

FreeRTOS-Plus/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/FreeRTOS-Plus-POSIX/include/portable/espressif/esp32_devkitc_esp_wrover_kit/FreeRTOS_POSIX_portable.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Amazon FreeRTOS+POSIX V1.0.0
2+
* Amazon FreeRTOS+POSIX V1.0.4
33
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
*
55
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -42,12 +42,19 @@
4242
#define posixconfigENABLE_PTHREAD_MUTEXATTR_T 0
4343
#define posixconfigENABLE_PTHREAD_T 0
4444
#define posixconfigENABLE_TIME_T 0
45-
#define posixconfigENABLE_TIMER_T 0
4645
#define posixconfigENABLE_TIMESPEC 0
4746
#define posixconfigENABLE_ITIMERSPEC 0
4847

49-
/* ESP-IDF already provides the header sched.h. Exclude them by
50-
* activating the double inclusion guards. */
48+
/* ESP-IDF already provides the header sched.h. Exclude FreeRTOS+POSIX sched.h by
49+
* defining its double inclusion guard. */
5150
#define _FREERTOS_POSIX_SCHED_H_
5251

52+
/* Use the FreeRTOS+POSIX time.h header instead of the ESP-IDF time.h. Disable
53+
* ESP-IDF time.h by defining its double inclusion guard. */
54+
#define _TIME_H_
55+
56+
/* Disable the timer_t type defined by ESP-IDF. */
57+
#define __timer_t_defined
58+
#include <sys/types.h>
59+
5360
#endif /* _FREERTOS_POSIX_PORTABLE_H_ */

0 commit comments

Comments
 (0)