summaryrefslogtreecommitdiff
path: root/attr.c
diff options
context:
space:
mode:
Diffstat (limited to 'attr.c')
-rw-r--r--attr.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/attr.c b/attr.c
index 1b4f348..00a728b 100644
--- a/attr.c
+++ b/attr.c
@@ -8,6 +8,16 @@
#include "pthread.h"
#include "implement.h"
+static int
+is_attr(pthread_attr_t *attr)
+{
+ /* Return 0 if the attr object is valid, 1 otherwise. */
+
+ return (attr == NULL || attr->valid != _PTHREAD_ATTR_VALID);
+}
+
+#ifdef _POSIX_THREAD_ATTR_STACKSIZE
+
int
pthread_attr_setstacksize(pthread_attr_t *attr,
size_t stacksize)
@@ -18,7 +28,7 @@ pthread_attr_setstacksize(pthread_attr_t *attr,
return EINVAL;
}
- if (attr == NULL)
+ if (is_attr(attr) != 0)
{
return EINVAL;
}
@@ -32,7 +42,7 @@ int
pthread_attr_getstacksize(const pthread_attr_t *attr,
size_t *stacksize)
{
- if (attr == NULL)
+ if (is_attr(attr) != 0)
{
return EINVAL;
}
@@ -42,11 +52,15 @@ pthread_attr_getstacksize(const pthread_attr_t *attr,
return 0;
}
+#endif /* _POSIX_THREAD_ATTR_STACKSIZE */
+
+#ifdef _POSIX_THREAD_ATTR_STACKADDR
+
int
pthread_attr_setstackaddr(pthread_attr_t *attr,
void *stackaddr)
{
- if (attr == NULL)
+ if (is_attr(attr) != 0)
{
return EINVAL;
}
@@ -59,7 +73,7 @@ int
pthread_attr_getstackaddr(const pthread_attr_t *attr,
void **stackaddr)
{
- if (attr == NULL)
+ if (is_attr(attr) != 0)
{
return EINVAL;
}
@@ -68,6 +82,9 @@ pthread_attr_getstackaddr(const pthread_attr_t *attr,
return ENOSYS;
}
+#endif /* _POSIX_THREAD_ATTR_STACKADDR */
+
+
int
pthread_attr_init(pthread_attr_t *attr)
{
@@ -77,8 +94,12 @@ pthread_attr_init(pthread_attr_t *attr)
return EINVAL;
}
- /* FIXME: Fill out the structure with default values. */
- attr->stacksize = 0;
+#ifdef _POSIX_THREAD_ATTR_STACKSIZE
+ attr->stacksize = PTHREAD_STACK_MIN;
+#endif
+
+ attr->cancelability = _PTHREAD_CANCEL_DEFAULTS;
+ attr->valid = 0;
return 0;
}
@@ -86,11 +107,13 @@ pthread_attr_init(pthread_attr_t *attr)
int
pthread_attr_destroy(pthread_attr_t *attr)
{
- if (attr == NULL)
+ if (is_attr(attr) != 0)
{
return EINVAL;
}
-
- /* Nothing to do. */
+
+ /* Set the attribute object to a specific invalid value. */
+ attr->valid = _PTHREAD_ATTR_INVALID;
+
return 0;
}