Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 339021
b: refs/heads/master
c: 61e9451
h: refs/heads/master
i:
  339019: 4aab9c5
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo committed Nov 14, 2012
1 parent 7eafeed commit 11cd538
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f95e0818cbd026a8f2277895c65fcc9cc5b28cf6
refs/heads/master: 61e945150fe0ec4c20b7a3663b90c7ab705a88b4
46 changes: 23 additions & 23 deletions trunk/tools/perf/util/pstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,59 @@ struct pstack {

struct pstack *pstack__new(unsigned short max_nr_entries)
{
struct pstack *self = zalloc((sizeof(*self) +
max_nr_entries * sizeof(void *)));
if (self != NULL)
self->max_nr_entries = max_nr_entries;
return self;
struct pstack *pstack = zalloc((sizeof(*pstack) +
max_nr_entries * sizeof(void *)));
if (pstack != NULL)
pstack->max_nr_entries = max_nr_entries;
return pstack;
}

void pstack__delete(struct pstack *self)
void pstack__delete(struct pstack *pstack)
{
free(self);
free(pstack);
}

bool pstack__empty(const struct pstack *self)
bool pstack__empty(const struct pstack *pstack)
{
return self->top == 0;
return pstack->top == 0;
}

void pstack__remove(struct pstack *self, void *key)
void pstack__remove(struct pstack *pstack, void *key)
{
unsigned short i = self->top, last_index = self->top - 1;
unsigned short i = pstack->top, last_index = pstack->top - 1;

while (i-- != 0) {
if (self->entries[i] == key) {
if (pstack->entries[i] == key) {
if (i < last_index)
memmove(self->entries + i,
self->entries + i + 1,
memmove(pstack->entries + i,
pstack->entries + i + 1,
(last_index - i) * sizeof(void *));
--self->top;
--pstack->top;
return;
}
}
pr_err("%s: %p not on the pstack!\n", __func__, key);
}

void pstack__push(struct pstack *self, void *key)
void pstack__push(struct pstack *pstack, void *key)
{
if (self->top == self->max_nr_entries) {
pr_err("%s: top=%d, overflow!\n", __func__, self->top);
if (pstack->top == pstack->max_nr_entries) {
pr_err("%s: top=%d, overflow!\n", __func__, pstack->top);
return;
}
self->entries[self->top++] = key;
pstack->entries[pstack->top++] = key;
}

void *pstack__pop(struct pstack *self)
void *pstack__pop(struct pstack *pstack)
{
void *ret;

if (self->top == 0) {
if (pstack->top == 0) {
pr_err("%s: underflow!\n", __func__);
return NULL;
}

ret = self->entries[--self->top];
self->entries[self->top] = NULL;
ret = pstack->entries[--pstack->top];
pstack->entries[pstack->top] = NULL;
return ret;
}

0 comments on commit 11cd538

Please sign in to comment.