From 71a15024894b876bc75dd34485535379d3ca434f Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 24 Apr 2012 20:47:36 +0200 Subject: [PATCH] add support of pid caching --- newlib/src/libgloss/metalsvm/config.h | 3 +++ newlib/src/libgloss/metalsvm/fork.c | 4 +++- newlib/src/libgloss/metalsvm/getpid.c | 17 ++++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/newlib/src/libgloss/metalsvm/config.h b/newlib/src/libgloss/metalsvm/config.h index 21f199e5..32a0f6fe 100644 --- a/newlib/src/libgloss/metalsvm/config.h +++ b/newlib/src/libgloss/metalsvm/config.h @@ -22,5 +22,8 @@ /* support for section attributes */ #define HAVE_SECTION_ATTRIBUTES 1 +/* definition of an invalid pid */ +#define INVALID_PID 0 + /* symbol prefix */ #define __SYMBOL_PREFIX "" diff --git a/newlib/src/libgloss/metalsvm/fork.c b/newlib/src/libgloss/metalsvm/fork.c index d4fcacde..b27c3b4a 100644 --- a/newlib/src/libgloss/metalsvm/fork.c +++ b/newlib/src/libgloss/metalsvm/fork.c @@ -40,6 +40,8 @@ #include "warning.h" #include "syscall.h" +extern int __private_pid; + int _DEFUN (_fork, (), _NOARGS) @@ -51,7 +53,7 @@ _DEFUN (_fork, (), if (ret < 0) { errno = -ret; ret = -1; - } + } else __private_pid = INVALID_PID; return ret; } diff --git a/newlib/src/libgloss/metalsvm/getpid.c b/newlib/src/libgloss/metalsvm/getpid.c index 9c2f2f26..c822722f 100644 --- a/newlib/src/libgloss/metalsvm/getpid.c +++ b/newlib/src/libgloss/metalsvm/getpid.c @@ -40,17 +40,20 @@ #include "warning.h" #include "syscall.h" +int __private_pid = INVALID_PID; + int _DEFUN (_getpid, (), _NOARGS) { - int ret; - - ret = SYSCALL0(__NR_getpid); - if (ret < 0) { - errno = -ret; - ret = -1; + if (__private_pid == INVALID_PID) { + __private_pid = SYSCALL0(__NR_getpid); + if (__private_pid < 0) { + errno = -__private_pid; + __private_pid = INVALID_PID; + return -1; + } } - return ret; + return __private_pid; }