[haiku-commits] haiku: hrev52687 - src/system/libroot/os src/system/libroot/posix/malloc_debug src/system/libroot/posix/malloc headers/private/libroot src/system/libroot/stubbed

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 25 Dec 2018 18:00:23 -0500 (EST)

hrev52687 adds 1 changeset to branch 'master'
old head: 20e0f7607c4f0fe784a4b2cb800aeff67fb2652e
new head: e4103b1b92852e3fc293c8e3b8857e5bd58e8dc3
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=e4103b1b9285+%5E20e0f7607c4f

----------------------------------------------------------------------------

e4103b1b9285: libroot: Introduce thread specific heap init/exit hooks.
  
  This allows heap implementations to initialize and clean up any thread
  specific structures. The current default hoard heap does not use these.
  
  Note that the thread exit hook will not be called for the main thread as
  the heap may be needed during process termination (__cxa_finalize for
  example).
  
  Change-Id: I703fbd34dec0d9029d619a2125c5b19d8c1933aa
  Reviewed-on: https://review.haiku-os.org/799
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

                                            [ Michael Lotz <mmlr@xxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev52687
Commit:      e4103b1b92852e3fc293c8e3b8857e5bd58e8dc3
URL:         https://git.haiku-os.org/haiku/commit/?id=e4103b1b9285
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Tue Dec 25 19:52:57 2018 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Tue Dec 25 23:00:20 2018 UTC

----------------------------------------------------------------------------

6 files changed, 35 insertions(+), 2 deletions(-)
headers/private/libroot/libroot_private.h                |  2 ++
src/system/libroot/os/thread.c                           |  7 +++++--
src/system/libroot/posix/malloc/wrapper.cpp              | 12 ++++++++++++
.../libroot/posix/malloc_debug/malloc_debug_api.cpp      | 12 ++++++++++++
src/system/libroot/posix/pthread/pthread.cpp             |  2 ++
src/system/libroot/stubbed/libroot_stubs.c               |  2 ++

----------------------------------------------------------------------------

diff --git a/headers/private/libroot/libroot_private.h 
b/headers/private/libroot/libroot_private.h
index 79ec524e6f..caa9be1cce 100644
--- a/headers/private/libroot/libroot_private.h
+++ b/headers/private/libroot/libroot_private.h
@@ -39,6 +39,8 @@ void __heap_terminate_after(void);
 void __heap_before_fork(void);
 void __heap_after_fork_child(void);
 void __heap_after_fork_parent(void);
+void __heap_thread_init(void);
+void __heap_thread_exit(void);
 
 void __init_time(addr_t commPageTable);
 void __arch_init_time(struct real_time_data *data, bool setDefaults);
diff --git a/src/system/libroot/os/thread.c b/src/system/libroot/os/thread.c
index 41e105e4c5..c92ce075f3 100644
--- a/src/system/libroot/os/thread.c
+++ b/src/system/libroot/os/thread.c
@@ -37,11 +37,13 @@ thread_entry(void* _entry, void* _thread)
 {
        thread_func entry = (thread_func)_entry;
        pthread_thread* thread = (pthread_thread*)_thread;
-       status_t returnCode;
 
-       returnCode = entry(thread->entry_argument);
+       __heap_thread_init();
+
+       status_t returnCode = entry(thread->entry_argument);
 
        _thread_do_exit_work();
+       __heap_thread_exit();
 
        return returnCode;
 }
@@ -168,6 +170,7 @@ void
 exit_thread(status_t status)
 {
        _thread_do_exit_work();
+       __heap_thread_exit();
        _kern_exit_thread(status);
 }
 
diff --git a/src/system/libroot/posix/malloc/wrapper.cpp 
b/src/system/libroot/posix/malloc/wrapper.cpp
index 4465f512ea..ead5d22b4b 100644
--- a/src/system/libroot/posix/malloc/wrapper.cpp
+++ b/src/system/libroot/posix/malloc/wrapper.cpp
@@ -285,6 +285,18 @@ __heap_after_fork_parent(void)
 }
 
 
+extern "C" void
+__heap_thread_init(void)
+{
+}
+
+
+extern "C" void
+__heap_thread_exit(void)
+{
+}
+
+
 //     #pragma mark - public functions
 
 
diff --git a/src/system/libroot/posix/malloc_debug/malloc_debug_api.cpp 
b/src/system/libroot/posix/malloc_debug/malloc_debug_api.cpp
index bf38d4c9e7..4a0f87022a 100644
--- a/src/system/libroot/posix/malloc_debug/malloc_debug_api.cpp
+++ b/src/system/libroot/posix/malloc_debug/malloc_debug_api.cpp
@@ -220,6 +220,18 @@ __heap_after_fork_parent(void)
 }
 
 
+extern "C" void
+__heap_thread_init(void)
+{
+}
+
+
+extern "C" void
+__heap_thread_exit(void)
+{
+}
+
+
 // #pragma mark - Public API
 
 
diff --git a/src/system/libroot/posix/pthread/pthread.cpp 
b/src/system/libroot/posix/pthread/pthread.cpp
index 967fb70024..6bd62f9f36 100644
--- a/src/system/libroot/posix/pthread/pthread.cpp
+++ b/src/system/libroot/posix/pthread/pthread.cpp
@@ -40,6 +40,8 @@ pthread_thread_entry(void*, void* _thread)
 {
        pthread_thread* thread = (pthread_thread*)_thread;
 
+       __heap_thread_init();
+
        pthread_exit(thread->entry(thread->entry_argument));
        return 0;
 }
diff --git a/src/system/libroot/stubbed/libroot_stubs.c 
b/src/system/libroot/stubbed/libroot_stubs.c
index 370a85126b..cd05405dcf 100644
--- a/src/system/libroot/stubbed/libroot_stubs.c
+++ b/src/system/libroot/stubbed/libroot_stubs.c
@@ -880,6 +880,8 @@ void __heap_after_fork_child() {}
 void __heap_after_fork_parent() {}
 void __heap_before_fork() {}
 void __heap_terminate_after() {}
+void __heap_thread_init() {}
+void __heap_thread_exit() {}
 void __hypot() {}
 void __hypotf() {}
 void __hypotl() {}


Other related posts:

  • » [haiku-commits] haiku: hrev52687 - src/system/libroot/os src/system/libroot/posix/malloc_debug src/system/libroot/posix/malloc headers/private/libroot src/system/libroot/stubbed - waddlesplash