Shared Persistent Heap Data Environment Manual  1.1.0
Macros | Functions | Variables
sphthread.h File Reference

Thread utility functions. More...

#include <unistd.h>

Go to the source code of this file.

Functions

__C__ pid_t sphdeGetPID (void)
 Return the process identification. More...
 
__C__ pid_t sphdeGetTID (void)
 Return the thread identification. More...
 
__C__ char * sphdeGetCmdLine (void)
 Return the command line string. More...
 
static int sphFastGetPID (void)
 Return the process identification. More...
 
__thread pid_t threadID __attribute__ ((tls_model("initial-exec")))
 
static int sphFastGetTID (void)
 Return the thread identification. More...
 

Variables

pid_t procID
 

Detailed Description

Thread utility functions.

The process pid can be obtained using sphdeGetPID, thread id by sphdeGetTID, and command line string by sphdeGetCmdLine. Fast versions that access static variables and avoid syscall where possible are provided: sphFastGetPID for process id and sphFastGetTID for thread id.

For instance, to provide a fast event log header:

struct eventHeader
{
unsigned int eventID;
unsigned short pid;
unsigned short tid;
unsigned sphtimer_t timestamp;
} evh;
evh.eventID = 0;
evh.pid = sphFastGetPID ();
evh.tid = sphFastGetTID ();
evh.timestamp = sphgettimer ();

Function Documentation

__thread pid_t threadID __attribute__ ( (tls_model("initial-exec"))  )

Per-thread thread identification variable. Should not be accessed directly, instead the function sphFastGetTID should be used.

__C__ char* sphdeGetCmdLine ( void  )

Return the command line string.

The command line is obtained from '/proc/pid/cmdline' and maintained in an internal static variable.

Returns
A null-terminated string with the process command line.
__C__ pid_t sphdeGetPID ( void  )

Return the process identification.

The function issues a syscall when needed and it also update its internal command line value (so a subsequent call to sphdeGetCmdLine will just return the already available command line value).

Returns
The process id or 0 if an error occurs.
__C__ pid_t sphdeGetTID ( void  )

Return the thread identification.

The function issues a syscall when needed. The thread identification value is a per-thread variable so a subsequent call to sphFastGetTID will just need to return a variable value (no syscall needed).

Returns
The thread identification or -1 if an error occurs.
static int sphFastGetPID ( void  )
inlinestatic

Return the process identification.

Fast version of sphdeGetPID.

Returns
The process id or 0 if an error occurs.
static int sphFastGetTID ( void  )
inlinestatic

Return the thread identification.

Fast version of sphdeGetTID.

Returns
The thread identification or -1 if an error occurs.

Variable Documentation

pid_t procID

Process identification variable. Should not be accessed directly, instead the function sphFastGetPID should be used.