Beispiel #1
0
mm_task_combiner_prepare(struct mm_task_combiner *combiner, const char *name,
			 size_t size, size_t handoff)
{
	ENTER();

	mm_combiner_prepare(&combiner->combiner, size, handoff);

	MM_THREAD_LOCAL_ALLOC(mm_domain_selfptr(), name, combiner->wait_queue);
	for (mm_core_t core = 0; core < mm_core_getnum(); core++) {
		struct mm_list *wait_queue = MM_THREAD_LOCAL_DEREF(core, combiner->wait_queue);
		mm_list_prepare(wait_queue);
	}

	LEAVE();
}
Beispiel #2
0
mm_chunk_destroy(struct mm_chunk *chunk)
{
	mm_chunk_t tag = mm_chunk_gettag(chunk);

	// A chunk from a shared memory space can be freed by any thread in
	// the same manner utilizing synchronization mechanisms built-in to
	// the corresponding memory allocation routines.
	if (tag == MM_CHUNK_COMMON) {
		mm_common_free(chunk);
		return;
	}
	if (unlikely(tag == MM_CHUNK_GLOBAL)) {
		mm_global_free(chunk);
		return;
	}

	if (tag == MM_CHUNK_REGULAR) {
#if ENABLE_SMP
		// In SMP mode regular memory space is just another case of
		// shared space with built-in synchronization. So it can be
		// freed by any thread alike.
		mm_regular_free(chunk);
		return;
#else
		struct mm_domain *domain = mm_domain_selfptr();
		if (domain == mm_regular_domain) {
			mm_regular_free(chunk);
			return;
		}
#endif
	}

	// A chunk from a private space can be immediately freed by its
	// originating thread but it is a subject for asynchronous memory
	// reclamation mechanism for any other thread.
	struct mm_thread *thread = mm_thread_selfptr();
	struct mm_domain *domain = mm_thread_getdomain(thread);
	if (domain == mm_regular_domain && tag == mm_thread_getnumber(thread)) {
		mm_private_free(chunk);
		return;
	}

	thread->deferred_chunks_count++;
	mm_chunk_stack_insert(&thread->deferred_chunks, chunk);
	mm_chunk_enqueue_deferred(thread, false);
}
Beispiel #3
0
struct mm_chunk * MALLOC
mm_chunk_create(size_t size)
{
	// Prefer private space if available.
#if ENABLE_SMP
	struct mm_private_space *space = mm_private_space_get();
	if (mm_private_space_ready(space))
		return mm_chunk_create_private(size);
#else
	struct mm_domain *domain = mm_domain_selfptr();
	if (domain == mm_regular_domain && mm_private_space_ready(&mm_regular_space))
		return mm_chunk_create_regular(size);
#endif

	// Common space could only be used after it gets
	// initialized during bootstrap.
	if (likely(mm_common_space_ready()))
		return mm_chunk_create_common(size);

	// Use global allocator if everything else fails
	// (that is during bootstrap and shutdown).
	return mm_chunk_create_global(size);
}