mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-27 02:45:32 +02:00
[220446] Converted request monitor excercises to use the request monitor.
This commit is contained in:
parent
7456589c4f
commit
fd71e3600f
4 changed files with 73 additions and 63 deletions
|
@ -8,24 +8,25 @@
|
||||||
|
|
||||||
Contributors:
|
Contributors:
|
||||||
IBM Corporation - initial API and implementation
|
IBM Corporation - initial API and implementation
|
||||||
|
Wind River Systems - adopted to use with DSF
|
||||||
|
|
||||||
EclipseCon
|
EclipseCon
|
||||||
Debug Tutorial Exercises
|
DSF Tutorial Exercises
|
||||||
====================================================================== -->
|
====================================================================== -->
|
||||||
<project name="EclipseCon" default="generateAll">
|
<project name="EclipseCon" default="generateAll">
|
||||||
<description>
|
<description>
|
||||||
Debug Tutorial Exercises
|
DSF Tutorial Exercises
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<taskdef name="preprocess" classname="org.eclipse.dd.examples.ant.tasks.PreProcessor" classpath="../bin" />
|
<taskdef name="preprocess" classname="org.eclipse.dd.examples.ant.tasks.PreProcessor" classpath="bin" />
|
||||||
<property name="workspace" location="c:\eclipse-dev\dev-3.4" />
|
<property name="$workspace" location="c:\eclipse-dev\dev-3.4" />
|
||||||
<property name="srcBase" location="${workspace}/org.eclipse.dd.examples.dsf/src_preprocess" />
|
<property name="srcBase" location="${workspace}/org.eclipse.dd.examples.dsf/src_preprocess" />
|
||||||
<property name="destBase" location="${workspace}/org.eclipse.dd.examples.dsf/src" />
|
<property name="destBase" location="${workspace}/org.eclipse.dd.examples.dsf/src" />
|
||||||
|
|
||||||
<!-- =================================
|
<!-- =================================
|
||||||
target: generateAll
|
target: generateAll
|
||||||
================================= -->
|
================================= -->
|
||||||
<target name="generateAll" description="--> Debug Tutorial Exercises">
|
<target name="generateAll" description="--> DSF Tutorial Exercises">
|
||||||
|
|
||||||
<!-- = = = = = = = = = = = = = = = = =
|
<!-- = = = = = = = = = = = = = = = = =
|
||||||
macrodef: process
|
macrodef: process
|
||||||
|
@ -34,17 +35,19 @@
|
||||||
<attribute name="packagedir"/>
|
<attribute name="packagedir"/>
|
||||||
<attribute name="symbols"/>
|
<attribute name="symbols"/>
|
||||||
<sequential>
|
<sequential>
|
||||||
<delete dir="@{destBase}/${packagedir}/excercise"/>
|
<delete dir="src/@{packagedir}"/>
|
||||||
<delete dir="@{destBase}/${packagedir}/answer"/>
|
<mkdir dir="src/@{packagedir}"/>
|
||||||
<mkdir dir="@{destBase}/${packagedir}/excercise"/>
|
<mkdir dir="src/@{packagedir}/answers"/>
|
||||||
<mkdir dir="@{destBase}/${packagedir}/answer"/>
|
<preprocess destdir="src/@{packagedir}" symbols="excercises">
|
||||||
<preprocess destdir="@{destBase}/${packagedir}/excercise" symbols="@{symbols}">
|
<fileset dir="src_preprocess/@{packagedir}"/>
|
||||||
<fileset dir="@{destBase}/${packagedir}"/>
|
</preprocess>
|
||||||
|
<preprocess destdir="src/@{packagedir}/answers" symbols="answers">
|
||||||
|
<fileset dir="src_preprocess/@{packagedir}"/>
|
||||||
</preprocess>
|
</preprocess>
|
||||||
</sequential>
|
</sequential>
|
||||||
</macrodef>
|
</macrodef>
|
||||||
|
|
||||||
<process packagedir="${srcBase}/org/eclipse/dd/examples/dsf/requestmonitor" symbols="request_monitors_ex1"/>
|
<process packagedir="org/eclipse/dd/examples/dsf/requestmonitor" symbols="answers"/>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -8,7 +8,11 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Wind River Systems - initial API and implementation
|
* Wind River Systems - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
//#ifdef excercises
|
||||||
package org.eclipse.dd.examples.dsf.requestmonitor;
|
package org.eclipse.dd.examples.dsf.requestmonitor;
|
||||||
|
//#else
|
||||||
|
//#package org.eclipse.dd.examples.dsf.requestmonitor.answers;
|
||||||
|
//#endif
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
|
@ -8,10 +8,10 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Wind River Systems - initial API and implementation
|
* Wind River Systems - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
//#ifdef request_monitors_ex1
|
//#ifdef excercises
|
||||||
//#package org.eclipse.dd.examples.dsf.requestmonitor.excercise;
|
package org.eclipse.dd.examples.dsf.requestmonitor;
|
||||||
//#else
|
//#else
|
||||||
package org.eclipse.dd.examples.dsf.requestmonitor.answer;
|
//#package org.eclipse.dd.examples.dsf.requestmonitor.answers;
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
@ -37,23 +37,21 @@ public class AsyncHelloWorld {
|
||||||
|
|
||||||
static void asyncHelloWorld(RequestMonitor rm) {
|
static void asyncHelloWorld(RequestMonitor rm) {
|
||||||
System.out.println("Hello world");
|
System.out.println("Hello world");
|
||||||
//#ifdef request_monitors_ex1
|
//#ifdef excercises
|
||||||
//# // TODO: Request Monitors Exercise 1 - Call a second async.
|
// TODO Exercise 1: - Call the second async. "Hello world 2" method.
|
||||||
//# // "Hello world 2" method.
|
rm.done();
|
||||||
//# rm.done();
|
|
||||||
//#else
|
//#else
|
||||||
RequestMonitor rm2 = new RequestMonitor(ImmediateExecutor.getInstance(), rm);
|
//# RequestMonitor rm2 = new RequestMonitor(ImmediateExecutor.getInstance(), rm);
|
||||||
asyncHelloWorld2(rm2);
|
//# asyncHelloWorld2(rm2);
|
||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//#ifdef request_monitors_ex1
|
//#ifdef excercises
|
||||||
//# // TODO: Request Monitors Exercise 1 - Add a second async.
|
// TODO: Exercise 1 - Add a second async. "Hello world 2" method.
|
||||||
//# // "Hello world 2" method.
|
|
||||||
//#else
|
//#else
|
||||||
static void asyncHelloWorld2(RequestMonitor rm) {
|
//# static void asyncHelloWorld2(RequestMonitor rm) {
|
||||||
System.out.println("Hello world 2");
|
//# System.out.println("Hello world 2");
|
||||||
rm.done();
|
//# rm.done();
|
||||||
}
|
//# }
|
||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,19 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Wind River Systems - initial API and implementation
|
* Wind River Systems - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
//#ifdef excercises
|
||||||
package org.eclipse.dd.examples.dsf.requestmonitor;
|
package org.eclipse.dd.examples.dsf.requestmonitor;
|
||||||
|
//#else
|
||||||
|
//#package org.eclipse.dd.examples.dsf.requestmonitor.answers;
|
||||||
|
//#endif
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import org.eclipse.dd.dsf.concurrent.CountingRequestMonitor;
|
import org.eclipse.dd.dsf.concurrent.CountingRequestMonitor;
|
||||||
|
//#ifdef answers
|
||||||
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
|
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
|
||||||
|
//#endif
|
||||||
import org.eclipse.dd.dsf.concurrent.ImmediateExecutor;
|
import org.eclipse.dd.dsf.concurrent.ImmediateExecutor;
|
||||||
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
|
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
|
||||||
|
|
||||||
|
@ -45,43 +51,42 @@ public class AsyncQuicksort {
|
||||||
{
|
{
|
||||||
if (right > left) {
|
if (right > left) {
|
||||||
int pivot = left;
|
int pivot = left;
|
||||||
//#ifdef request_monitors_ex2
|
//#ifdef excercises
|
||||||
//# // TODO: Request Monitors Exercise 2 - Convert partition to an async. method.
|
// TODO: Request Monitors Exercise 2 - Convert partition to an async. method.
|
||||||
//# int newPivot = partition(array, left, right, pivot);
|
int newPivot = partition(array, left, right, pivot);
|
||||||
//# int newPivot = getData();
|
printArray(array, left, right, newPivot);
|
||||||
//# printArray(array, left, right, newPivot);
|
|
||||||
//#
|
|
||||||
//# CountingRequestMonitor countingRm = new CountingRequestMonitor(fgExecutor, rm);
|
|
||||||
//# asyncQuicksort(array, left, newPivot - 1, countingRm);
|
|
||||||
//# asyncQuicksort(array, newPivot + 1, right, countingRm);
|
|
||||||
//# countingRm.setDoneCount(2);
|
|
||||||
//#else
|
|
||||||
asyncPartition(
|
|
||||||
array, left, right, pivot,
|
|
||||||
new DataRequestMonitor<Integer>(fgExecutor, rm) {
|
|
||||||
@Override
|
|
||||||
protected void handleCompleted() {
|
|
||||||
int newPivot = getData();
|
|
||||||
printArray(array, left, right, newPivot);
|
|
||||||
|
|
||||||
CountingRequestMonitor countingRm = new CountingRequestMonitor(fgExecutor, rm);
|
CountingRequestMonitor countingRm = new CountingRequestMonitor(fgExecutor, rm);
|
||||||
asyncQuicksort(array, left, newPivot - 1, countingRm);
|
asyncQuicksort(array, left, newPivot - 1, countingRm);
|
||||||
asyncQuicksort(array, newPivot + 1, right, countingRm);
|
asyncQuicksort(array, newPivot + 1, right, countingRm);
|
||||||
countingRm.setDoneCount(2);
|
countingRm.setDoneCount(2);
|
||||||
}
|
//#else
|
||||||
});
|
//# asyncPartition(
|
||||||
//#endif
|
//# array, left, right, pivot,
|
||||||
|
//# new DataRequestMonitor<Integer>(fgExecutor, rm) {
|
||||||
|
//# @Override
|
||||||
|
//# protected void handleCompleted() {
|
||||||
|
//# int newPivot = getData();
|
||||||
|
//# printArray(array, left, right, newPivot);
|
||||||
|
//#
|
||||||
|
//# CountingRequestMonitor countingRm = new CountingRequestMonitor(fgExecutor, rm);
|
||||||
|
//# asyncQuicksort(array, left, newPivot - 1, countingRm);
|
||||||
|
//# asyncQuicksort(array, newPivot + 1, right, countingRm);
|
||||||
|
//# countingRm.setDoneCount(2);
|
||||||
|
//# }
|
||||||
|
//# });
|
||||||
|
//#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
rm.done();
|
rm.done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#ifdef request_monitors_ex2
|
//#ifdef excercises
|
||||||
//# // TODO: Request Monitors Exercise 2 - Convert partition to an async. method.
|
// TODO Exercise 2 - Convert partition to an asynchronous method.
|
||||||
//# static int partition(int[] array, int left, int right, int pivot)
|
static int partition(int[] array, int left, int right, int pivot)
|
||||||
//#else
|
//#else
|
||||||
static void asyncPartition(int[] array, int left, int right, int pivot, DataRequestMonitor<Integer> rm)
|
//# static void asyncPartition(int[] array, int left, int right, int pivot, DataRequestMonitor<Integer> rm)
|
||||||
//#endif
|
//#endif
|
||||||
{
|
{
|
||||||
int pivotValue = array[pivot];
|
int pivotValue = array[pivot];
|
||||||
|
@ -99,12 +104,12 @@ public class AsyncQuicksort {
|
||||||
array[right] = array[store];
|
array[right] = array[store];
|
||||||
array[store] = pivotValue;
|
array[store] = pivotValue;
|
||||||
|
|
||||||
//#ifdef request_monitors_ex2
|
//#ifdef excercises
|
||||||
//# // TODO: Request Monitors Exercise 2 - Convert partition to an async. method.
|
// TODO: Request Monitors Exercise 2 - Convert partition to an async. method.
|
||||||
//# return store;
|
return store;
|
||||||
//#else
|
//#else
|
||||||
rm.setData(store);
|
//# rm.setData(store);
|
||||||
rm.done();
|
//# rm.done();
|
||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue