Skip to content

Commit 901701e

Browse files
committed
ThreadX: Support for __DYNAMIC_REENT__
- ThreadX change to handle dynamic reent for both newlib and xclib - Adapt ThreadX xclib interface code to handle dynamic reent pointers
1 parent 1de3589 commit 901701e

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

ports/xtensa/xcc/src/tx_clib_lock.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ __env_unlock (struct _reent * ptr)
136136
#include <errno.h>
137137
#include <sys/reent.h>
138138

139+
#if defined(__DYNAMIC_REENT__)
140+
// Helps to keep code similar between dynamic and non-dynamic.
141+
#undef _reent_ptr
142+
struct _reent * _reent_ptr;
143+
#endif
144+
139145
#define XT_NUM_CLIB_LOCKS (_MAX_LOCK + FOPEN_MAX)
140146

141147
typedef TX_MUTEX * _Rmtx;
@@ -209,6 +215,31 @@ _Mtxunlock (_Rmtx * mtx)
209215

210216
#endif /* XSHAL_CLIB == XTHAL_CLIB_XCLIB */
211217

218+
#if defined(__DYNAMIC_REENT__)
219+
/**************************************************************************/
220+
/* Return libc context pointer for current thread. Overrides weak */
221+
/* version in libc. Until real threads are active, use the libc's */
222+
/* global reent struct. */
223+
/**************************************************************************/
224+
struct _reent *
225+
__getreent(void)
226+
{
227+
TX_THREAD * thread_ptr = _tx_thread_current_ptr;
228+
229+
if (thread_ptr) {
230+
return &(thread_ptr->tx_thread_clib_reent);
231+
}
232+
233+
#if XSHAL_CLIB == XTHAL_CLIB_XCLIB
234+
extern struct _reent g_reent; /* from xclib */
235+
return &g_reent;
236+
#endif
237+
#if XSHAL_CLIB == XTHAL_CLIB_NEWLIB
238+
extern struct _reent * _impure_ptr; /* from newlib */
239+
return _impure_ptr;
240+
#endif
241+
}
242+
#endif
212243

213244
/**************************************************************************/
214245
/* _sbrk_r - heap allocator. This function is called when the memory */

0 commit comments

Comments
 (0)