Skip to content

Commit 37ac6ee

Browse files
committed
CHAIN: allocate before the main
1 parent fb2d8df commit 37ac6ee

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/sctk_alloc_posix.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ SCTK_INTERN struct sctk_alloc_chain * sctk_alloc_posix_create_new_tls_chain(void
519519
* Setup the allocation chain for the current thread. It init an allocation chain and point it with
520520
* the TLS sctk_current_alloc_chain.
521521
**/
522+
522523
SCTK_INTERN struct sctk_alloc_chain * sctk_alloc_posix_setup_tls_chain(void)
523524
{
524525
//vars
@@ -544,6 +545,18 @@ SCTK_INTERN struct sctk_alloc_chain * sctk_alloc_posix_setup_tls_chain(void)
544545
return chain;
545546
}
546547

548+
/* Ensure Main thread has an allocator before the main */
549+
void __build_tls_chain(void) __attribute__ ((constructor));
550+
551+
void __build_tls_chain(void)
552+
{
553+
if(sctk_get_tls_chain() == NULL)
554+
{
555+
sctk_alloc_posix_setup_tls_chain();
556+
}
557+
}
558+
559+
547560
/************************* FUNCTION ************************/
548561
SCTK_PUBLIC void * sctk_calloc (size_t nmemb, size_t size)
549562
{

0 commit comments

Comments
 (0)