OLD | NEW |
1 // Copyright (c) 2014, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dartino project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 #include <pthread.h> | 5 #include <pthread.h> |
6 #include <unistd.h> | 6 #include <unistd.h> |
7 | 7 |
8 #include "src/shared/assert.h" | 8 #include "src/shared/assert.h" |
9 #include "src/shared/platform.h" | 9 #include "src/shared/platform.h" |
10 #include "src/shared/test_case.h" | 10 #include "src/shared/test_case.h" |
11 | 11 |
12 #include "src/vm/thread.h" | 12 #include "src/vm/thread.h" |
13 | 13 |
14 namespace fletch { | 14 namespace dartino { |
15 | 15 |
16 static void yield() { usleep(1); } | 16 static void yield() { usleep(1); } |
17 | 17 |
18 static const int kLockCounterLimit = 50; | 18 static const int kLockCounterLimit = 50; |
19 static int busy_lock_counter = 0; | 19 static int busy_lock_counter = 0; |
20 | 20 |
21 static void LoopIncrement(Mutex* mutex, int rem) { | 21 static void LoopIncrement(Mutex* mutex, int rem) { |
22 while (true) { | 22 while (true) { |
23 int count = 0; | 23 int count = 0; |
24 int last_count = -1; | 24 int last_count = -1; |
(...skipping 24 matching lines...) Expand all Loading... |
49 TEST_CASE(Mutex) { | 49 TEST_CASE(Mutex) { |
50 pthread_t other; | 50 pthread_t other; |
51 Mutex* mutex = Platform::CreateMutex(); | 51 Mutex* mutex = Platform::CreateMutex(); |
52 int thread_created = pthread_create(&other, NULL, &RunTestBusyLock, mutex); | 52 int thread_created = pthread_create(&other, NULL, &RunTestBusyLock, mutex); |
53 EXPECT_EQ(0, thread_created); | 53 EXPECT_EQ(0, thread_created); |
54 LoopIncrement(mutex, 1); | 54 LoopIncrement(mutex, 1); |
55 pthread_join(other, NULL); | 55 pthread_join(other, NULL); |
56 delete mutex; | 56 delete mutex; |
57 } | 57 } |
58 | 58 |
59 } // namespace fletch | 59 } // namespace dartino |
OLD | NEW |