< prev index next >
src/share/vm/utilities/semaphore.cpp
Print this page
@@ -28,68 +28,33 @@
/////////////// Unit tests ///////////////
#ifndef PRODUCT
-static void test_semaphore_single_with_max_once(uint max) {
- assert(max > 0, "precondition");
+static void test_semaphore_single_separate(uint count) {
+ Semaphore sem(0);
- Semaphore sem(0, max);
-
- sem.signal();
- sem.wait();
-}
-
-static void test_semaphore_single_with_max_one_less(uint max) {
- assert(max > 0, "precondition");
-
- Semaphore sem(0, max);
-
- for (uint i = 0; i < max -1; i++) {
+ for (uint i = 0; i < count; i++) {
sem.signal();
}
- for (uint i = 0; i < max -1; i++) {
+ for (uint i = 0; i < count; i++) {
sem.wait();
}
}
-static void test_semaphore_single_with_max_all(uint max) {
- assert(max > 0, "precondition");
-
- Semaphore sem(0, max);
+static void test_semaphore_single_combined(uint count) {
+ Semaphore sem(0);
- for (uint i = 0; i < max; i++) {
- sem.signal();
- }
-
- for (uint i = 0; i < max; i++) {
- sem.wait();
- }
-}
-
-static void test_semaphore_single_with_value(uint value, uint max) {
- assert(max > 0, "precondition");
-
- Semaphore sem(value, max);
-
- for (uint i = 0; i < value; i++) {
- sem.wait();
- }
-}
-
-static void test_semaphore_single_multiple() {
- Semaphore sem(0, 1);
-
- for (uint i = 0; i < 100; i++) {
+ for (uint i = 0; i < count; i++) {
sem.signal();
sem.wait();
}
}
static void test_semaphore_many(uint value, uint max, uint increments) {
- Semaphore sem(value, max);
+ Semaphore sem(value);
uint total = value;
for (uint i = value; i + increments <= max; i += increments) {
sem.signal(increments);
@@ -112,21 +77,17 @@
}
}
void test_semaphore() {
for (uint i = 1; i < 10; i++) {
- test_semaphore_single_with_max_once(i);
- test_semaphore_single_with_max_one_less(i);
- test_semaphore_single_with_max_all(i);
+ test_semaphore_single_separate(i);
}
for (uint i = 0; i < 10; i++) {
- test_semaphore_single_with_value(i, 9 /* arbitrary max */);
+ test_semaphore_single_combined(i);
}
- test_semaphore_single_multiple();
-
test_semaphore_many();
}
#endif // PRODUCT
< prev index next >