Merge pull request #3484 from AchrafReyani/feat/libkernel-pthread-mutexattr-gettype

feat(libkernel): implement pthread_mutexattr_gettype
This commit is contained in:
Adrià 2026-10-11 13:53:23 +02:00 committed by GitHub
commit fd1a66cab6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 0 deletions

View File

@ -118,4 +118,11 @@ int APS5_VABI pthread_mutexattr_settype_nid_postfix(PthreadMutexattr* attr, int
return PosixThread::ToErrno(scePthreadMutexattrSettype(attr, type));
}
int APS5_VABI pthread_mutexattr_gettype_nid_postfix(const PthreadMutexattr* attr, int* type) {
if (!attr || !*attr) return POSIX_EINVAL;
if (!type) throw std::runtime_error("pthread_mutexattr_gettype: null type");
*type = static_cast<int>((*attr)->type);
return 0;
}
}

View File

@ -8,6 +8,8 @@ int APS5_VABI pthread_mutexattr_destroy_nid_postfix(PthreadMutexattr* attr);
int APS5_VABI pthread_mutexattr_setprotocol_nid_postfix(PthreadMutexattr* attr, int protocol);
int APS5_VABI pthread_mutexattr_setprioceiling_nid_postfix(PthreadMutexattr* attr, int prioceiling);
int APS5_VABI pthread_mutexattr_getprioceiling_nid_postfix(const PthreadMutexattr* attr, int* prioceiling);
int APS5_VABI pthread_mutexattr_settype_nid_postfix(PthreadMutexattr* attr, int type);
int APS5_VABI pthread_mutexattr_gettype_nid_postfix(const PthreadMutexattr* attr, int* type);
int APS5_VABI pthread_mutex_init_nid_postfix(PthreadMutex* mutex, const PthreadMutexattr* attr);
int APS5_VABI pthread_mutex_lock_nid_postfix(PthreadMutex* mutex);
int APS5_VABI pthread_mutex_unlock_nid_postfix(PthreadMutex* mutex);
@ -33,7 +35,26 @@ static bool Throws(Call call) {
return false;
}
static void CheckType() {
PthreadMutexattr attr = nullptr;
Require(pthread_mutexattr_init_nid_postfix(&attr) == 0);
int type = -1;
Require(pthread_mutexattr_gettype_nid_postfix(&attr, &type) == 0 && type == 1);
for (const int set : {2, 3, 4, 1}) {
Require(pthread_mutexattr_settype_nid_postfix(&attr, set) == 0);
Require(pthread_mutexattr_gettype_nid_postfix(&attr, &type) == 0 && type == set);
}
Require(pthread_mutexattr_settype_nid_postfix(&attr, 5) == GUEST_EINVAL);
Require(pthread_mutexattr_gettype_nid_postfix(&attr, &type) == 0 && type == 1);
Require(Throws([&] { pthread_mutexattr_gettype_nid_postfix(&attr, nullptr); }));
Require(pthread_mutexattr_destroy_nid_postfix(&attr) == 0);
type = -1;
Require(pthread_mutexattr_gettype_nid_postfix(&attr, &type) == GUEST_EINVAL && type == -1);
Require(pthread_mutexattr_gettype_nid_postfix(nullptr, &type) == GUEST_EINVAL && type == -1);
}
int main() {
CheckType();
PthreadMutexattr attr = nullptr;
Require(pthread_mutexattr_init_nid_postfix(&attr) == 0);
int ceiling = -1;