diff --git a/libpthread/Makefile b/libpthread/Makefile
index 46c79323..fce68a45 100644
--- a/libpthread/Makefile
+++ b/libpthread/Makefile
@@ -14,7 +14,9 @@ OBJS=\
pthread_equal.o \
pthread_initialize.o \
pthread_mutexattr_destroy.o \
+pthread_mutexattr_gettype.o \
pthread_mutexattr_init.o \
+pthread_mutexattr_settype.o \
pthread_mutex_destroy.o \
pthread_mutex_init.o \
pthread_mutex_lock.o \
diff --git a/libpthread/include/__/pthread.h b/libpthread/include/__/pthread.h
index 8c96fa94..506515a2 100644
--- a/libpthread/include/__/pthread.h
+++ b/libpthread/include/__/pthread.h
@@ -66,10 +66,12 @@ typedef struct
#if defined(__is_sortix_libpthread)
typedef struct
{
+ int type;
} __pthread_mutexattr_t;
#else
typedef struct
{
+ int __pthread_type;
} __pthread_mutexattr_t;
#endif
diff --git a/libpthread/include/pthread.h b/libpthread/include/pthread.h
index d2e8fac8..f11d8956 100644
--- a/libpthread/include/pthread.h
+++ b/libpthread/include/pthread.h
@@ -218,13 +218,13 @@ int pthread_mutexattr_destroy(pthread_mutexattr_t*);
/* TODO: pthread_mutexattr_getprotocol */
/* TODO: pthread_mutexattr_getpshared */
/* TODO: pthread_mutexattr_getrobust */
-/* TODO: pthread_mutexattr_gettype */
+int pthread_mutexattr_gettype(pthread_mutexattr_t* __restrict, int* __restrict);
int pthread_mutexattr_init(pthread_mutexattr_t*);
/* TODO: pthread_mutexattr_setprioceiling */
/* TODO: pthread_mutexattr_setprotocol */
/* TODO: pthread_mutexattr_setpshared */
/* TODO: pthread_mutexattr_setrobust */
-/* TODO: pthread_mutexattr_settype */
+int pthread_mutexattr_settype(pthread_mutexattr_t*, int);
/* TODO: pthread_once */
/* TODO: pthread_rwlock_destroy */
/* TODO: pthread_rwlock_init */
diff --git a/libpthread/pthread_mutex_init.c++ b/libpthread/pthread_mutex_init.c++
index a23f459f..60a69cc8 100644
--- a/libpthread/pthread_mutex_init.c++
+++ b/libpthread/pthread_mutex_init.c++
@@ -1,6 +1,6 @@
/*******************************************************************************
- Copyright(C) Jonas 'Sortie' Termansen 2013.
+ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
This file is part of Sortix libpthread.
@@ -26,8 +26,19 @@
extern "C"
int pthread_mutex_init(pthread_mutex_t* restrict mutex,
- const pthread_mutexattr_t* restrict /*attr*/)
+ const pthread_mutexattr_t* restrict attr)
{
- *mutex = PTHREAD_MUTEX_INITIALIZER;
+ pthread_mutexattr_t default_attr;
+ if ( !attr )
+ {
+ pthread_mutexattr_init(&default_attr);
+ attr = &default_attr;
+ }
+
+ mutex->lock = 0;
+ mutex->type = attr->type;
+ mutex->owner = 0;
+ mutex->recursion = 0;
+
return 0;
}
diff --git a/libpthread/pthread_mutexattr_gettype.c++ b/libpthread/pthread_mutexattr_gettype.c++
new file mode 100644
index 00000000..d14e8f98
--- /dev/null
+++ b/libpthread/pthread_mutexattr_gettype.c++
@@ -0,0 +1,32 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2014.
+
+ This file is part of Sortix libpthread.
+
+ Sortix libpthread is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ Sortix libpthread is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with Sortix libpthread. If not, see .
+
+ pthread_mutexattr_gettype.c++
+ Gets the requested mutex type in a mutex attribute object.
+
+*******************************************************************************/
+
+#include
+
+extern "C"
+int pthread_mutexattr_gettype(pthread_mutexattr_t* restrict attr,
+ int* restrict type)
+{
+ return *type = attr->type, 0;
+}
diff --git a/libpthread/pthread_mutexattr_init.c++ b/libpthread/pthread_mutexattr_init.c++
index 4debce55..dad9ecd2 100644
--- a/libpthread/pthread_mutexattr_init.c++
+++ b/libpthread/pthread_mutexattr_init.c++
@@ -28,5 +28,6 @@
extern "C" int pthread_mutexattr_init(pthread_mutexattr_t* attr)
{
memset(attr, 0, sizeof(*attr));
+ attr->type = PTHREAD_MUTEX_DEFAULT;
return 0;
}
diff --git a/libpthread/pthread_mutexattr_settype.c++ b/libpthread/pthread_mutexattr_settype.c++
new file mode 100644
index 00000000..eeff1488
--- /dev/null
+++ b/libpthread/pthread_mutexattr_settype.c++
@@ -0,0 +1,30 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2014.
+
+ This file is part of Sortix libpthread.
+
+ Sortix libpthread is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ Sortix libpthread is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with Sortix libpthread. If not, see .
+
+ pthread_mutexattr_settype.c++
+ Sets the requested mutex type in a mutex attribute object.
+
+*******************************************************************************/
+
+#include
+
+extern "C" int pthread_mutexattr_settype(pthread_mutexattr_t* attr, int type)
+{
+ return attr->type = type, 0;
+}