* eina: call malloc only when content is requested from the pool.
authorcedric <cedric>
Tue, 21 Sep 2010 15:18:15 +0000 (15:18 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 21 Sep 2010 15:18:15 +0000 (15:18 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@52543 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/modules/mp/one_big/eina_one_big.c

index 27bfe83..1b810e6 100644 (file)
@@ -94,6 +94,16 @@ eina_one_big_malloc(void *data, __UNUSED__ unsigned int size)
         goto on_exit;
      }
 
+   if (!pool->base)
+     {
+       pool->base = malloc(pool->item_size * pool->max);
+       if (!pool->base)
+         {
+            eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
+            goto retry_smaller;
+         }
+     }
+
    if (pool->served < pool->max)
      {
         mem = pool->base + (pool->served++ *pool->item_size);
@@ -101,7 +111,8 @@ eina_one_big_malloc(void *data, __UNUSED__ unsigned int size)
         goto on_exit;
      }
 
-      eina_error_set(0);
+ retry_smaller:
+   eina_error_set(0);
    mem = malloc(pool->item_size);
    if (!mem)
       eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
@@ -187,13 +198,6 @@ eina_one_big_init(const char *context,
         memcpy((char *)pool->name, context, length);
      }
 
-   pool->base = malloc(pool->item_size * pool->max);
-   if (!pool->base)
-     {
-        free(pool);
-        return NULL;
-     }
-
 #ifdef EFL_HAVE_THREADS
 # ifdef EFL_HAVE_POSIX_THREADS
    pthread_mutex_init(&pool->mutex, NULL);