// tracking all names already seen thus avoiding the overhead of repeating
// malloc() and free() calls.
static char *lxc_containers (const char *path) {
- static struct utlbuf_s ub = { NULL, 0 }; // util buffer for whole cgroup
+ static __thread struct utlbuf_s ub = { NULL, 0 }; // util buffer for whole cgroup
static char lxc_none[] = "-";
static char lxc_oops[] = "?"; // used when memory alloc fails
/*
if ((p1 = strstr(ub.buf, (delim = lxc_delm1)))
|| ((p1 = strstr(ub.buf, (delim = lxc_delm2)))
|| ((p1 = strstr(ub.buf, (delim = lxc_delm3)))))) {
- static struct lxc_ele {
+ static __thread struct lxc_ele {
struct lxc_ele *next;
char *name;
} *anchor = NULL;
// The pid (tgid? tid?) is already in p, and a path to it in path, with some
// room to spare.
static proc_t *simple_readproc(PROCTAB *restrict const PT, proc_t *restrict const p) {
- static struct utlbuf_s ub = { NULL, 0 }; // buf for stat,statm,status
- static struct stat sb; // stat() buffer
+ static __thread struct utlbuf_s ub = { NULL, 0 }; // buf for stat,statm,status
+ static __thread struct stat sb; // stat() buffer
char *restrict const path = PT->path;
unsigned flags = PT->flags;
int rc = 0;
// t is the POSIX thread (task group member, generally not the leader)
// path is a path to the task, with some room to spare.
static proc_t *simple_readtask(PROCTAB *restrict const PT, proc_t *restrict const t, char *restrict const path) {
- static struct utlbuf_s ub = { NULL, 0 }; // buf for stat,statm,status
- static struct stat sb; // stat() buffer
+ static __thread struct utlbuf_s ub = { NULL, 0 }; // buf for stat,statm,status
+ static __thread struct stat sb; // stat() buffer
unsigned flags = PT->flags;
int rc = 0;
// This finds processes in /proc in the traditional way.
// Return non-zero on success.
static int simple_nextpid(PROCTAB *restrict const PT, proc_t *restrict const p) {
- static struct dirent *ent; /* dirent handle */
+ static __thread struct dirent *ent; /* dirent handle */
char *restrict const path = PT->path;
for (;;) {
ent = readdir(PT->procfs);
// This finds tasks in /proc/*/task/ in the traditional way.
// Return non-zero on success.
static int simple_nexttid(PROCTAB *restrict const PT, const proc_t *restrict const p, proc_t *restrict const t, char *restrict const path) {
- static struct dirent *ent; /* dirent handle */
+ static __thread struct dirent *ent; /* dirent handle */
if(PT->taskdir_user != p->tgid){
if(PT->taskdir){
closedir(PT->taskdir);
// This "finds" processes in a list that was given to openproc().
// Return non-zero on success. (tgid is a real headache)
static int listed_nextpid (PROCTAB *PT, proc_t *p) {
- static struct utlbuf_s ub = { NULL, 0 };
+ static __thread struct utlbuf_s ub = { NULL, 0 };
pid_t pid = *(PT->pids)++;
char *path = PT->path;
// the next unique process or task available. If no more are available,
// return a null pointer (boolean false).
proc_t *readeither (PROCTAB *restrict const PT, proc_t *restrict x) {
- static proc_t skel_p; // skeleton proc_t, only uses tid + tgid
- static proc_t *new_p; // for process/task transitions
- static int canary, leader;
+ static __thread proc_t skel_p; // skeleton proc_t, only uses tid + tgid
+ static __thread proc_t *new_p; // for process/task transitions
+ static __thread int canary, leader;
char path[PROCPATHLEN];
proc_t *ret;
PROCTAB *openproc(unsigned flags, ...) {
va_list ap;
struct stat sbuf;
- static int did_stat;
+ static __thread int did_stat;
PROCTAB *PT = calloc(1, sizeof(PROCTAB));
if (!PT)
// and would need 1258 if the obsolete fields were there.
// As of 3.13 /proc/vmstat needs 2623,
// and /proc/stat needs 3076.
-static char buf[8192];
+static __thread char buf[8192];
/* This macro opens filename only if necessary and seeks to 0 so
* that successive calls to the functions are more efficient.
* It also reads the current contents of the file into the global buf.
*/
#define FILE_TO_BUF(filename, fd) do{ \
- static int local_n; \
+ static __thread int local_n; \
if (fd == -1 && (fd = open(filename, O_RDONLY)) == -1) { \
fputs(BAD_OPEN_MESSAGE, stderr); \
fflush(NULL); \
{
FILE *fp;
char pidbuf[24];
- static int pid_length=0;
+ static __thread int pid_length=0;
if (pid_length)
return pid_length;