示例#1
0
int sem_wait(sem_t* sem) {
  atomic_uint* sem_count_ptr = SEM_TO_ATOMIC_POINTER(sem);
  unsigned int shared = SEM_GET_SHARED(sem_count_ptr);

  while (true) {
    if (__sem_dec(sem_count_ptr) > 0) {
      return 0;
    }

    int result = __futex_wait_ex(sem_count_ptr, shared, shared | SEMCOUNT_MINUS_ONE, false, nullptr);
    if (bionic_get_application_target_sdk_version() >= __ANDROID_API_N__) {
      if (result ==-EINTR) {
        errno = EINTR;
        return -1;
      }
    }
  }
}
const prop_info* __system_property_find_nth(unsigned n) {
#if !MB_OMIT_API_VERSION_CHECK
  if (bionic_get_application_target_sdk_version() >= __ANDROID_API_O__) {
    __libc_fatal(
        "__system_property_find_nth is not supported since Android O,"
        " please use __system_property_foreach instead.");
  }
#endif

  find_nth_cookie cookie(n);

  const int err = mb__system_property_foreach(find_nth_fn, &cookie);
  if (err < 0) {
    return nullptr;
  }

  return cookie.pi;
}