chiark / gitweb /
windows: consistent formatting windows
authorRichard Kettlewell <rjk@terraraq.org.uk>
Sat, 29 Dec 2012 11:28:06 +0000 (11:28 +0000)
committerRichard Kettlewell <rjk@terraraq.org.uk>
Sat, 29 Dec 2012 11:28:06 +0000 (11:28 +0000)
windows/mandycs/Fixed128.cs
windows/mandycs/JobQueue.cs
windows/tests/JobQueueTest.cs

index 83b27ec..4f37061 100644 (file)
@@ -98,8 +98,7 @@ namespace uk.org.greenend.mandy
     {
       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
@@ -148,7 +147,7 @@ namespace uk.org.greenend.mandy
     #endregion
 
     #region Arithmetic Operations
-    
+
     /// <summary>
     /// Add fixed-point values
     /// </summary>
@@ -357,7 +356,7 @@ namespace uk.org.greenend.mandy
     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")]
@@ -369,7 +368,7 @@ namespace uk.org.greenend.mandy
     [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
 
index a016748..7187c42 100644 (file)
@@ -97,25 +97,20 @@ namespace uk.org.greenend.mandy
     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);
           }
@@ -137,8 +132,7 @@ namespace uk.org.greenend.mandy
     /// <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
@@ -147,7 +141,7 @@ namespace uk.org.greenend.mandy
       }
       workersCreated = true;
     }
-    
+
     /// <summary>
     /// Add a job to the queue
     /// </summary>
@@ -155,10 +149,8 @@ namespace uk.org.greenend.mandy
     /// <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;
@@ -178,13 +170,10 @@ namespace uk.org.greenend.mandy
     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);
@@ -192,8 +181,7 @@ namespace uk.org.greenend.mandy
           node = next;
         }
       }
-      foreach (var job in cancelled)
-      {
+      foreach (var job in cancelled) {
         job.Cancel();
       }
     }
@@ -213,20 +201,16 @@ namespace uk.org.greenend.mandy
     {
       // 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);
@@ -239,20 +223,17 @@ namespace uk.org.greenend.mandy
           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;
index 874154c..2e7f33d 100644 (file)
@@ -62,16 +62,14 @@ namespace tests
       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));
@@ -87,8 +85,7 @@ namespace tests
       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);
@@ -99,22 +96,19 @@ namespace tests
       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));
         }
-      }  
+      }
     }
   }
 }