* Fixed incorrect check: The behavior of pthread_mutex_unlock() is undefined
when called with a default-type mutex owned by another thread. * Automatic whitespace cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36294 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+12
-17
@@ -2,16 +2,16 @@
|
|||||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||||
* This file is licensed under the GPL license. For the full content
|
* This file is licensed under the GPL license. For the full content
|
||||||
* of this license, see the COPYING file at the top level of this
|
* of this license, see the COPYING file at the top level of this
|
||||||
* source tree.
|
* source tree.
|
||||||
|
|
||||||
* Test that pthread_cond_timedwait()
|
* Test that pthread_cond_timedwait()
|
||||||
* shall be equivalent to pthread_cond_wait(), except that an error is returned
|
* shall be equivalent to pthread_cond_wait(), except that an error is returned
|
||||||
* if the absolute time specified by abstime has already been passed at the time
|
* if the absolute time specified by abstime has already been passed at the time
|
||||||
* of the call.
|
* of the call.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _XOPEN_SOURCE 600
|
#define _XOPEN_SOURCE 600
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
@@ -37,14 +37,14 @@ void *t1_func(void *arg)
|
|||||||
int rc;
|
int rc;
|
||||||
struct timeval curtime;
|
struct timeval curtime;
|
||||||
struct timespec timeout;
|
struct timespec timeout;
|
||||||
|
|
||||||
if (pthread_mutex_lock(&td.mutex) != 0) {
|
if (pthread_mutex_lock(&td.mutex) != 0) {
|
||||||
fprintf(stderr,"Thread1 failed to acquire the mutex\n");
|
fprintf(stderr,"Thread1 failed to acquire the mutex\n");
|
||||||
exit(PTS_UNRESOLVED);
|
exit(PTS_UNRESOLVED);
|
||||||
}
|
}
|
||||||
fprintf(stderr,"Thread1 started\n");
|
fprintf(stderr,"Thread1 started\n");
|
||||||
t1_start = 1; /* let main thread continue */
|
t1_start = 1; /* let main thread continue */
|
||||||
|
|
||||||
if (gettimeofday(&curtime, NULL) !=0 ) {
|
if (gettimeofday(&curtime, NULL) !=0 ) {
|
||||||
fprintf(stderr,"Fail to get current time\n");
|
fprintf(stderr,"Fail to get current time\n");
|
||||||
exit(PTS_UNRESOLVED);
|
exit(PTS_UNRESOLVED);
|
||||||
@@ -85,7 +85,7 @@ int main()
|
|||||||
return PTS_UNRESOLVED;
|
return PTS_UNRESOLVED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the thread hasn't ended in 5 seconds, then most probably
|
/* If the thread hasn't ended in 5 seconds, then most probably
|
||||||
* pthread_cond_timedwait is failing to function correctly. */
|
* pthread_cond_timedwait is failing to function correctly. */
|
||||||
alarm(5);
|
alarm(5);
|
||||||
|
|
||||||
@@ -96,29 +96,24 @@ int main()
|
|||||||
return PTS_UNRESOLVED;
|
return PTS_UNRESOLVED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure pthread_cond_timedwait released and re-acquired the mutex
|
/* Make sure pthread_cond_timedwait released and re-acquired the mutex
|
||||||
* as it should. */
|
* as it should. */
|
||||||
rc=pthread_mutex_trylock(&td.mutex);
|
rc=pthread_mutex_trylock(&td.mutex);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
fprintf(stderr,"Test FAILED: Did not re-acquire mutex after timedout out call to pthread_cond_timedwait\n");
|
fprintf(stderr,"Test FAILED: Did not re-acquire mutex after timedout out call to pthread_cond_timedwait\n");
|
||||||
return PTS_FAIL;
|
return PTS_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pthread_mutex_unlock(&td.mutex) != 0) {
|
|
||||||
fprintf(stderr,"Main failed to release mutex\n");
|
|
||||||
return PTS_UNRESOLVED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(th_ret == PTS_PASS)
|
if(th_ret == PTS_PASS)
|
||||||
{
|
{
|
||||||
printf("Test PASSED\n");
|
printf("Test PASSED\n");
|
||||||
return PTS_PASS;
|
return PTS_PASS;
|
||||||
}
|
}
|
||||||
else if(th_ret == PTS_FAIL)
|
else if(th_ret == PTS_FAIL)
|
||||||
{
|
{
|
||||||
printf("Test FAILED\n");
|
printf("Test FAILED\n");
|
||||||
return PTS_FAIL;
|
return PTS_FAIL;
|
||||||
} else
|
} else
|
||||||
return PTS_UNRESOLVED;
|
return PTS_UNRESOLVED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user