11#include <stdlib.h>
22#include <stdio.h>
33#include <string.h>
4+ #include <sys/iosupport.h>
5+
46#include "asm.h"
57#include "processor.h"
68#include "lwp_stack.h"
@@ -35,7 +37,6 @@ vu32 _thread_dispatch_disable_level;
3537
3638wd_cntrl _lwp_wd_timeslice ;
3739u32 _lwp_ticks_per_timeslice = 0 ;
38- void * * __lwp_thr_libc_reent = NULL ;
3940lwp_queue _lwp_thr_ready [LWP_MAXPRIORITIES ];
4041
4142static void (* _lwp_exitfunc )(void );
@@ -47,10 +48,6 @@ extern void _cpu_context_restore(void *);
4748extern void _cpu_context_save_fp (void * );
4849extern void _cpu_context_restore_fp (void * );
4950
50- extern int __libc_create_hook (lwp_cntrl * ,lwp_cntrl * );
51- extern int __libc_start_hook (lwp_cntrl * ,lwp_cntrl * );
52- extern int __libc_delete_hook (lwp_cntrl * , lwp_cntrl * );
53-
5451extern void kprintf (const char * str , ...);
5552
5653#ifdef _LWPTHREADS_DEBUG
@@ -80,6 +77,13 @@ void __lwp_dumpcontext_fp(lwp_cntrl *thrA,lwp_cntrl *thrB)
8077}
8178#endif
8279
80+ struct _reent * __SYSCALL (getreent )()
81+ {
82+ if ( _thr_executing == NULL || _thr_executing -> libc_reent == NULL ) return _GLOBAL_REENT ;
83+
84+ return _thr_executing -> libc_reent ;
85+ }
86+
8387/*
8488void __lwp_getthreadlist(lwp_obj **thrs)
8589{
@@ -193,10 +197,6 @@ void __thread_dispatch(void)
193197 _thr_executing = heir ;
194198 _CPU_ISR_Restore (level );
195199
196- if (__lwp_thr_libc_reent ) {
197- exec -> libc_reent = * __lwp_thr_libc_reent ;
198- * __lwp_thr_libc_reent = heir -> libc_reent ;
199- }
200200#ifdef _DEBUG
201201 _cpu_context_switch_ex ((void * )& exec -> context ,(void * )& heir -> context );
202202#else
@@ -617,7 +617,7 @@ u32 __lwp_thread_init(lwp_cntrl *thethread,void *stack_area,u32 stack_size,u32 p
617617 thethread -> res_cnt = 0 ;
618618 __lwp_thread_setpriority (thethread ,prio );
619619
620- __libc_create_hook ( _thr_executing , thethread ) ;
620+ thethread -> libc_reent = NULL ;
621621
622622 return 1 ;
623623}
@@ -646,7 +646,10 @@ void __lwp_thread_close(lwp_cntrl *thethread)
646646 thethread -> budget_algo = LWP_CPU_BUDGET_ALGO_NONE ;
647647 _CPU_ISR_Restore (level );
648648
649- __libc_delete_hook (_thr_executing ,thethread );
649+ struct _reent * ptr = thethread -> libc_reent ;
650+ _reclaim_reent (ptr );
651+ free (ptr );
652+ thethread -> libc_reent = NULL ;
650653
651654 if (__lwp_thread_isallocatedfp (thethread ))
652655 __lwp_thread_deallocatefp ();
@@ -701,7 +704,12 @@ u32 __lwp_thread_start(lwp_cntrl *thethread,void* (*entry)(void*),void *arg)
701704 thethread -> arg = arg ;
702705 __lwp_thread_loadenv (thethread );
703706 __lwp_thread_ready (thethread );
704- __libc_start_hook (_thr_executing ,thethread );
707+ struct _reent * ptr = (struct _reent * )calloc (1 ,sizeof (struct _reent ));
708+ if (!ptr ) abort ();
709+
710+ _REENT_INIT_PTR ((ptr ));
711+
712+ thethread -> libc_reent = ptr ;
705713 return 1 ;
706714 }
707715 return 0 ;
0 commit comments