Skip to content

Commit

Permalink
Enable dynamic reent for multicore/multithread
Browse files Browse the repository at this point in the history
Dynamic_reent enables each core or thread to have its own local store.
W/o it, crashes can happen if two cores are running newlib code at the
same time.  printf_float, for instance.

Also completely remove the fake locking routines and supply them in the
core directly.
  • Loading branch information
earlephilhower committed Jun 19, 2022
1 parent f38fa5a commit cb31b54
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
15 changes: 15 additions & 0 deletions patches/lib-dynamic-reent.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h
index 4bc8d29bf..23d465407 100644
--- a/newlib/libc/include/sys/config.h
+++ b/newlib/libc/include/sys/config.h
@@ -4,6 +4,10 @@
#include <machine/ieeefp.h> /* floating point macros */
#include <sys/features.h> /* POSIX defs */

+#ifndef __DYNAMIC_REENT__
+#define __DYNAMIC_REENT__
+#endif
+
#ifdef __aarch64__
#define MALLOC_ALIGNMENT 16
#endif
17 changes: 15 additions & 2 deletions patches/lib-weak-locks.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
diff --git a/newlib/libc/misc/lock.c b/newlib/libc/misc/lock.c
index 545511e78..984b51f72 100644
index 545511e78..bae9ec187 100644
--- a/newlib/libc/misc/lock.c
+++ b/newlib/libc/misc/lock.c
@@ -92,63 +92,73 @@ struct __lock {
@@ -83,7 +83,7 @@ subroutines are required for linking multi-threaded applications.
*/

/* dummy lock routines and static locks for single-threaded apps */
-
+#if 0
#ifndef __SINGLE_THREAD__

#include <sys/lock.h>
@@ -92,66 +92,77 @@ struct __lock {
char unused;
};

Expand Down Expand Up @@ -86,3 +95,7 @@ index 545511e78..984b51f72 100644
void
__retarget_lock_release_recursive (_LOCK_T lock)
{
}

#endif /* !defined(__SINGLE_THREAD__) */
+#endif

0 comments on commit cb31b54

Please sign in to comment.