-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 338862 b: refs/heads/master c: 9d2f8e2 h: refs/heads/master v: v3
- Loading branch information
Arnaldo Carvalho de Melo
committed
Oct 6, 2012
1 parent
4cfca59
commit 1c2bc09
Showing
6 changed files
with
74 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: 0c1fe6b2f30fa275d939071293b6e28771283f6d | ||
refs/heads/master: 9d2f8e22fc965bcdd5561d000d234fe2d23657ba |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "machine.h" | ||
#include "map.h" | ||
#include "thread.h" | ||
#include <stdbool.h> | ||
|
||
static struct thread *__machine__findnew_thread(struct machine *machine, pid_t pid, | ||
bool create) | ||
{ | ||
struct rb_node **p = &machine->threads.rb_node; | ||
struct rb_node *parent = NULL; | ||
struct thread *th; | ||
|
||
/* | ||
* Font-end cache - PID lookups come in blocks, | ||
* so most of the time we dont have to look up | ||
* the full rbtree: | ||
*/ | ||
if (machine->last_match && machine->last_match->pid == pid) | ||
return machine->last_match; | ||
|
||
while (*p != NULL) { | ||
parent = *p; | ||
th = rb_entry(parent, struct thread, rb_node); | ||
|
||
if (th->pid == pid) { | ||
machine->last_match = th; | ||
return th; | ||
} | ||
|
||
if (pid < th->pid) | ||
p = &(*p)->rb_left; | ||
else | ||
p = &(*p)->rb_right; | ||
} | ||
|
||
if (!create) | ||
return NULL; | ||
|
||
th = thread__new(pid); | ||
if (th != NULL) { | ||
rb_link_node(&th->rb_node, parent, p); | ||
rb_insert_color(&th->rb_node, &machine->threads); | ||
machine->last_match = th; | ||
} | ||
|
||
return th; | ||
} | ||
|
||
struct thread *machine__findnew_thread(struct machine *machine, pid_t pid) | ||
{ | ||
return __machine__findnew_thread(machine, pid, true); | ||
} | ||
|
||
struct thread *machine__find_thread(struct machine *machine, pid_t pid) | ||
{ | ||
return __machine__findnew_thread(machine, pid, false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef __PERF_MACHINE_H | ||
#define __PERF_MACHINE_H | ||
|
||
#include <sys/types.h> | ||
|
||
struct thread; | ||
struct machine; | ||
|
||
struct thread *machine__find_thread(struct machine *machine, pid_t pid); | ||
|
||
#endif /* __PERF_MACHINE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters