Beispiel #1
0
float    timerprocessor_c::takt(double dt)
{
    //RECURSIVE_ALERT(); recursive calls allowed. sys_idle can be called from timeup

    tmp_array_del_t<timer_subscriber_entry_s, 32> processing;

    float nexttime = -1;
    aint cnt = m_items.size();
    for (aint i = 0; i < cnt;)
    {
        timer_subscriber_entry_s * e = m_items.get(i);
        if (timer_subscriber_c *t = e->hook.get())
        {
            e->ttl -= dt;
            if (e->ttl < 0)
            {
                processing.add(m_items.get_remove_fast(i));
                --cnt;
                continue;
            } else
            {
                if (nexttime < 0 || e->ttl < nexttime)
                    nexttime = (float)e->ttl;
            }
        }
        ++i;
    }

    for (timer_subscriber_entry_s *e : processing)
    {
        timer_subscriber_c *t = e->hook.get();
        e->hook.unconnect();
        void * par = e->param;
        if (t) t->timeup(par);
    }

    for (int i = 0; i < m_items.size();)
    {
        timer_subscriber_entry_s * e = m_items.get(i);
        if (e->hook.expired())
        {
            makefree( m_items.get_remove_fast(i) );
            continue;
        }
        ++i;
    }

    while (processing.size()) makefree(processing.get_last_remove());
    return nexttime;
}
Beispiel #2
0
void    timerprocessor_c::del(timer_subscriber_c *t)
{
    for (aint i = 0; i < m_items.size();)
    {
        if (t == m_items.get(i)->hook.get())
        {
            makefree( m_items.get_remove_fast(i) );
            continue;
        }
        ++i;
    }
}
void VoronoiDiagramGenerator::endpoint(struct VoronoiDiagramGenerator::Edge *e,int lr,struct VoronoiDiagramGenerator::Site * s)
{
	e -> ep[lr] = s;
	ref(s);
	if(e -> ep[re-lr]== (struct Site *) NULL) 
		return;

	clip_line(e);

	deref(e->reg[le]);
	deref(e->reg[re]);
	makefree((Freenode*)e, &efl);
}
Beispiel #4
0
void    timerprocessor_c::del(timer_subscriber_c *t, void * par)
{
    int cnt = m_items.size();
    for (int i = 0; i < cnt; ++i)
    {
        timer_subscriber_entry_s *at = m_items.get(i);
        if (at->param == par && t == at->hook.get())
        {
            makefree(m_items.get_remove_fast(i));
            return;
        }
    }
}
Beispiel #5
0
int main(void) {
    int total_size, choice, request_size;

    frame_echo("\tB U D D Y   S Y S T E M  R E Q U I R E M E N T S");

    printf("*  Enter the Size of the memory  :  ");

    scanf("%d", &total_size);

    while (1) {
        frame_echo("\tB U D D Y   S Y S T E M ");
        puts(" *  1)\tLocate the process into the Memory");
        puts(" *  2)\tRemove the process from Memory");
        puts(" *  3)\tTree structure for Memory allocation Map");
        puts(" *  4)\tExit");
        printf(" *  Enter your choice : ");

        scanf(" %d", &choice);

        switch (choice) {
            case 1:
                frame_echo("\tM E M O R Y   A L L O C A T I O N ");
                printf(" *  Enter the Process size  : ");

                scanf("%d", &request_size);

                segmentalloc(total_size, request_size);

                break;
            case 2:
                frame_echo("\tM E M O R Y   D E A L L O C A T I O N ");
                printf(" *  Enter the process size  :  ");

                scanf("%d", &request_size);

                makefree(request_size);

                break;
            case 3:
                frame_echo("\tM E M O R Y   A L L O C A T I O N   M A P ");

                printing(total_size, 0);

                putchar('\n');

                break;
            default:
                return 0;
        }
    }
}
Beispiel #6
0
void endpoint(Edge * e, int lr, Site * s)
{
    e->ep[lr] = s;
    ref(s);
    if (e->ep[re - lr] == (Site *) NULL)
	return;
    clip_line(e);
#ifdef STANDALONE
    out_ep(e);
#endif
    deref(e->reg[le]);
    deref(e->reg[re]);
    makefree(e, &efl);
}
/* Get entry from hash table, pruning any deleted nodes */
struct VoronoiDiagramGenerator::Halfedge * VoronoiDiagramGenerator::ELgethash(int b)
{
	struct Halfedge *he;
	
	if(b<0 || b>=ELhashsize) 
		return((struct Halfedge *) NULL);
	he = ELhash[b]; 
	if (he == (struct Halfedge *) NULL || he->ELedge != (struct Edge *) DELETED ) 
		return (he);
	
	/* Hash table points to deleted half edge.  Patch as necessary. */
	ELhash[b] = (struct Halfedge *) NULL;
	if ((he -> ELrefcnt -= 1) == 0) 
		makefree((Freenode*)he, &hfl);
	return ((struct Halfedge *) NULL);
}	
Beispiel #8
0
void *getfree(Freelist * fl)
{
    int i;
    Freenode *t;
    Freeblock *mem;

    if (fl->head == NULL) {
	int size = fl->nodesize;
	char *cp;

	mem = GNEW(Freeblock);
	mem->nodes = gmalloc(sqrt_nsites * size);
	cp = (char *) (mem->nodes);
	for (i = 0; i < sqrt_nsites; i++) {
	    makefree(cp + i * size, fl);
	}
	mem->next = fl->blocklist;
	fl->blocklist = mem;
    }
    t = fl->head;
    fl->head = t->nextfree;
    return ((void *) t);
}
char * VoronoiDiagramGenerator::getfree(struct VoronoiDiagramGenerator::Freelist *fl)
{
	int i; 
	struct Freenode *t;

	if(fl->head == (struct Freenode *) NULL)
	{	
		t =  (struct Freenode *) myalloc(sqrt_nsites * fl->nodesize);

		if(t == 0)
			return 0;
		
		currentMemoryBlock->next = new FreeNodeArrayList;
		currentMemoryBlock = currentMemoryBlock->next;
		currentMemoryBlock->memory = t;
		currentMemoryBlock->next = 0;

		for(i=0; i<sqrt_nsites; i+=1) 	
			makefree((struct Freenode *)((char *)t+i*fl->nodesize), fl);		
	};
	t = fl -> head;
	fl -> head = (fl -> head) -> nextfree;
	return((char *)t);
}
Beispiel #10
0
pass5()
{
struct	inodesc idesc;
	daddr_t	blkno;
	int	n;
	BUFAREA	*bp1, *bp2;
	extern int debug;

	bzero(&idesc, sizeof (idesc));
	idesc.id_type = ADDR;

	if(sflag)
		fixfree = 1;
	else {
		ifreechk();
		if(freemap)
			bcopy(blockmap, freemap, (int)bmapsz);
		else {
			for(blkno = 0; blkno < fmapblk-bmapblk; blkno++) {
				bp1 = getblk((BUFAREA *)NULL,blkno+bmapblk);
				bp2 = getblk((BUFAREA *)NULL,blkno+fmapblk);
				bcopy(bp1->b_un.b_buf,bp2->b_un.b_buf,DEV_BSIZE);
				dirty(bp2);
			}
		}
		badblk = dupblk = 0;
		freeblk.df_nfree = sblock.fs_nfree;
		for(n = 0; n < NICFREE; n++)
			freeblk.df_free[n] = sblock.fs_free[n];
		freechk();
		if(badblk)
			pfatal("%d BAD BLKS IN FREE LIST\n",badblk);
		if(dupblk)
			pwarn("%d DUP BLKS IN FREE LIST\n",dupblk);
		if (debug)
			printf("n_files %ld n_blks %ld n_free %ld fmax %ld fmin %ld ninode: %u\n",
				n_files, n_blks, n_free, fmax, fmin,sblock.fs_ninode);
		if(fixfree == 0) {
			if ((n_blks+n_free) != (fmax-fmin) && 
					dofix(&idesc, "BLK(S) MISSING"))
				fixfree = 1;
			else if (n_free != sblock.fs_tfree && 
			   dofix(&idesc,"FREE BLK COUNT WRONG IN SUPERBLOCK")) {
					sblock.fs_tfree = n_free;
					sbdirty();
				}
		}
		if(fixfree && !dofix(&idesc, "BAD FREE LIST"))
				fixfree = 0;
	}

	if(fixfree) {
		if (preen == 0)
			printf("** Phase 6 - Salvage Free List\n");
		makefree();
		n_free = sblock.fs_tfree;
		sblock.fs_ronly = 0;
		sblock.fs_fmod = 0;
		sbdirty();
	}
}
void VoronoiDiagramGenerator::deref(struct VoronoiDiagramGenerator::Site *v)
{
	v -> refcnt -= 1;
	if (v -> refcnt == 0 ) 
		makefree((Freenode*)v, &sfl);
}
Beispiel #12
0
int main()
{
	int totsize,totalalloc,ch,n,req=0;

	for(i=0;i<80;i++) printf("%c",5);
	printf("\n	************************************************************");
	printf("\n 	WELCOME TO (LAZY) BUDDY KERNEL MEMORY ALLOCATOR SIMULATION  ");
	printf("\n	************************************************************\n");
	for(i=0;i<80;i++) printf("%c",5);
	printf("\n We will run the simulation with a memory size = 1024 x (2's power) Bytes");
	printf("\n For power=1, it is 2 power 1 , 3 is 2 power 3 etc. ");
	printf("\n Our default is 1024 and if you enter power 0, it will stay 1024\n");
	printf("\n Enter the POWER OF 2 with which we will multiply default memory size: ");
	scanf("%d",&n);
	
	if (n>5)
		{
			printf("\n Sorry ..we do not support that much of memory in this simulation ...");
			exit(0);
		}
	
	totsize=1024*power(2,n);
	printf("\n TOTAL SYSTEM MEMORY IN BYTES FOR SIMULATION=%d \n", totsize);
	maxlevel=getLevel(totsize);
	maxnodes=power(2,maxlevel+1)-1;
	
	printf("\n ****************************************************************");
	printf("\n NOTE : MAXIMUM HEIGHT OF FULLY SPLIT BUDDY TREE =%d \n", maxlevel);
	printf("\n Starting from node size of 2 bytes, we can have maximum nodes =%d \n", maxnodes);
	printf("\n Our Array implementation of binary tree has ONLY size = %d ",MAXNODES);
	printf("\n So,accordingly select your memory request size..................");
	printf("\n We will allow a minimum size of 16 bytes");	
	printf("\n ****************************************************************");
	
    printf("\n\n Press a key to continue...");
	getchar();

	while(1)
	{
		for(i=0;i<80;i++) printf("%c",5);
		printf("\n ............................................\n");
		printf("\n LAZY BUDDY  SYSTEM  ALGORITHM SIMULATION....\n");
	
		for(i=0;i<80;i++) printf("%c",5);
		printf("	*  1)   Allocation request \n");
		printf("	*  2)   Free request \n");
		printf("	*  3)   Show Memory allocation \n");
		printf("	*  4)   Enable LAZY mode \n");
		printf("	*  5)   Disable LAZY mode \n");
		printf("	*  6)   End simulation\n");
		for(i=0;i<80;i++) printf("%c",5);
		printf("\n.........  Enter your choice  :  \n");
		scanf("%d",&ch);
		switch(ch)
		{
			case 1:
				//clear_screen();
				printf(" ");
				for(i=0;i<80;i++) printf("%c",5);
				printf(" ");
				printf("A L L O C A T I O N\n");
				for(i=0;i<80;i++) printf("%c",5);
				printf("\n  Enter the request size  : ");
				scanf("%d",&req);
				printf("\n total memmory in system : %d \n",totsize);
				printf("\n memory block allocated so far is : %d \n",totalalloc);
				if (req<16)
					{
						printf("\n Sorry ..minimum size of 16 bytes allowed");
						continue;
					}
				
				if (req <=(totsize-totalalloc))
				{
					totalalloc=totalalloc+segmentalloc(totsize,req);
					printf("\n total memory available is : %d \n",(totsize-totalalloc));
				}
				else
					printf("\n Not enough memory left in system\n");
				break;
			case 2:
				printf(" ");
				for(i=0;i<80;i++) printf("%c",5);
				printf(" ");
				printf("D E A L L O C A T I O N \n");
				for(i=0;i<80;i++) printf("%c",5);
				printf("	* requested  size  :  \n");
				scanf("%d",&req);
				makefree(req);
				break;
			case 3:
				
				printf(" ");
				for(i=0;i<80;i++) printf("%c",5);
				printf("CURRENT  M E M O R Y   A L L O C A T I O N   \n");
				for(i=0;i<80;i++) printf("%c",5);
				printf(" ");
				printing(totsize,0);
				printf(" ");
				for(i=0;i<80;i++) printf("%c",5);
				getchar();
				break;
			case 4:
				printf("LAZY MODE is now enabled..Memory COALESCING WILL BE DELAYED.\n");
				lazy=1;
				continue;
			case 5:
				printf(" Lazy mode is NOW DISABLED..Now free any block to reclaim all possible cases...\n");
				lazy=0;
				continue;  
			case 6: 
				printf("\n Thank you for using memory allocator simulation ..GoodBye ");
				exit(0);	
			default:
				printf("\n We expect input 1 to 6 only... ");
			 	continue;
		}
	}
	
}
Beispiel #13
0
void
deref(Site *v)
{
    v -> refcnt -= 1;
    if (v -> refcnt == 0 ) makefree(v, &sfl);
}
Beispiel #14
0
void    timerprocessor_c::clear()
{
    while(m_items.size()) makefree( m_items.get_last_remove() );
}