EAPI Eina_Stringshare * eina_stringshare_ref(Eina_Stringshare *str) { int slen; if (!str) return eina_share_common_ref(stringshare_share, str); /* special cases */ if (str[0] == '\0') slen = 0; else if (str[1] == '\0') slen = 1; else if (str[2] == '\0') slen = 2; else if (str[3] == '\0') slen = 3; else slen = 3 + (int)strlen(str + 3); if (slen < 2) { eina_share_common_population_add(stringshare_share, slen); return str; } else if (slen < 4) { const char *s; eina_share_common_population_add(stringshare_share, slen); eina_lock_take(&_mutex_small); s = _eina_stringshare_small_add(str, slen); eina_lock_release(&_mutex_small); return s; } return eina_share_common_ref(stringshare_share, str); }
static void * _eio_pool_malloc(Eio_Alloc_Pool *pool) { void *result = NULL; if (pool->count) { eina_lock_take(&(pool->lock)); result = eina_trash_pop(&pool->trash); if (result) pool->count--; eina_lock_release(&(pool->lock)); } if (!result) { result = malloc(pool->mem_size); eina_spinlock_take(&memory_pool_lock); if (result) memory_pool_usage += pool->mem_size; eina_spinlock_release(&memory_pool_lock); } return result; }
EAPI void ecore_fork_reset(void) { Eina_List *l, *ln; Ecore_Fork_Cb *fcb; eina_lock_take(&_thread_safety); ecore_pipe_del(_thread_call); _thread_call = ecore_pipe_add(_thread_callback, NULL); /* If there was something in the pipe, trigger a wakeup again */ if (_thread_cb) ecore_pipe_write(_thread_call, &wakeup, sizeof (int)); eina_lock_release(&_thread_safety); // should this be done withing the eina lock stuff? fork_cbs_walking++; EINA_LIST_FOREACH(fork_cbs, l, fcb) { fcb->func(fcb->data); }
static void * eina_one_big_malloc(void *data, EINA_UNUSED unsigned int size) { One_Big *pool = data; unsigned char *mem = NULL; if (!eina_lock_take(&pool->mutex)) { #ifdef EINA_HAVE_DEBUG_THREADS assert(eina_thread_equal(pool->self, eina_thread_self())); #endif } if (pool->empty) { #ifndef NVALGRIND VALGRIND_MAKE_MEM_DEFINED(pool->empty, pool->item_size); #endif mem = eina_trash_pop(&pool->empty); pool->usage++; goto on_exit; } if (!pool->base) { pool->base = malloc(pool->item_size * pool->max); if (!pool->base) goto retry_smaller; #ifndef NVALGRIND VALGRIND_MAKE_MEM_NOACCESS(pool->base, pool->item_size * pool->max); #endif } if (pool->served < pool->max) { mem = pool->base + (pool->served++ *pool->item_size); pool->usage++; goto on_exit; } retry_smaller: mem = malloc(sizeof(Eina_Inlist) + pool->offset_to_item_inlist); if (mem) { Eina_Inlist *node = OVER_MEM_TO_LIST(pool, mem); pool->over++; /* Only need to zero list elements and not the payload here */ memset(node, 0, sizeof(Eina_Inlist)); pool->over_list = eina_inlist_append(pool->over_list, node); } #ifndef NVALGRIND VALGRIND_MAKE_MEM_NOACCESS(mem, pool->item_size); #endif on_exit: eina_lock_release(&pool->mutex); #ifndef NVALGRIND VALGRIND_MEMPOOL_ALLOC(pool, mem, pool->item_size); #endif return mem; }