More pthreads cleanup.
POSIX says pthread_create returns EAGAIN, not ENOMEM. Also pull pthread_attr_t functions into their own file. Also pull pthread_setname_np into its own file. Also remove unnecessary #includes from pthread_key.cpp. Also account for those pthread keys used internally by bionic, so they don't count against the number of keys available to user code. (They do with glibc, but glibc's limit is the much more generous 1024.) Also factor out the common errno-restoring idiom to reduce gotos. Bug: 6702535 Change-Id: I555e66efffcf2c1b5a2873569e91489156efca42
This commit is contained in:
@@ -28,12 +28,14 @@ TEST(pthread, pthread_key_create) {
|
||||
ASSERT_EQ(EINVAL, pthread_key_delete(key));
|
||||
}
|
||||
|
||||
#if !defined(__GLIBC__) // glibc uses keys internally that its sysconf value doesn't account for.
|
||||
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));
|
||||
// If this fails, it's likely that GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT is wrong.
|
||||
ASSERT_EQ(0, pthread_key_create(&key, NULL)) << i << " of " << sysconf(_SC_THREAD_KEYS_MAX);
|
||||
keys.push_back(key);
|
||||
}
|
||||
|
||||
@@ -46,6 +48,7 @@ TEST(pthread, pthread_key_create_lots) {
|
||||
ASSERT_EQ(0, pthread_key_delete(keys[i]));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void* IdFn(void* arg) {
|
||||
return arg;
|
||||
@@ -87,6 +90,15 @@ TEST(pthread, pthread_create) {
|
||||
ASSERT_EQ(expected_result, result);
|
||||
}
|
||||
|
||||
TEST(pthread, pthread_create_EAGAIN) {
|
||||
pthread_attr_t attributes;
|
||||
ASSERT_EQ(0, pthread_attr_init(&attributes));
|
||||
ASSERT_EQ(0, pthread_attr_setstacksize(&attributes, static_cast<size_t>(-1) & ~(getpagesize() - 1)));
|
||||
|
||||
pthread_t t;
|
||||
ASSERT_EQ(EAGAIN, pthread_create(&t, &attributes, IdFn, NULL));
|
||||
}
|
||||
|
||||
TEST(pthread, pthread_no_join_after_detach) {
|
||||
pthread_t t1;
|
||||
ASSERT_EQ(0, pthread_create(&t1, NULL, SleepFn, reinterpret_cast<void*>(5)));
|
||||
|
Reference in New Issue
Block a user