Esempio n. 1
0
int32_t main(int32_t argc, char **argv)
{
      
    struct mem_pool *test_mem_pool;
    struct mem_pool *test_mem_pool_2;
    struct mem_pool *test_mem_pool_3;
    gf_mem_init_mempool_list();
    gf_mem_acct_enable_set ();
    signals_setup();
    mem_acct_init(gf_common_mt_end+1);
    test_mem_t ** mem_array   = CALLOC(size,sizeof(test_mem_t * )); 
    test_mem_2_t ** mem_array2  = CALLOC(size,sizeof(test_mem_2_t * ));
    test_mem_3_t ** mem_array3  = CALLOC(size,sizeof(test_mem_3_t * ));
    int j;
    int i;
    CPU_TIME_START;
    test_mem_pool = mem_pool_new (test_mem_t, size);
    test_mem_pool_2 = mem_pool_new (test_mem_2_t, size);
    test_mem_pool_3 = mem_pool_new (test_mem_3_t, size);
    CPU_TIME_END_PRINT("mem pool");
    CPU_TIME_START;
    for(j=0; j<10000; j++){    
            if (!test_mem_pool)
            {
                DBG_PRINT("create mem pool error");
                return -1;
            }
        for(i=0; i<size; i++)
            mem_array[i] = (test_mem_t *)mem_get(test_mem_pool);
            mem_array2[i] = (test_mem_2_t *)mem_get(test_mem_pool_2);
            mem_array3[i] = (test_mem_3_t *)mem_get(test_mem_pool_3);
        for(i=0; i<size; i++)
            mem_put(mem_array[i]) ;
            mem_put(mem_array2[i]) ;
            mem_put(mem_array3[i]) ;
        
    }
    CPU_TIME_END_PRINT("mem pool");
    mem_pool_destroy(test_mem_pool);
    mem_pool_destroy(test_mem_pool_2);
    mem_pool_destroy(test_mem_pool_3);
    CPU_TIME_START;
    for(j=0; j<100; j++){
        for(i=0; i<size; i++)
            mem_array[i] = (test_mem_t *)MALLOC(sizeof(test_mem_t));
            mem_array2[i] = (test_mem_2_t *)MALLOC(sizeof(test_mem_2_t));
            mem_array3[i] = (test_mem_3_t *)MALLOC(sizeof(test_mem_3_t));
        for(i=0; i<size; i++)
            free (mem_array[i]);
            free (mem_array2[i]);
            free (mem_array3[i]);
    }
    CPU_TIME_END_PRINT("not mem pool");
    
    //getchar();
    return 0;
}
Esempio n. 2
0
void *
rbthash_remove (rbthash_table_t *tbl, void *key, int keylen)
{
        struct rbthash_bucket   *bucket = NULL;
        rbthash_entry_t         *entry = NULL;
        rbthash_entry_t         searchentry = {0, };
        void                    *dataref = NULL;

        if ((!tbl) || (!key))
                return NULL;

        bucket = rbthash_key_bucket (tbl, key, keylen);
        if (!bucket) {
                gf_log (GF_RBTHASH, GF_LOG_ERROR, "Failed to get bucket");
                return NULL;
        }

        searchentry.key = key;
        searchentry.keylen = keylen;

        LOCK (&bucket->bucketlock);
        {
                entry = rb_delete (bucket->bucket, &searchentry);
        }
        UNLOCK (&bucket->bucketlock);

        if (!entry)
                return NULL;

        GF_FREE (entry->key);
        dataref = entry->data;
        mem_put (tbl->entrypool, entry);

        return dataref;
}
Esempio n. 3
0
void
ga_heal_args_free (ga_heal_args_t *args)
{
        if (!args)
                goto out;

        GF_FREE (args->bname);

        mem_put (args);
out:
        return;
}
/** Write bytes from a buffer into a memory stream.
 * The internal buffer is expanded as needed to hold the data,
 * up to the stream maximum (if specified). If the buffer cannot
 * be expanded -ENOMEM is returned.
 *
 * @param io mem stream
 * @param buf buffer
 * @param n number of bytes to write
 * @return number of bytes written on success, negative error code otherwise
 */
static int mem_write(IOStream *io, const void *msg, size_t n){
    int room;
    MemData *data = get_mem_data(io);
    if(data->err) return -data->err;
    room = mem_room(data);
    if(n > room){
        int err = mem_expand(data, n - room);
        if(err) return err;
    }
    mem_put(data, msg, n);
    data->hi += n;
    return n;
}
Esempio n. 5
0
void
ga_newfile_args_free (ga_newfile_args_t *args)
{
        if (!args)
                goto out;

        GF_FREE (args->bname);

        if (S_ISLNK (args->st_mode) && args->args.symlink.linkpath) {
                GF_FREE (args->args.symlink.linkpath);
                args->args.symlink.linkpath = NULL;
        }

        mem_put (args);
out:
        return;
}
Esempio n. 6
0
void
rbthash_deinit_entry (rbthash_table_t *tbl, rbthash_entry_t *entry)
{

        if (!entry)
                return;

        if (entry->key)
                GF_FREE (entry->key);

        if (tbl) {
                if ((entry->data) && (tbl->dfunc))
                        tbl->dfunc (entry->data);
                mem_put (tbl->entrypool, entry);
        }

        return;
}
Esempio n. 7
0
static void
sdfs_local_cleanup (sdfs_local_t *local)
{
        if (!local)
                return;

        loc_wipe (&local->loc);
        loc_wipe (&local->parent_loc);

        if (local->stub) {
                call_stub_destroy (local->stub);
                local->stub = NULL;
        }

        sdfs_lock_array_free (local->lock);
        GF_FREE (local->lock);

        mem_put (local);
}
Esempio n. 8
0
static int skipws(void)
{
	int clen;
	char *cbuf;
	while (1) {
		if (cur == len) {
			clen = 0;
			while (!clen)
				if (cpp_read(&cbuf, &clen))
					return 1;
			mem_put(&tok_mem, cbuf, clen);
			buf = mem_buf(&tok_mem);
			len = mem_len(&tok_mem);
		}
		while (cur < len && isspace(buf[cur]))
			cur++;
		if (cur == len)
			continue;
		if (buf[cur] == '\\' && buf[cur + 1] == '\n') {
			cur += 2;
			continue;
		}
		if (buf[cur] == '/' && buf[cur + 1] == '/') {
			while (++cur < len && buf[cur] != '\n')
				if (buf[cur] == '\\')
					cur++;
			continue;
		}
		if (buf[cur] == '/' && buf[cur + 1] == '*') {
			while (++cur < len) {
				if (buf[cur] == '*' && buf[cur + 1] == '/') {
					cur += 2;
					break;
				}
			}
			continue;
		}
		break;
	}
	return 0;
}
Esempio n. 9
0
int  mem_get(char *id) 
{
  int currentIndex;
  currentIndex = hash(id);
  if (Memory[currentIndex] == NULL)
    {
      printf("\n*** WARNING: Read uninitialized variables \"%s\". Return value 0\n", id);
      mem_put(id, 0);
      
      return 0;
    }

  if (Memory[currentIndex] != NULL && strcmp(Memory[currentIndex]->name, id) ) 
    {
      printf("\n*** Memory conflict: Variables \"%s\" and \"%s\" map to same memory location %d\n", Memory[currentIndex]->name, id, currentIndex);
      exit (-1);
    }
    
  return( Memory[currentIndex]->value);   
  
}
Esempio n. 10
0
rbthash_entry_t *
rbthash_init_entry (rbthash_table_t *tbl, void *data, void *key, int keylen)
{
    int             ret = -1;
    rbthash_entry_t *entry = NULL;

    if ((!tbl) || (!data) || (!key))
        return NULL;

    entry = mem_get (tbl->entrypool);
    if (!entry) {
        lz_log (LZ_RBTHASH, LZ_LOG_ERROR, "Failed to get entry from"
                " mem-pool");
        goto ret;
    }

    entry->data = data;
    entry->key = CALLOC (keylen, sizeof (char));
    if (!entry->key) {
        lz_log (LZ_RBTHASH, LZ_LOG_ERROR, "Memory allocation failed");
        goto free_entry;
    }

    memcpy (entry->key, key, keylen);
    entry->keylen = keylen;
    entry->keyhash = tbl->hashfunc (entry->key, entry->keylen);
    lz_log (LZ_RBTHASH, LZ_LOG_TRACE, "HASH: %u", entry->keyhash);

    ret = 0;
free_entry:
    if (ret == -1) {
        mem_put (tbl->entrypool, entry);
        entry = NULL;
    }

ret:
    return entry;
}
Esempio n. 11
0
void Mem_LoadApp (void)
{
    U32 DataOffset, MapOffset, DataLen, MapLen,
        CODE0, SIZE, AppHeapAvail, RequestSize,
        MinSize, Count;
    U8 Compat32=0;
    char Temp[256];

    CODE0=Res_GetOffset('CODE',0); //Find CODE 0
    CODE0+=4;

    Mem_JumpSize=FlipL(Mem_GetL(ResP,CODE0 - 4));

    if(FlipW(Mem_GetW(ResP,CODE0 + 0x10))==0x0004 || Res_GetOffset('rseg',0))
        Port_Puts(PUTS_DEBUG,"Mem_LoadApp (mem.c)","CFM-68K");
    else
        Port_Puts(PUTS_DEBUG,"Mem_LoadApp (mem.c)","Classic 68K");

    //Total App mem - jump table size - 66KB - 32
    //That gives the stack 32KB and a 2KB seperator from heap
    AppHeapAvail=(Mem_App_End - Mem_App_Start)
                 - Mem_JumpSize
                 - 0x10800
                 - 32;

    AppHeapLimit=0;

    SIZE=Res_GetOffset('SIZE',0); //Find SIZE 0
    if(SIZE)
    {
        SIZE+=4;

        if((ResP[SIZE+1] & 0x80) == 0x80) //Endianness (bit 0 = bit 7)
            Compat32=1;
        else
            Compat32=0;

        RequestSize=FlipL(Mem_GetL(ResP,SIZE+2));
        MinSize=FlipL(Mem_GetL(ResP,SIZE+6));
    }
    else
    {
        SIZE=Res_GetOffset('SIZE',0xFFFF); //Find SIZE -1
        if(SIZE)
        {
            SIZE+=4;

            if((ResP[SIZE+1] & 0x80) == 0x80) //Endianness (bit 0 = bit 7)
                Compat32=1;
            else
                Compat32=0;

            RequestSize=FlipL(Mem_GetL(ResP,SIZE+2));
            MinSize=FlipL(Mem_GetL(ResP,SIZE+6));
        }
        else
        {
            RequestSize=0x80000; //512KB
            MinSize=0;
        }
    }

/* For future use (when a 32-bit CPU is emulated)
    if(Compat32==0)
        Port_Puts(PUTS_WARNING,"Mem_LoadApp (mem.c)","Application may not be 32-bit compatible");
    if(Compat32==1)
        Port_Puts(PUTS_DEBUG,"Mem_LoadApp (mem.c)","Application is 32-bit compatible");
*/

    if(RequestSize>AppHeapAvail)
    {
        if(MinSize>AppHeapAvail)
        {
            Port_Puts(PUTS_ERROR,"Mem_LoadApp (mem.c)","Application requires more memory than is available");
            File_Close(ResP);
            App_Exit();
        }
        else
        {
            AppHeapLimit=AppHeapAvail; //Use all available app memory
            Port_Puts(PUTS_DEBUG,"Mem_LoadApp (mem.c)","Application requests more memory than is available, but\nthere is enough to satisfy minimum requirement. Using all available app memory");
        }
    }
    else
        AppHeapLimit=RequestSize; //Max out at requested memory size

    //Heap Size + 32KB (Stack) + 2KB (Buffer)
    Mem_Stack=Mem_App_Start+AppHeapLimit+0x8800;
    //Mem_Stack is end of stack, since it's FILO

    if((Mem_Stack % 2) == 1) //If it's odd
        ++Mem_Stack; //Make it even

    //Mem_Stack (Heap Size + 32KB (Stack) + 2KB) + 32KB (App Globals)
    Mem_A5=Mem_Stack+0x8000;

    if((Mem_A5 % 2) == 1) //If it's odd
        ++Mem_A5; //Make it even

    A[5]=Mem_A5;
    A[8]=Mem_Stack; //Stack Pointer
    A[6]=Mem_Stack; //Stack Frame

    //Copy jump table into memory
    for(Count=0;Count<Mem_JumpSize;++Count)
        mem_put(ResP[CODE0+Count],Mem_A5+32+Count,BYTE);

    mem_put(32,Mem_A5+32+0xC,LONG); //Jump table offset
    mem_put(32,0x934,WORD); //CurJTOffset

    //A5 + AppParams + JumpTable Header + First Offset WORD
    PC=Mem_A5+32+0x10+2; //Run code in jump table to load entry point

    return;
}
Esempio n. 12
0
static void
inst_store(struct machine *m)
{
  mem_put(m, m->cpu.abr, m->cpu.dbb);
}