-
Notifications
You must be signed in to change notification settings - Fork 7.6k
posix: implement other _POSIX_THREAD_SAFE_FUNCTIONS
#74350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ycsin
wants to merge
3
commits into
zephyrproject-rtos:main
from
ycsin:pr/posix_thread_safe_functions_1
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,3 +82,5 @@ config COMMON_LIBC_THRD | |
default y | ||
help | ||
Common implementation of C11 <threads.h> API. | ||
|
||
rsource "source/Kconfig" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright (c) 2024 Meta Platforms | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_subdirectory_ifdef(CONFIG_COMMON_LIBC_STDIO stdio) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright (c) 2024 Meta Platforms | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
rsource "stdio/Kconfig" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright (c) 2024 Meta Platforms | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_GETC_UNLOCKED getc_unlocked.c) | ||
zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_PUTC_UNLOCKED putc_unlocked.c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) 2024 Meta Platforms | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config COMMON_LIBC_STDIO | ||
bool | ||
help | ||
common function implementation in stdio.h | ||
|
||
config COMMON_LIBC_GETC_UNLOCKED | ||
bool | ||
select COMMON_LIBC_STDIO | ||
help | ||
common implementation of getc_unlocked() & getchar_unlocked(). | ||
|
||
config COMMON_LIBC_PUTC_UNLOCKED | ||
bool | ||
select COMMON_LIBC_STDIO | ||
help | ||
common implementation of putc_unlocked() & putchar_unlocked(). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 2024 Meta Platforms | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <stdio.h> | ||
|
||
#include <zephyr/sys/util.h> | ||
|
||
int getc_unlocked(FILE *stream) | ||
{ | ||
ARG_UNUSED(stream); | ||
|
||
errno = ENOSYS; | ||
|
||
return EOF; | ||
} | ||
|
||
int getchar_unlocked(void) | ||
{ | ||
return getc_unlocked(stdin); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2024 Meta Platforms | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#include <zephyr/sys/libc-hooks.h> | ||
|
||
int putc_unlocked(int c, FILE *stream) | ||
{ | ||
return zephyr_fputc(c, stream); | ||
} | ||
|
||
int putchar_unlocked(int c) | ||
{ | ||
return putc_unlocked(c, stdout); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright (c) 2024 Meta Platforms | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config POSIX_FILE_LOCKING | ||
bool "POSIX file locking [EXPERIMENTAL]" | ||
select EXPERIMENTAL | ||
cfriedt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
select FDTABLE | ||
help | ||
Select 'y' here and Zephyr will provide implementations for the POSIX_FILE_LOCKING Option | ||
Group. | ||
This includes support for flockfile(), ftrylockfile(), funlockfile(), getc_unlocked(), | ||
getchar_unlocked(), putc_unlocked() and putchar_unlocked(). | ||
|
||
For more information, please see | ||
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html | ||
|
||
if POSIX_FILE_LOCKING | ||
|
||
# These options are intended to be used for compatibility with external POSIX | ||
# implementations such as those in Newlib or Picolibc. | ||
|
||
config POSIX_FD_MGMT_ALIAS_FLOCKFILE | ||
bool | ||
help | ||
Select 'y' here and Zephyr will provide an alias for flockfile() as _flockfile(). | ||
|
||
config POSIX_FD_MGMT_ALIAS_FTRYLOCKFILE | ||
bool | ||
help | ||
Select 'y' here and Zephyr will provide an alias for ftrylockfile() as _ftrylockfile(). | ||
|
||
config POSIX_FD_MGMT_ALIAS_FUNLOCKFILE | ||
bool | ||
help | ||
Select 'y' here and Zephyr will provide an alias for funlockfile() as _funlockfile(). | ||
|
||
endif # POSIX_FILE_LOCKING |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2024 Meta Platforms | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <stdio.h> | ||
|
||
#include <zephyr/sys/libc-hooks.h> | ||
#include <zephyr/sys/util.h> | ||
|
||
void zvfs_flockfile(int fd); | ||
int zvfs_ftrylockfile(int fd); | ||
void zvfs_funlockfile(int fd); | ||
|
||
void flockfile(FILE *file) | ||
{ | ||
zvfs_flockfile(POINTER_TO_INT(file)); | ||
} | ||
#ifdef CONFIG_POSIX_FD_MGMT_ALIAS_FLOCKFILE | ||
FUNC_ALIAS(flockfile, _flockfile, void); | ||
#endif /* CONFIG_POSIX_FD_MGMT_ALIAS_FLOCKFILE */ | ||
|
||
int ftrylockfile(FILE *file) | ||
{ | ||
return zvfs_ftrylockfile(POINTER_TO_INT(file)); | ||
} | ||
#ifdef CONFIG_POSIX_FD_MGMT_ALIAS_FTRYLOCKFILE | ||
FUNC_ALIAS(ftrylockfile, _ftrylockfile, int); | ||
#endif /* CONFIG_POSIX_FD_MGMT_ALIAS_FTRYLOCKFILE */ | ||
|
||
void funlockfile(FILE *file) | ||
{ | ||
zvfs_funlockfile(POINTER_TO_INT(file)); | ||
} | ||
#ifdef CONFIG_POSIX_FD_MGMT_ALIAS_FUNLOCKFILE | ||
FUNC_ALIAS(funlockfile, _funlockfile, void); | ||
#endif /* CONFIG_POSIX_FD_MGMT_ALIAS_FUNLOCKFILE */ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this one, I would add a
zvfs_getc_unlocked()
and just call that.zvfs_getc_unlocked()
should do some basic error checking but should not incur lock overhead.E.g. check to see if
stream
is a valid pointer withIS_ARRAY_ELEMENT()
, check theread()
vtable method is non-NULL
, etc.