URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Only display areas with differences |
Details |
Blame |
View Log
Rev 275 |
Rev 384 |
/* zz30
|
/* zz30
|
*
|
*
|
* demonstrate a splay-tree depth problem
|
* demonstrate a splay-tree depth problem
|
*/
|
*/
|
|
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <unistd.h>
|
#include <unistd.h>
|
|
|
#ifndef SCALE
|
#ifndef SCALE
|
#define SCALE 100000
|
#define SCALE 100000
|
#endif
|
#endif
|
|
|
|
|
struct list
|
struct list
|
{
|
{
|
struct list *next;
|
struct list *next;
|
};
|
};
|
|
|
|
|
int
|
int
|
main ()
|
main ()
|
{
|
{
|
struct list *head = NULL;
|
struct list *head = NULL;
|
struct list *tail = NULL;
|
struct list *tail = NULL;
|
struct list *p;
|
struct list *p;
|
long n;
|
long n;
|
int direction;
|
int direction;
|
|
|
for (direction = 0; direction < 2; direction++)
|
for (direction = 0; direction < 2; direction++)
|
{
|
{
|
fprintf (stdout, "allocating\n");
|
fprintf (stdout, "allocating\n");
|
fflush (stdout);
|
fflush (stdout);
|
|
|
for (n = 0; n < SCALE; ++n)
|
for (n = 0; n < SCALE; ++n)
|
{
|
{
|
p = malloc (sizeof *p);
|
p = malloc (sizeof *p);
|
if (NULL == p)
|
if (NULL == p)
|
{
|
{
|
fprintf (stdout, "malloc failed\n");
|
fprintf (stdout, "malloc failed\n");
|
break;
|
break;
|
}
|
}
|
if (direction == 0)
|
if (direction == 0)
|
{ /* add at tail */
|
{ /* add at tail */
|
p->next = NULL;
|
p->next = NULL;
|
if (NULL != tail)
|
if (NULL != tail)
|
tail->next = p;
|
tail->next = p;
|
else
|
else
|
head = p;
|
head = p;
|
tail = p;
|
tail = p;
|
}
|
}
|
else
|
else
|
{ /* add at head */
|
{ /* add at head */
|
p->next = head;
|
p->next = head;
|
if (NULL == tail)
|
if (NULL == tail)
|
tail = p;
|
tail = p;
|
head = p;
|
head = p;
|
}
|
}
|
}
|
}
|
|
|
fprintf (stdout, "freeing\n");
|
fprintf (stdout, "freeing\n");
|
fflush (stdout);
|
fflush (stdout);
|
|
|
while (NULL != head)
|
while (NULL != head)
|
{
|
{
|
p = head;
|
p = head;
|
head = head->next;
|
head = head->next;
|
free (p);
|
free (p);
|
}
|
}
|
|
|
}
|
}
|
|
|
fprintf (stdout, "done\n");
|
fprintf (stdout, "done\n");
|
fflush (stdout);
|
fflush (stdout);
|
|
|
return (0);
|
return (0);
|
}
|
}
|
|
|
/* { dg-output "allocating.*freeing.*allocating.*freeing.*done" } */
|
/* { dg-output "allocating.*freeing.*allocating.*freeing.*done" } */
|
|
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.