Pull the pthread_key_t functions out of pthread.c.

This was originally motivated by noticing that we were setting the
wrong bits for the well-known tls entries. That was a harmless bug
because none of the well-known tls entries has a destructor, but
it's best not to leave land mines lying around.

Also add some missing POSIX constants, a new test, and fix
pthread_key_create's return value when we hit the limit.

Change-Id: Ife26ea2f4b40865308e8410ec803b20bcc3e0ed1
This commit is contained in:
Elliott Hughes
2013-02-08 15:46:37 -08:00
parent 9a9bb243b5
commit ad59322ae4
9 changed files with 370 additions and 367 deletions

View File

@@ -28,6 +28,25 @@ TEST(pthread, pthread_key_create) {
ASSERT_EQ(EINVAL, pthread_key_delete(key));
}
TEST(pthread, pthread_key_create_lots) {
// We can allocate _SC_THREAD_KEYS_MAX keys.
std::vector<pthread_key_t> keys;
for (int i = 0; i < sysconf(_SC_THREAD_KEYS_MAX); ++i) {
pthread_key_t key;
ASSERT_EQ(0, pthread_key_create(&key, NULL));
keys.push_back(key);
}
// ...and that really is the maximum.
pthread_key_t key;
ASSERT_EQ(EAGAIN, pthread_key_create(&key, NULL));
// (Don't leak all those keys!)
for (size_t i = 0; i < keys.size(); ++i) {
ASSERT_EQ(0, pthread_key_delete(keys[i]));
}
}
static void* IdFn(void* arg) {
return arg;
}