summaryrefslogtreecommitdiff
path: root/mutex.c
diff options
context:
space:
mode:
authorbje <bje>1998-07-12 11:26:43 +0000
committerbje <bje>1998-07-12 11:26:43 +0000
commitf4a31d3296b11194d92b0983ba1dddb363436298 (patch)
treea51f15f3114a92234218fa8892cff504f6b9da92 /mutex.c
parenta0c8a187f3c4d5107ab1f3ad265128ad92725222 (diff)
* mutex.c (pthread_mutexattr_init): Implement.
(pthread_mutexattr_destroy): Implement. (pthread_mutexattr_setpshared): Likewise. (pthread_mutexattr_getpshared): Likewise. (insert_attr): New function; very preliminary implementation! (is_attr): Likewise. (remove_attr): Likewise.
Diffstat (limited to 'mutex.c')
-rw-r--r--mutex.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/mutex.c b/mutex.c
index b9739b9..33aafca 100644
--- a/mutex.c
+++ b/mutex.c
@@ -7,6 +7,104 @@
#include "pthread.h"
+static int
+insert_attr(pthread_mutexattr_t *attr)
+{
+ /* Add this attribute object to a list. */
+
+ /* FIXME: implement using some dynamic scheme. */
+ return 0;
+}
+
+static int
+is_attr(pthread_mutexattr_t *attr)
+{
+ /* Return 0 if present, 1 otherwise. */
+
+ /* FIXME: implement. For now, pretend the attribute is always okay, unless
+ it is NULL. */
+
+ return (attr == NULL) ? 1 : 0;
+}
+
+static int
+remove_attr(pthread_mutexattr_t *attr)
+{
+ /* Remove this attribute object from the list. */
+
+ /* FIXME: implement. */
+ return 0;
+}
+
+int
+pthread_mutexattr_init(pthread_mutexattr_t *attr)
+{
+ if (attr == NULL)
+ {
+ /* This is disallowed. */
+ return EINVAL;
+ }
+
+ attr->ptr = malloc(sizeof(_pthread_mutexattr_t));
+ if (attr->ptr == NULL)
+ {
+ return ENOMEM;
+ }
+
+ (_pthread_mutexattr_t *) (attr->ptr).proc_shared = PTHREAD_PROCESS_PRIVATE;
+
+ return 0;
+}
+
+int
+pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
+{
+ if (is_attr(attr) != 0)
+ {
+ return EINVAL;
+ }
+ else
+ {
+ free(attr->ptr);
+ return 0;
+ }
+}
+
+int
+pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int process_shared)
+{
+ /* Ensure the value for this attribute is within the legal range. */
+ if ((process_shared != PTHREAD_PROCESS_PRIVATE) ||
+ (process_shared != PTHREAD_PROCESS_SHARED))
+ {
+ return EINVAL;
+ }
+
+ /* Ensure attr points to a valid attribute object. */
+ if (is_attr(attr) != 0)
+ {
+ return EINVAL;
+ }
+
+ /* Everything is okay. */
+ (_pthread_mutexattr_t *) (attr->ptr)->proc_shared = process_shared;
+ return 0;
+}
+
+int
+pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr,
+ int *process_shared)
+{
+ if (is_attr(attr) != 0)
+ {
+ return EINVAL;
+ }
+
+ /* Everything is okay. */
+ *process_shared = (_pthread_mutexattr_t *) (attr->ptr)->proc_shared;
+ return 0;
+}
+
int
pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
int protocol)