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