am 2c02d005: Merge "Add __pure2 to a few more functions, most notably gettid and pthread_self."

* commit '2c02d0057c93bfa6db4b30d8646baeb55d076062':
  Add __pure2 to a few more functions, most notably gettid and pthread_self.
This commit is contained in:
Elliott Hughes 2014-06-11 23:39:47 +00:00 committed by Android Git Automerger
commit e02086a6dc
6 changed files with 14 additions and 8 deletions

View File

@ -18,11 +18,14 @@
#include <pthread.h> #include <pthread.h>
// Stop GCC optimizing out our pure function.
/* Must not be static! */ pthread_t (*pthread_self_fp)() = pthread_self;
static void BM_pthread_self(int iters) { static void BM_pthread_self(int iters) {
StartBenchmarkTiming(); StartBenchmarkTiming();
for (int i = 0; i < iters; ++i) { for (int i = 0; i < iters; ++i) {
pthread_self(); pthread_self_fp();
} }
StopBenchmarkTiming(); StopBenchmarkTiming();

View File

@ -30,11 +30,14 @@ static void BM_unistd_getpid(int iters) {
} }
BENCHMARK(BM_unistd_getpid); BENCHMARK(BM_unistd_getpid);
// Stop GCC optimizing out our pure function.
/* Must not be static! */ pid_t (*gettid_fp)() = gettid;
static void BM_unistd_gettid(int iters) { static void BM_unistd_gettid(int iters) {
StartBenchmarkTiming(); StartBenchmarkTiming();
for (int i = 0; i < iters; ++i) { for (int i = 0; i < iters; ++i) {
gettid(); gettid_fp();
} }
StopBenchmarkTiming(); StopBenchmarkTiming();

View File

@ -41,7 +41,7 @@ __BEGIN_DECLS
#endif #endif
/* internal function returning the address of the thread-specific errno */ /* internal function returning the address of the thread-specific errno */
extern volatile int* __errno(void); extern volatile int* __errno(void) __pure2;
/* a macro expanding to the errno l-value */ /* a macro expanding to the errno l-value */
#define errno (*__errno()) #define errno (*__errno())

View File

@ -226,7 +226,7 @@ int pthread_rwlock_trywrlock(pthread_rwlock_t*) __nonnull((1));
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) __nonnull((1)); int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) __nonnull((1));
int pthread_rwlock_wrlock(pthread_rwlock_t*) __nonnull((1)); int pthread_rwlock_wrlock(pthread_rwlock_t*) __nonnull((1));
pthread_t pthread_self(void); pthread_t pthread_self(void) __pure2;
int pthread_setname_np(pthread_t, const char*) __nonnull((2)); int pthread_setname_np(pthread_t, const char*) __nonnull((2));

View File

@ -138,21 +138,21 @@ typedef struct {
int rem; int rem;
} div_t; } div_t;
extern div_t div(int, int); extern div_t div(int, int) __pure2;
typedef struct { typedef struct {
long int quot; long int quot;
long int rem; long int rem;
} ldiv_t; } ldiv_t;
extern ldiv_t ldiv(long, long); extern ldiv_t ldiv(long, long) __pure2;
typedef struct { typedef struct {
long long int quot; long long int quot;
long long int rem; long long int rem;
} lldiv_t; } lldiv_t;
extern lldiv_t lldiv(long long, long long); extern lldiv_t lldiv(long long, long long) __pure2;
/* BSD compatibility. */ /* BSD compatibility. */
extern const char* getprogname(void); extern const char* getprogname(void);

View File

@ -54,7 +54,7 @@ extern __noreturn void _exit(int);
extern pid_t fork(void); extern pid_t fork(void);
extern pid_t vfork(void); extern pid_t vfork(void);
extern pid_t getpid(void); extern pid_t getpid(void);
extern pid_t gettid(void); extern pid_t gettid(void) __pure2;
extern pid_t getpgid(pid_t); extern pid_t getpgid(pid_t);
extern int setpgid(pid_t, pid_t); extern int setpgid(pid_t, pid_t);
extern pid_t getppid(void); extern pid_t getppid(void);