| OLD | NEW |
| 1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2005, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include <assert.h> | 40 #include <assert.h> |
| 41 #include <string.h> // for memcmp | 41 #include <string.h> // for memcmp |
| 42 #include <stdio.h> // for __isthreaded on FreeBSD | 42 #include <stdio.h> // for __isthreaded on FreeBSD |
| 43 // We don't actually need strings. But including this header seems to | 43 // We don't actually need strings. But including this header seems to |
| 44 // stop the compiler trying to short-circuit our pthreads existence | 44 // stop the compiler trying to short-circuit our pthreads existence |
| 45 // tests and claiming that the address of a function is always | 45 // tests and claiming that the address of a function is always |
| 46 // non-zero. I have no idea why ... | 46 // non-zero. I have no idea why ... |
| 47 #include <string> | 47 #include <string> |
| 48 #include "maybe_threads.h" | 48 #include "maybe_threads.h" |
| 49 #include "base/basictypes.h" | 49 #include "base/basictypes.h" |
| 50 #include "base/logging.h" |
| 50 | 51 |
| 51 // __THROW is defined in glibc systems. It means, counter-intuitively, | 52 // __THROW is defined in glibc systems. It means, counter-intuitively, |
| 52 // "This function will never throw an exception." It's an optional | 53 // "This function will never throw an exception." It's an optional |
| 53 // optimization tool, but we may need to use it to match glibc prototypes. | 54 // optimization tool, but we may need to use it to match glibc prototypes. |
| 54 #ifndef __THROW // I guess we're not on a glibc system | 55 #ifndef __THROW // I guess we're not on a glibc system |
| 55 # define __THROW // __THROW is just an optimization, so ok to make it "" | 56 # define __THROW // __THROW is just an optimization, so ok to make it "" |
| 56 #endif | 57 #endif |
| 57 | 58 |
| 58 // These are the methods we're going to conditionally include. | 59 // These are the methods we're going to conditionally include. |
| 59 extern "C" { | 60 extern "C" { |
| 60 int pthread_key_create (pthread_key_t*, void (*)(void*)) | 61 int pthread_key_create (pthread_key_t*, void (*)(void*)) |
| 61 __THROW ATTRIBUTE_WEAK; | 62 __THROW ATTRIBUTE_WEAK; |
| 62 void *pthread_getspecific(pthread_key_t) | 63 void *pthread_getspecific(pthread_key_t) |
| 63 __THROW ATTRIBUTE_WEAK; | 64 __THROW ATTRIBUTE_WEAK; |
| 64 int pthread_setspecific(pthread_key_t, const void*) | 65 int pthread_setspecific(pthread_key_t, const void*) |
| 65 __THROW ATTRIBUTE_WEAK; | 66 __THROW ATTRIBUTE_WEAK; |
| 66 int pthread_once(pthread_once_t *, void (*)(void)) | 67 int pthread_once(pthread_once_t *, void (*)(void)) |
| 67 ATTRIBUTE_WEAK; | 68 ATTRIBUTE_WEAK; |
| 69 int pthread_atfork(void (*__prepare) (void), |
| 70 void (*__parent) (void), |
| 71 void (*__child) (void)) |
| 72 __THROW ATTRIBUTE_WEAK; |
| 68 } | 73 } |
| 69 | 74 |
| 70 #define MAX_PERTHREAD_VALS 16 | 75 #define MAX_PERTHREAD_VALS 16 |
| 71 static void *perftools_pthread_specific_vals[MAX_PERTHREAD_VALS]; | 76 static void *perftools_pthread_specific_vals[MAX_PERTHREAD_VALS]; |
| 72 static int next_key; | 77 static int next_key; |
| 73 | 78 |
| 74 int perftools_pthread_key_create(pthread_key_t *key, | 79 int perftools_pthread_key_create(pthread_key_t *key, |
| 75 void (*destr_function) (void *)) { | 80 void (*destr_function) (void *)) { |
| 76 if (pthread_key_create) { | 81 if (pthread_key_create) { |
| 77 return pthread_key_create(key, destr_function); | 82 return pthread_key_create(key, destr_function); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return pthread_once(ctl, init_routine); | 133 return pthread_once(ctl, init_routine); |
| 129 } else { | 134 } else { |
| 130 if (memcmp(ctl, &pthread_once_init, sizeof(*ctl)) == 0) { | 135 if (memcmp(ctl, &pthread_once_init, sizeof(*ctl)) == 0) { |
| 131 init_routine(); | 136 init_routine(); |
| 132 ++*(char*)(ctl); // make it so it's no longer equal to init | 137 ++*(char*)(ctl); // make it so it's no longer equal to init |
| 133 } | 138 } |
| 134 return 0; | 139 return 0; |
| 135 } | 140 } |
| 136 #endif | 141 #endif |
| 137 } | 142 } |
| 143 |
| 144 void perftools_pthread_atfork(void (*before)(), |
| 145 void (*parent_after)(), |
| 146 void (*child_after)()) { |
| 147 if (pthread_atfork) { |
| 148 int rv = pthread_atfork(before, parent_after, child_after); |
| 149 CHECK(rv == 0); |
| 150 } |
| 151 } |
| OLD | NEW |