2 * Copyright (c) 2007 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
29 #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
31 static pthread_mutex_t sBarrierMutex
;
32 static pthread_cond_t sBarrierFree
;
34 static volatile int sValue
= 0;
36 static void __attribute__((constructor
)) myinit()
38 pthread_mutex_init(&sBarrierMutex
, NULL
);
39 pthread_cond_init(&sBarrierFree
, NULL
);
42 void waitForState(int value
)
44 pthread_mutex_lock(&sBarrierMutex
);
45 while ( sValue
< value
) {
47 struct timespec tsTimeout
;
48 gettimeofday(&tvNow
, NULL
);
49 TIMEVAL_TO_TIMESPEC(&tvNow
, &tsTimeout
);
50 tsTimeout
.tv_sec
+= 2; // fail if block for 2 seconds
51 if ( pthread_cond_timedwait(&sBarrierFree
, &sBarrierMutex
, &tsTimeout
) == ETIMEDOUT
) {
52 FAIL("dlsym-dyld-locking");
56 pthread_mutex_unlock(&sBarrierMutex
);
60 void setState(int value
)
62 pthread_mutex_lock(&sBarrierMutex
);
64 pthread_cond_broadcast(&sBarrierFree
);
65 pthread_mutex_unlock(&sBarrierMutex
);