This one actually works..

Original commit message from CVS:
This one actually works..
This commit is contained in:
Wim Taymans 2001-09-30 03:23:31 +00:00
parent 7bb4b2cefe
commit 4389c3a5c9
2 changed files with 35 additions and 22 deletions

View file

@ -6,20 +6,28 @@
#define CHUNK_LOCK ""
#endif
/*******************************************************
* area size
* +-----------------------------------------+
* chunk size
* +------------+
*
* !next!data... !next!data.... !next!data...
* ! ^ ! ^ !
* +-------------+ +------------+ +---> NULL
*
*/
static void
setup_area (guint8 *area, gint chunk_size, gulong area_size)
populate (GstMemChunk *mem_chunk)
{
guint8 *area;
gint i;
g_print ("setup area at %p, real area_size %lu, chunk size %d\n", area, area_size, chunk_size);
for (i = 0; i < area_size; i += chunk_size) {
guint8 *next;
area = (guint8 *)g_malloc0 (mem_chunk->area_size);
next = area + chunk_size;
((GstMemChunkElement *)area)->link = (gpointer)(next);
area = next;
for (i = 0; i < mem_chunk->area_size; i += mem_chunk->chunk_size) {
gst_mem_chunk_free (mem_chunk, area + sizeof (gpointer));
area += mem_chunk->chunk_size;
}
}
@ -30,22 +38,22 @@ gst_mem_chunk_new (gchar * name, gint atom_size, gulong area_size, gint type)
GstMemChunk *mem_chunk;
gint chunk_size;
g_print ("create: atom size %d, area_size %lu\n", atom_size, area_size);
//g_print ("create: atom size %d, area_size %lu\n", atom_size, area_size);
chunk_size = atom_size + sizeof (gpointer);
area_size = (area_size/atom_size) * chunk_size;
g_print ("chunk size %d, real area_size %lu\n", chunk_size, area_size);
//g_print ("chunk size %d, real area_size %lu\n", chunk_size, area_size);
mem_chunk = g_malloc (sizeof (GstMemChunk));
mem_chunk->free = g_malloc0 (area_size);
mem_chunk->free = NULL;
mem_chunk->cnt = 0;
mem_chunk->atom_size = atom_size;
mem_chunk->chunk_size = chunk_size;
mem_chunk->area_size = area_size;
setup_area ((guint8 *)mem_chunk->free, chunk_size, area_size);
populate (mem_chunk);
return mem_chunk;
}
@ -54,11 +62,12 @@ gpointer
gst_mem_chunk_alloc (GstMemChunk *mem_chunk)
{
guint8 *chunk = NULL;
g_return_val_if_fail (mem_chunk != NULL, NULL);
again:
__asm__ __volatile__ ("testl %%eax, %%eax \n\t"
"jz 20f \n"
"jz 20f \n"
"10:\t"
"movl (%%eax), %%ebx \n\t"
"movl %%edx, %%ecx \n\t"
@ -67,15 +76,17 @@ gst_mem_chunk_alloc (GstMemChunk *mem_chunk)
"jz 20f \n\t"
"testl %%eax, %%eax \n\t"
"jnz 10b \n"
"20:\t":"=a" (chunk):"m" (*mem_chunk),
"a" (mem_chunk->free), "d" (mem_chunk->cnt):"ecx",
"ebx");
"20:\t"
:"=a" (chunk)
:"m" (*mem_chunk), "a" (mem_chunk->free), "d" (mem_chunk->cnt)
:"ecx", "ebx");
if (chunk)
chunk += sizeof (gpointer);
else {
g_print ("empty\n");
exit (-1);
//g_print ("extending\n");
populate (mem_chunk);
goto again;
}
return (gpointer) chunk;
@ -92,5 +103,7 @@ gst_mem_chunk_free (GstMemChunk *mem_chunk, gpointer mem)
__asm__ __volatile__ ( "1:\t"
"movl %2, (%1) \n"
CHUNK_LOCK "cmpxchg %1, %0 \n\t"
"jnz 1b \n\t"::"m" (*mem_chunk), "r" (chunk), "a" (mem_chunk->free));
"jnz 1b \n\t"
:
:"m" (*mem_chunk), "r" (chunk), "a" (mem_chunk->free));
}

View file

@ -56,7 +56,7 @@ main (gint argc, gchar *argv[])
num_threads = atoi (argv[1]);
num_allocs = atoi (argv[2]);
_chunks = gst_mem_chunk_new ("test", 32, 32 * 16, G_ALLOC_AND_FREE);
_chunks = gst_mem_chunk_new ("test", 32, 32 * 4, G_ALLOC_AND_FREE);
for(t=0; t < num_threads; t++) {
rc = pthread_create (&threads[t], NULL, run_test, (void *)t);