Exemple #1
0
/***********************************************************************
* create prx heap from memory container 1("app")
***********************************************************************/
int32_t create_heap(int32_t size)
{
	mc_app = vsh_memory_container_by_id(1);
	if (!mc_app) {destroy_heap(); return(-1);}

	heap_size = MB(size);

	sys_memory_allocate_from_container(heap_size, mc_app, SYS_MEMORY_PAGE_SIZE_1M, &heap_mem);
	if (!heap_mem) {destroy_heap(); return(-1);}

	prx_heap = (uint32_t)heap_mem;
	return(0);
}
Exemple #2
0
void heapsort(SequenceT* arr, size_t size, SortOrderT order) {
    if (arr == NULL || size <= 1) {
        return;
    }

    HeapT* h = create_heap_from(arr, size);
    assert(h != NULL);
    HeapImplT* heap = (HeapImplT*) h;
    void (*heapify)(HeapT*, size_t);

    if (order == DESC) {
        build_max_heap(h);
        heapify = max_heapify;
    } else {
        build_min_heap(h);
        heapify = min_heapify;
    }

    size_t index = size - 1;
    for (; index > 0; --index) {
        swap(&heap->data[index], &heap->data[0]);
        --heap->size;
        heapify(h, 0);
    }

    memcpy(arr, heap->data, size * sizeof(SequenceT));
    destroy_heap(h);
}
Exemple #3
0
void *pop_heap(heap *h) {
	if (h->size == 0) return NULL;
	void *ret = h->buffer[0];
	if (h->size == 1) destroy_heap(h);
	else { h->buffer[0] = h->buffer[--h->size]; percdown(h, 0); }
	return ret;
}
Exemple #4
0
 ~region_allocator() throw() {
   heap* h = m_head;
   while (h) {
     heap* const next = h->m_next;
     destroy_heap(h);
     h = next;
   }
 }
Exemple #5
0
void
destroy_priqueue(struct PriQueue *priqueue)
{
	if(priqueue) {
		if(priqueue->heap)
			destroy_heap(priqueue->heap);
	}
	free(priqueue);
}
Exemple #6
0
/**
 * free_s_point
 *
 * Destructor FUNCTION for s_points. Note that s_points were not
 * encapsulated as objects in the first place. Otherwise I would not
 * have to write this function and place it here. NOTE: This function
 * only frees the HEAP inside the spoint; it does not free the memory
 * allocated to the spoint struct itself. Nor does is free the
 * e_cons0 or the cons0 referenced by the S_POINT.
 *
 */
void free_s_point (
  S_POINT *sp        ///< The item being destroyed.
) {
  destroy_heap(sp->seed_heap);
  if (sp->cons0) info_cons0_alloc--;
  free(sp->e_cons0);
  free(sp->cons0);
  memset(sp, 0, sizeof(S_POINT));
} // free_s_point
Exemple #7
0
/***********************************************************************
* stop VSH Menu
***********************************************************************/
static void stop_VSH_Menu(void)
{
    // menu off
    menu_running = 0;

    // free heap memory
    destroy_heap();

    // continue rsx rendering
    rsx_fifo_pause(0);
}
Exemple #8
0
 inline void deallocate(void* const ptr) throw() {
   heap* const h = find_heap(ptr);
   if (h) {
     if (h->deallocate()) {
       if (m_depth > m_max_depth) {
         destroy_heap(h);
       }
     }
   } else {
     std::free(ptr);
   }
 }
Exemple #9
0
void test_one_heap_entry() {
    printf("Testing one heap entry... ");

    create_heap();
    add_to_heap(7);
    int max = peek_heap();
    if (max != 7) {
        printf("ERROR: Expected 7, but got %d\n", max);
    }
    else {
        printf("Pass\n");
    }

    destroy_heap();
}
Exemple #10
0
void test_many_heap_entry() {
    printf("Testing many heap entry... ");

    create_heap();
    for (int i = 100; i > 0; i -= 1) {
        add_to_heap(i);
    }
    print_heap();
    int max = peek_heap();
    if (max != 100) {
        printf("ERROR: Expected 100, but got %d\n", max);
    }
    else {
        printf("Pass\n");
    }

    destroy_heap();
}
Exemple #11
0
/////////////////////////MAIN PROCEDURE//////////////////////
int main(int argc, char * * argv)
{
    heap * p_H;

/* a new heap is empty */
    if (init_heap(&p_H, 256, cmp_int) == ERROR || !empty_heap(p_H))
        return EXIT_FAILURE;

/* a heap with one element is not empty */
    if (heap_insert_int(p_H, 2) == ERROR || empty_heap(p_H))
        return EXIT_FAILURE;

/* the minimum element is 1 */
    {
        int res;
        if (heap_insert_int(p_H, 1) == ERROR ||
            heap_insert_int(p_H, 5) == ERROR ||
            heap_delete_int(p_H, 0, &res) == ERROR ||
            res != 1)
        {
            return EXIT_FAILURE;
        }//if
    }//scope

/* there is no element at index 2 */
    {
        int res;
        if (heap_delete_int(p_H, 2, &res) == OK)
            return EXIT_FAILURE;
    }//scope
    
/* The element on the second level is 5 */
    {
        int res;
        if (heap_delete_int(p_H, 1, &res) == ERROR || res != 5)
            return EXIT_FAILURE;
    }//scope

/* the remaining element is 2 */
    {
        int res;
        if (heap_delete_int(p_H, 0, &res) == ERROR || res != 2)
            return EXIT_FAILURE;
    }//scope

/* removing an element from an empty heap yeilds an error */
    {
        int res;
        if (heap_delete_int(p_H, 0, &res) == OK)
            return EXIT_FAILURE;
    }//scope






    destroy_heap(&p_H, destroy_int);

/* after destruction, the heap is NULL?*/
    if (p_H != NULL)
        return EXIT_FAILURE;

    return EXIT_SUCCESS;
}
Exemple #12
0
/*
 * Function:		art_thread()
 * File:			main.c
 * Project:			ArtemisPS3-PRX
 * Description:		Artemis PRX Thread start
 *					Interprets user input and calls art_process()
 * Arguments:		
 *	arg:			
 * Return:			void
 */
static void art_thread(uint64_t arg)
{
	int GameProcessID = 0, lastGameProcessID = 0;

	printf("Artemis PS3 :::: Thread Started!\n");
	
	sys_timer_sleep(10);
	sys_ppu_thread_yield();
	
	CellPadData data;
	CellPadInfo2 info;
	int delay = 0, delay2 = 0, hasDisplayed = 0, fd = 0;

	while (1)
	{
		if (exitThread)
		{
			destroy_heap();
			exitThread = 0;
			{ sys_ppu_thread_exit(0); }
			{ return; }
		}

		GameProcessID = GetGameProcessID();
		if (GameProcessID != 0)
		{
			if (!check_turnoff()) //exit
			{
				printf("Artemis PS3 :::: Process Exited\n");
				destroy_heap();
				attachedPID = 0;
			}
			else
			{
				if (GameProcessID != lastGameProcessID)
				{
					for (int x = 0; x < (10 * 100); x++) //10 second delay
					{
						sys_timer_usleep(10000);
						sys_ppu_thread_yield();
					}


					show_msg((char *)"Artemis PS3\nStart To Attach");
				}

				cellPadGetInfo2(&info);
				if (info.port_status[0] && (cellPadGetData(0, &data) | 1) && data.len > 0)
				{
					uint32_t pad = data.button[2] | (data.button[3] << 8);
					if (attachedPID) // Run codes
					{
						art_process(0);
					}

					if (pad & PAD_START)
					{
						attachedPID = GameProcessID;
						if (attachedPID)
						{
							show_msg((char *)"Artemis PS3\nAttached and Wrote");
							printf("Artemis PS3 :::: Attached to 0x%08X\n", attachedPID);

							if (get_heap() == 0)
								create_heap(1);
							check_syscall_api();
							art_process(1);

							while ((cellPadGetData(0, &data) | 1) && data.len > 0)
							{
								if (!((data.button[2] | (data.button[3] << 8)) & PAD_START))
									break;

								sys_timer_usleep(1000000);
								sys_ppu_thread_yield();
							}
						}
						else
						{
							show_msg((char *)"Artemis PS3\nFailed to Attach");
						}
					}
					else if (pad & PAD_SELECT && attachedPID)
					{
						show_msg((char *)"Artemis PS3\nDetached");
						reset_heap();
						attachedPID = 0;
					}

				}

				sys_timer_usleep(100 * 1000); //0.1 second delay
			}
		}
		else
		{
			if (attachedPID) // Disconnect
			{
				printf("Artemis PS3 :::: Process Exited\n");
				destroy_heap();
				attachedPID = 0;
			}
			else
				sys_timer_usleep(3 * 1000 * 1000); //3 second delay
		}

		lastGameProcessID = GameProcessID;
		sys_timer_usleep(1668);
		sys_ppu_thread_yield();
	}

	destroy_heap();
	sys_ppu_thread_exit(0);

}