sigprocmask(SIG_SETMASK, &self->p_start_args.mask, NULL);
/* Set the scheduling policy and priority for the new thread, if needed */
if (THREAD_GETMEM(self, p_start_args.schedpolicy) >= 0)
+ /* Explicit scheduling attributes were provided: apply them */
__sched_setscheduler(THREAD_GETMEM(self, p_pid),
THREAD_GETMEM(self, p_start_args.schedpolicy),
&self->p_start_args.schedparam);
+else if (__pthread_manager_thread.p_priority > 0)
+ /* Default scheduling required, but thread manager runs in realtime
+ scheduling: switch new thread to SCHED_OTHER policy */
+ {
+ struct sched_param default_params;
+ default_params.sched_priority = 0;
+ __sched_setscheduler(THREAD_GETMEM(self, p_pid),
+ SCHED_OTHER, &default_params);
+ }
/* Make gdb aware of new thread */
if (__pthread_threads_debug && __pthread_sig_debug > 0) {
request.req_thread = self;
sizeof (struct sched_param));
break;
case PTHREAD_INHERIT_SCHED:
- /* schedpolicy doesn't need to be set, only get priority */
+ new_thread->p_start_args.schedpolicy = __sched_getscheduler(father_pid);
__sched_getparam(father_pid, &new_thread->p_start_args.schedparam);
break;
}
MALLOC_HOOKS (default: NOT defined)
Define to enable support run-time replacement of the allocation
functions through user-defined `hooks'.
- REALLOC_ZERO_BYTES_FREES (default: NOT defined)
+ REALLOC_ZERO_BYTES_FREES (default: defined)
Define this if you think that realloc(p, 0) should be equivalent
- to free(p). Otherwise, since malloc returns a unique pointer for
- malloc(0), so does realloc(p, 0).
+ to free(p). (The C standard requires this behaviour, therefore
+ it is the default.) Otherwise, since malloc returns a unique
+ pointer for malloc(0), so does realloc(p, 0).
HAVE_MEMCPY (default: defined)
Define if you are not otherwise using ANSI STD C, but still
have memcpy and memset in your C library and want to use them.
#endif
/*
- REALLOC_ZERO_BYTES_FREES should be set if a call to
- realloc with zero bytes should be the same as a call to free.
- Some people think it should. Otherwise, since this malloc
- returns a unique pointer for malloc(0), so does realloc(p, 0).
+ REALLOC_ZERO_BYTES_FREES should be set if a call to realloc with
+ zero bytes should be the same as a call to free. The C standard
+ requires this. Otherwise, since this malloc returns a unique pointer
+ for malloc(0), so does realloc(p, 0).
*/
#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
#define MAP_ANONYMOUS MAP_ANON
#endif
+#if !defined(MAP_FAILED)
+#define MAP_FAILED ((char*)-1)
+#endif
#ifndef MAP_NORESERVE
# ifdef MAP_AUTORESRV
computed. */
+
+/* On some platforms we can compile internal, not exported functions better.
+ Let the environment provide a macro and define it to be empty if it
+ is not available. */
+#ifndef internal_function
+# define internal_function
+#endif
+
+
/*
Special defines for the Linux/GNU C library.
#endif
-/* On some platforms we can compile internal, not exported functions better.
- Let the environment provide a macro and define it to be empty if it
- is not available. */
-#ifndef internal_function
-# define internal_function
-#endif
-
\f
/* sizes, alignments */
(void)mutex_init(&list_lock);
}
-#endif
+#endif /* !defined NO_THREADS */
/* Initialization routine. */
#if defined(_LIBC)
return p;
}
+static void
+internal_function
#if __STD_C
-static void munmap_chunk(mchunkptr p)
+munmap_chunk(mchunkptr p)
#else
-static void munmap_chunk(p) mchunkptr p;
+munmap_chunk(p) mchunkptr p;
#endif
{
INTERNAL_SIZE_T size = chunksize(p);
#if HAVE_MREMAP
+static mchunkptr
+internal_function
#if __STD_C
-static mchunkptr mremap_chunk(mchunkptr p, size_t new_size)
+mremap_chunk(mchunkptr p, size_t new_size)
#else
-static mchunkptr mremap_chunk(p, new_size) mchunkptr p; size_t new_size;
+mremap_chunk(p, new_size) mchunkptr p; size_t new_size;
#endif
{
size_t page_mask = malloc_getpagesize - 1;
cp = (char *)mremap((char *)p - offset, size + offset, new_size,
MREMAP_MAYMOVE);
- if (cp == (char *)-1) return 0;
+ if (cp == MAP_FAILED) return 0;
p = (mchunkptr)(cp + offset);
if(next->size < MINSIZE &&
(unsigned long)sz > trim_threshold &&
ar_ptr != &main_arena) { /* fencepost */
- heap_info* heap = heap_for_ptr(top(ar_ptr));
+ heap_info *heap = heap_for_ptr(top(ar_ptr));
if(top(ar_ptr) == chunk_at_offset(heap, sizeof(*heap)) &&
heap->prev == heap_for_ptr(p))
into a user pointer with requested size sz. */
static Void_t*
+internal_function
#if __STD_C
chunk2mem_check(mchunkptr p, size_t sz)
#else
necessary. */
static int
+internal_function
#if __STD_C
top_check(void)
#else
#endif
{
Void_t *vptr = NULL;
+ mchunkptr victim;
tsd_getspecific(arena_key, vptr);
if(!vptr) {
- mchunkptr victim = chunk_alloc(&main_arena, request2size(sz));
- return victim ? chunk2mem(victim) : 0;
+ if(save_malloc_hook != malloc_check) {
+ victim = chunk_alloc(&main_arena, request2size(sz));
+ return victim ? chunk2mem(victim) : 0;
+ } else {
+ if(top_check() < 0) return 0;
+ victim = chunk_alloc(&main_arena, request2size(sz+1));
+ return victim ? chunk2mem_check(victim, sz) : 0;
+ }
} else {
/* Suspend the thread until the `atfork' handlers have completed.
By that time, the hooks will have been reset as well, so that
if (mem == 0) /* free(0) has no effect */
return;
- p = mem2chunk(mem);
+ p = mem2chunk(mem); /* do not bother to replicate free_check here */
#if HAVE_MMAP
if (chunk_is_mmapped(p)) /* release mmapped memory. */
(void)mutex_unlock(&ar_ptr->mutex);
}
-#endif
+#endif /* !defined NO_THREADS */
#endif /* defined _LIBC || defined MALLOC_HOOKS */