Exemplo n.º 1
0
int
main (int   argc,
      char *argv[])
{
  int j, n_pages = 0;
  void *mps[N_MAGAZINE_PROBES];

  /* probe some magazine sizes */
  for (j = 0; j < N_MAGAZINE_PROBES; j++)
    mps[j] = g_slice_alloc (magazine_probes[j]);
  /* mps[*] now contains pointers to allocated slices */

  /* allocate blocks from N_PAGES different pages */
  while (n_pages < N_PAGES)
    {
      void *b = g_slice_alloc (SAMPLE_SIZE);
      void *p = (void*) (PAGE_SIZE * ((gsize) b / PAGE_SIZE));
      for (j = 0; j < N_PAGES; j++)
        if (pages[j].page == p)
          break;
      if (j < N_PAGES)  /* known page */
        free_list = g_slist_prepend (free_list, b);
      else              /* new page */
        {
          j = n_pages++;
          pages[j].page = p;
          pages[j].sample = b;
        }
    }
  /* release intermediate allocations */
  release_trash_list (&free_list, SAMPLE_SIZE);

  /* ensure that we can allocate from known pages */
  if (!allocate_from_known_page())
    g_error ("failed to allocate from magazine/page cache (before g_thread_init)");
  /* release intermediate allocations */
  release_trash_list (&free_list, SAMPLE_SIZE);

  /* release magazine probes to be retained */
  for (j = 0; j < N_MAGAZINE_PROBES; j++)
    g_slice_free1 (magazine_probes[j], mps[j]);
  /* mps[*] now contains pointers to releaed slices */

  /* ensure probes were retained */
  for (j = 0; j < N_MAGAZINE_PROBES; j++)
    {
      GSList *trash = NULL;
      guint k;
      for (k = 0; k < MAX_PROBE_TRIALS; k++)
        {
          void *mem = g_slice_alloc (magazine_probes[j]);
          if (mem == mps[j])
            break;      /* reallocated previously freed slice */
          trash = g_slist_prepend (trash, mem);
        }
      release_trash_list (&trash, magazine_probes[j]);
      if (k >= MAX_PROBE_TRIALS)        /* failed to reallocate slice */
        g_error ("failed to reallocate slice from magazine (before g_thread_init): size=%d", magazine_probes[j]);
    }
  /* mps[*] now contains pointers to reallocated slices */

  /* release magazine probes to be retained across g_thread_init */
  for (j = 0; j < N_MAGAZINE_PROBES; j++)
    g_slice_free1 (magazine_probes[j], mps[j]);
  /* mps[*] now contains pointers to released slices */

  /* initialize threading (should retain allocator state) */
  g_thread_init (NULL);

  /* ensure probes were retained */
  for (j = 0; j < N_MAGAZINE_PROBES; j++)
    {
      GSList *trash = NULL;
      guint k;
      for (k = 0; k < MAX_PROBE_TRIALS; k++)
        {
          void *mem = g_slice_alloc (magazine_probes[j]);
          if (mem == mps[j])
            break;      /* reallocated previously freed slice */
          trash = g_slist_prepend (trash, mem);
        }
      release_trash_list (&trash, magazine_probes[j]);
      if (k >= MAX_PROBE_TRIALS)        /* failed to reallocate slice */
        g_error ("failed to reallocate slice from magazine (after g_thread_init): size=%d", magazine_probes[j]);
    }
  /* mps[*] now contains pointers to reallocated slices */

  /* ensure that we can allocate from known pages */
  if (!allocate_from_known_page())
    g_error ("failed to allocate from magazine/page cache (after g_thread_init)");

  /* some cleanups */
  for (j = 0; j < N_MAGAZINE_PROBES; j++)
    g_slice_free1 (magazine_probes[j], mps[j]);
  release_trash_list (&free_list, SAMPLE_SIZE);

  return 0;
}
Exemplo n.º 2
0
int
main (int   argc,
      char *argv[])
{
  int j, n_pages = 0;
  void *mps[N_MAGAZINE_PROBES];
#ifdef __SYMBIAN32__
  g_log_set_handler (NULL,  G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
  g_set_print_handler(mrtPrintHandler);
  #endif /*__SYMBIAN32__*/
  /* probe some magazine sizes */
  for (j = 0; j < N_MAGAZINE_PROBES; j++)
    mps[j] = g_slice_alloc (magazine_probes[j]);
  /* mps[*] now contains pointers to allocated slices */

  /* allocate blocks from N_PAGES different pages */
  while (n_pages < N_PAGES)
    {
      void *b = g_slice_alloc (SAMPLE_SIZE);
      void *p = (void*) (PAGE_SIZE * ((gsize) b / PAGE_SIZE));
      for (j = 0; j < N_PAGES; j++)
        if (pages[j].page == p)
          break;
      if (j < N_PAGES)  /* known page */
        free_list = g_slist_prepend (free_list, b);
      else              /* new page */
        {
          j = n_pages++;
          pages[j].page = p;
          pages[j].sample = b;
        }
    }
  /* release intermediate allocations */
  release_trash_list (&free_list, SAMPLE_SIZE);

  /* ensure that we can allocate from known pages */
  if (!allocate_from_known_page())
    g_error ("failed to allocate from magazine/page cache (before g_thread_init)");
  /* release intermediate allocations */
  release_trash_list (&free_list, SAMPLE_SIZE);

  /* release magazine probes to be retained */
  for (j = 0; j < N_MAGAZINE_PROBES; j++)
    g_slice_free1 (magazine_probes[j], mps[j]);
  /* mps[*] now contains pointers to releaed slices */

  /* ensure probes were retained */
  for (j = 0; j < N_MAGAZINE_PROBES; j++)
    {
      GSList *trash = NULL;
      guint k;
      for (k = 0; k < MAX_PROBE_TRIALS; k++)
        {
          void *mem = g_slice_alloc (magazine_probes[j]);
          if (mem == mps[j])
            break;      /* reallocated previously freed slice */
          trash = g_slist_prepend (trash, mem);
        }
      release_trash_list (&trash, magazine_probes[j]);
      if (k >= MAX_PROBE_TRIALS)        /* failed to reallocate slice */
        g_error ("failed to reallocate slice from magazine (before g_thread_init): size=%d", magazine_probes[j]);
    }
  /* mps[*] now contains pointers to reallocated slices */

  /* release magazine probes to be retained across g_thread_init */
  for (j = 0; j < N_MAGAZINE_PROBES; j++)
    g_slice_free1 (magazine_probes[j], mps[j]);
  /* mps[*] now contains pointers to released slices */

  /* initialize threading (should retain allocator state) */
  g_thread_init (NULL);

  /* ensure probes were retained */
  for (j = 0; j < N_MAGAZINE_PROBES; j++)
    {
      GSList *trash = NULL;
      guint k;
      for (k = 0; k < MAX_PROBE_TRIALS; k++)
        {
          void *mem = g_slice_alloc (magazine_probes[j]);
          if (mem == mps[j])
            break;      /* reallocated previously freed slice */
          trash = g_slist_prepend (trash, mem);
        }
      release_trash_list (&trash, magazine_probes[j]);
      if (k >= MAX_PROBE_TRIALS)        /* failed to reallocate slice */
        g_error ("failed to reallocate slice from magazine (after g_thread_init): size=%d", magazine_probes[j]);
    }
  /* mps[*] now contains pointers to reallocated slices */

  /* ensure that we can allocate from known pages */
  if (!allocate_from_known_page())
    g_error ("failed to allocate from magazine/page cache (after g_thread_init)");

  /* some cleanups */
  for (j = 0; j < N_MAGAZINE_PROBES; j++)
    g_slice_free1 (magazine_probes[j], mps[j]);
  release_trash_list (&free_list, SAMPLE_SIZE);
#if __SYMBIAN32__
  testResultXml("slice-threadinit");
  #endif /* EMULATOR */
  return 0;
}