summaryrefslogtreecommitdiffstats
path: root/libc/bionic/pthread.c
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:03:48 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:03:48 -0800
commit4e468ed2eb86a2406e14f1eca82072ee501d05fd (patch)
tree4e05b3c66eef86531e464521a3bf96a1864d4bf5 /libc/bionic/pthread.c
parenta27d2baa0c1a2ec70f47ea9199b1dd6762c8a349 (diff)
downloadbionic-4e468ed2eb86a2406e14f1eca82072ee501d05fd.zip
bionic-4e468ed2eb86a2406e14f1eca82072ee501d05fd.tar.gz
bionic-4e468ed2eb86a2406e14f1eca82072ee501d05fd.tar.bz2
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'libc/bionic/pthread.c')
-rw-r--r--libc/bionic/pthread.c85
1 files changed, 44 insertions, 41 deletions
diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c
index 67fc519..2fd740e 100644
--- a/libc/bionic/pthread.c
+++ b/libc/bionic/pthread.c
@@ -767,6 +767,25 @@ int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
return EINVAL;
}
+/* process-shared mutexes are not supported at the moment */
+
+int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
+{
+ if (!attr)
+ return EINVAL;
+
+ return (pshared == PTHREAD_PROCESS_PRIVATE) ? 0 : ENOTSUP;
+}
+
+int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared)
+{
+ if (!attr)
+ return EINVAL;
+
+ *pshared = PTHREAD_PROCESS_PRIVATE;
+ return 0;
+}
+
int pthread_mutex_init(pthread_mutex_t *mutex,
const pthread_mutexattr_t *attr)
{
@@ -1120,54 +1139,31 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
return pthread_cond_timedwait(cond, mutex, NULL);
}
-int pthread_cond_timedwait(pthread_cond_t *cond,
- pthread_mutex_t * mutex,
- const struct timespec *abstime)
+int __pthread_cond_timedwait_relative(pthread_cond_t *cond,
+ pthread_mutex_t * mutex,
+ const struct timespec *reltime)
{
- int oldvalue;
- struct timespec ts;
- struct timespec * tsp;
- int status;
-
- if (abstime != NULL) {
- clock_gettime(CLOCK_REALTIME, &ts);
- ts.tv_sec = abstime->tv_sec - ts.tv_sec;
- ts.tv_nsec = abstime->tv_nsec - ts.tv_nsec;
- if (ts.tv_nsec < 0) {
- ts.tv_sec--;
- ts.tv_nsec += 1000000000;
- }
- if((ts.tv_nsec < 0) || (ts.tv_sec < 0)) {
- return ETIMEDOUT;
- }
- tsp = &ts;
- } else {
- tsp = NULL;
- }
-
- oldvalue = cond->value;
+ int status;
+ int oldvalue = cond->value;
pthread_mutex_unlock(mutex);
- status = __futex_wait(&cond->value, oldvalue, tsp);
+ status = __futex_wait(&cond->value, oldvalue, reltime);
pthread_mutex_lock(mutex);
- if(status == (-ETIMEDOUT)) return ETIMEDOUT;
-
+ if (status == (-ETIMEDOUT)) return ETIMEDOUT;
return 0;
}
-
-int pthread_cond_timedwait_monotonic(pthread_cond_t *cond,
- pthread_mutex_t * mutex,
- const struct timespec *abstime)
+int __pthread_cond_timedwait(pthread_cond_t *cond,
+ pthread_mutex_t * mutex,
+ const struct timespec *abstime,
+ clockid_t clock)
{
- int oldvalue;
struct timespec ts;
struct timespec * tsp;
- int status;
if (abstime != NULL) {
- clock_gettime(CLOCK_MONOTONIC, &ts);
+ clock_gettime(clock, &ts);
ts.tv_sec = abstime->tv_sec - ts.tv_sec;
ts.tv_nsec = abstime->tv_nsec - ts.tv_nsec;
if (ts.tv_nsec < 0) {
@@ -1182,15 +1178,22 @@ int pthread_cond_timedwait_monotonic(pthread_cond_t *cond,
tsp = NULL;
}
- oldvalue = cond->value;
+ return __pthread_cond_timedwait_relative(cond, mutex, tsp);
+}
- pthread_mutex_unlock(mutex);
- status = __futex_wait(&cond->value, oldvalue, tsp);
- pthread_mutex_lock(mutex);
+int pthread_cond_timedwait(pthread_cond_t *cond,
+ pthread_mutex_t * mutex,
+ const struct timespec *abstime)
+{
+ return __pthread_cond_timedwait(cond, mutex, abstime, CLOCK_REALTIME);
+}
- if(status == (-ETIMEDOUT)) return ETIMEDOUT;
- return 0;
+int pthread_cond_timedwait_monotonic(pthread_cond_t *cond,
+ pthread_mutex_t * mutex,
+ const struct timespec *abstime)
+{
+ return __pthread_cond_timedwait(cond, mutex, abstime, CLOCK_MONOTONIC);
}
int pthread_cond_timeout_np(pthread_cond_t *cond,