{
Fixed128 r = 0;
int error = Fixed128_str2_cs(ref r, s);
- switch(error)
- {
+ switch (error) {
case 0: // FIXED128_STR_OK
break;
case 1: // FIXED128_STR_RANGE
#endregion
#region Arithmetic Operations
-
+
/// <summary>
/// Add fixed-point values
/// </summary>
private static extern int Fixed128_str2_cs(ref Fixed128 r, string s);
[DllImport("libmandy.dll")]
- private unsafe static extern IntPtr Fixed128_2str(byte *buffer, IntPtr bufsize,
+ private unsafe static extern IntPtr Fixed128_2str(byte* buffer, IntPtr bufsize,
ref Fixed128 a, int radix);
[DllImport("libmandy.dll")]
[DllImport("libmandy.dll")]
private static extern double iterate_cs(ref Fixed128 zx, ref Fixed128 zy,
ref Fixed128 cx, ref Fixed128 cy,
- int maxiters, int arith);
+ int maxiters, int arith);
#endregion
static private void Worker()
{
Monitor.Enter(jobsPending);
- while (true)
- {
- if (jobsPending.Count > 0)
- {
+ while (true) {
+ if (jobsPending.Count > 0) {
// There is work to be done
Job j = jobsPending.First.Value;
jobsPending.RemoveFirst();
jobsWorking.Add(j);
Monitor.Exit(jobsPending);
- try
- {
+ try {
j.Run();
}
- catch (Exception)
- {
+ catch (Exception) {
// Jobs that throw exceptions just lose them.
}
- lock (jobsComplete)
- {
+ lock (jobsComplete) {
jobsComplete.AddLast(j);
Monitor.PulseAll(jobsComplete);
}
/// <remarks><para>Called with lock held.</para></remarks>
static private void CreateWorkers()
{
- for (int n = 0; n < Workers; ++n)
- {
+ for (int n = 0; n < Workers; ++n) {
Thread newThread = new Thread(new ThreadStart(Worker))
{
IsBackground = true
}
workersCreated = true;
}
-
+
/// <summary>
/// Add a job to the queue
/// </summary>
/// <param name="context">Context information</param>
public static void Add(Job job, object context)
{
- lock (jobsPending)
- {
- if (!workersCreated)
- {
+ lock (jobsPending) {
+ if (!workersCreated) {
CreateWorkers();
}
job.context = context;
public static void Cancel(object context)
{
List<Job> cancelled = new List<Job>();
- lock (jobsPending)
- {
- for (var node = jobsPending.First; node != null; )
- {
+ lock (jobsPending) {
+ for (var node = jobsPending.First; node != null; ) {
var next = node.Next;
- if (node.Value.context == context)
- {
+ if (node.Value.context == context) {
jobsPending.Remove(node);
// The cancel callback had better be issued outside the lock
cancelled.Add(node.Value);
node = next;
}
}
- foreach (var job in cancelled)
- {
+ foreach (var job in cancelled) {
job.Cancel();
}
}
{
// Special case a count of 0 - it's a stupid value to pass
// but it shouldn't cause a hang.
- if (count == 0)
- {
+ if (count == 0) {
return 0;
}
int completed = 0;
Monitor.Enter(jobsComplete);
- while (true)
- {
+ while (true) {
int completedThisTime = 0;
- for (var node = jobsComplete.First; count > 0 && node != null; )
- {
+ for (var node = jobsComplete.First; count > 0 && node != null; ) {
var next = node.Next;
- if (context == null || node.Value.context == context)
- {
+ if (context == null || node.Value.context == context) {
// Found a suitable job. Remove it from the list
// and then call Complete() on it.
jobsComplete.Remove(node);
node = next;
}
completed += completedThisTime;
- if (count == 0)
- {
+ if (count == 0) {
// We've done as much work as we were asked to do.
break;
}
- if (completedThisTime > 0)
- {
+ if (completedThisTime > 0) {
// If we did any work we'll have released the lock, so it's
// possible that more work arrived in the meantime. Go back
// and check.
continue;
}
- if (!block)
- {
+ if (!block) {
// We didn't find any work to do. If we were asked not to block,
// exit now.
break;
const int nJobs = 128;
List<TestJob> jobs = new List<TestJob>();
// Create a collection of jobs and run them
- for (int i = 0; i < nJobs; ++i)
- {
+ for (int i = 0; i < nJobs; ++i) {
TestJob job = new TestJob();
jobs.Add(job);
JobQueue.Add(job, this);
}
int complete = JobQueue.Complete(nJobs, null, true);
Assert.AreEqual(nJobs, complete, string.Format("only {0} jobs completed", complete));
- for(int i = 0; i < nJobs; ++i)
- {
+ for (int i = 0; i < nJobs; ++i) {
var job = jobs[i];
Assert.AreEqual(true, job.hasRun, string.Format("job {0} wasn't run", i));
Assert.AreEqual(true, job.hasCompleted, string.Format("job {0} wasn't completed", i));
const int nJobs = 128;
List<TestJob> classOneJobs = new List<TestJob>();
List<TestJob> classTwoJobs = new List<TestJob>();
- for (int i = 0; i < nJobs; ++i)
- {
+ for (int i = 0; i < nJobs; ++i) {
TestJob job = new TestJob();
classOneJobs.Add(job);
JobQueue.Add(job, classOneJobs);
JobQueue.Cancel(classTwoJobs);
int complete = JobQueue.Complete(2 * nJobs, null, true);
Assert.IsTrue(complete >= nJobs, string.Format("only {0} jobs completed", complete));
- for (int i = 0; i < nJobs; ++i)
- {
+ for (int i = 0; i < nJobs; ++i) {
var job = classOneJobs[i];
Assert.AreEqual(true, job.hasRun, string.Format("class one job {0} wasn't run", i));
Assert.AreEqual(true, job.hasCompleted, string.Format("class one job {0} wasn't completed", i));
job = classTwoJobs[i];
- if (job.hasRun)
- {
+ if (job.hasRun) {
Assert.AreEqual(true, job.hasCompleted, string.Format("class two job {0} run but wasn't completed", i));
}
- else
- {
+ else {
Assert.AreEqual(false, job.hasCompleted, string.Format("class two job {0} didn't run but was completed", i));
Assert.AreEqual(true, job.hasCancelled, string.Format("class two job {0} didn't run but wasn't cancelled", i));
}
- }
+ }
}
}
}