public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: cagney@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM]  master: Add a ProcessIdentifierFactory; use.
Date: Thu, 31 Jan 2008 20:30:00 -0000	[thread overview]
Message-ID: <20080131202959.3124.qmail@sourceware.org> (raw)

The branch, master has been updated
       via  3f77e12c3116c763bea37e0b56d82862f22dcada (commit)
      from  d54ac89a4df090b463fc40bb4de4319e2da36111 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 3f77e12c3116c763bea37e0b56d82862f22dcada
Author: Andrew Cagney <cagney@redhat.com>
Date:   Thu Jan 31 15:22:55 2008 -0500

    Add a ProcessIdentifierFactory; use.
    
    frysk-sys/frysk/sys/ChangeLog
    2008-01-31  Andrew Cagney  <cagney@redhat.com>
    
    	* Child.java: Extend ProcessIdentiferDecorator.
    	* Daemon.java: Ditto.
    	* cni/Child.cxx (Child::child): Use ProcessIdentifierFactory.
    	* cni/Daemon.cxx (Daemon::daemon): Ditto.
    	* ProcessIdentifierDecorator.java: New file.
    	* TestProcessIdentifier.java: New file.
    	* ProcessIdentifierFactory.java: New file.
    	* ProcessIdentifier.java: Use intValue() instead of pid through
    	out.
    
    frysk-sys/frysk/testbed/ChangeLog
    2008-01-31  Andrew Cagney  <cagney@redhat.com>
    
    	* TearDownProcess.java: Use ProcessIdentifierFactory.

-----------------------------------------------------------------------

Summary of changes:
 frysk-sys/frysk/sys/ChangeLog                      |   12 ++++
 frysk-sys/frysk/sys/Child.java                     |   24 +++-----
 frysk-sys/frysk/sys/Daemon.java                    |   23 +++-----
 frysk-sys/frysk/sys/ProcessIdentifier.java         |   46 +++++----------
 .../ProcessIdentifierDecorator.java}               |   20 ++++--
 .../frysk/sys/ProcessIdentifierFactory.java        |   60 ++++++++++++++------
 .../frysk/sys/TestProcessIdentifier.java           |   42 ++++++--------
 frysk-sys/frysk/sys/cni/Child.cxx                  |    6 +-
 frysk-sys/frysk/sys/cni/Daemon.cxx                 |    6 +-
 frysk-sys/frysk/testbed/ChangeLog                  |    4 +
 frysk-sys/frysk/testbed/TearDownProcess.java       |   17 +++---
 11 files changed, 139 insertions(+), 121 deletions(-)
 copy frysk-sys/frysk/{CompilerVersion.java => sys/ProcessIdentifierDecorator.java} (86%)
 copy frysk-core/frysk/testbed/IsaTestbed.java => frysk-sys/frysk/sys/ProcessIdentifierFactory.java (62%)
 copy frysk-core/frysk/testbed/IsaTestbed.java => frysk-sys/frysk/sys/TestProcessIdentifier.java (71%)

First 500 lines of diff:
diff --git a/frysk-sys/frysk/sys/ChangeLog b/frysk-sys/frysk/sys/ChangeLog
index a29bfbc..cd00993 100644
--- a/frysk-sys/frysk/sys/ChangeLog
+++ b/frysk-sys/frysk/sys/ChangeLog
@@ -1,3 +1,15 @@
+2008-01-31  Andrew Cagney  <cagney@redhat.com>
+
+	* Child.java: Extend ProcessIdentiferDecorator.
+	* Daemon.java: Ditto.
+	* cni/Child.cxx (Child::child): Use ProcessIdentifierFactory.
+	* cni/Daemon.cxx (Daemon::daemon): Ditto.
+	* ProcessIdentifierDecorator.java: New file.
+	* TestProcessIdentifier.java: New file.
+	* ProcessIdentifierFactory.java: New file.
+	* ProcessIdentifier.java: Use intValue() instead of pid through
+	out.
+
 2008-01-25  Andrew Cagney  <cagney@redhat.com>
 
 	* Signal.java-sh: Add the synonyms - POLL, IOT, INFO and CLD -
diff --git a/frysk-sys/frysk/sys/Child.java b/frysk-sys/frysk/sys/Child.java
index d481035..825bf14 100644
--- a/frysk-sys/frysk/sys/Child.java
+++ b/frysk-sys/frysk/sys/Child.java
@@ -39,41 +39,33 @@
 
 package frysk.sys;
 
-public class Child
-    extends ProcessIdentifier
-{
+public class Child extends ProcessIdentifierDecorator {
     /**
      * Create a child process (direct decendant of this process) that
      * redirects its I/O to REDIRECT, and executes EXEC.
      *
      * Private.
      */
-    private static native int child (Redirect redirect, Execute exec);
-
+    private static native ProcessIdentifier child(Redirect redirect,
+						  Execute exec);
     /**
      * Create a child wired to IO redirect, running exec.
      *
      * Package private.
      */
-    Child (Redirect redirect, Execute exec)
-    {
+    Child(Redirect redirect, Execute exec) {
 	super (child (redirect, exec));
     }
-
     /**
      * Create a child wired to nothing; STDIN is closed, STDOUT/ERROR
      * are the same as for this process.
      */
-    public Child (Execute exec)
-    {
-	this (new Redirect ()
-	    {
-		protected void reopen ()
-		{
+    public Child(Execute exec) {
+	this(new Redirect() {
+		protected void reopen() {
 		    FileDescriptor.in.close ();
 		}
-		protected void close ()
-		{
+		protected void close() {
 		}
 	    }, exec);
     }
diff --git a/frysk-sys/frysk/sys/Daemon.java b/frysk-sys/frysk/sys/Daemon.java
index 371638f..6b2cf3d 100644
--- a/frysk-sys/frysk/sys/Daemon.java
+++ b/frysk-sys/frysk/sys/Daemon.java
@@ -44,22 +44,20 @@ package frysk.sys;
  * the parent.
  */
 
-public class Daemon
-    extends ProcessIdentifier
-{
+public class Daemon extends ProcessIdentifierDecorator {
     /**
      * Create a daemon process (child of process 1 a.k.a. init) that
      * redirects its I/O to REDIRECT, and executes EXEC.
      *
      * Package private.
      */
-    private static native int daemon (Redirect redirect, Execute exec);
+    private static native ProcessIdentifier daemon(Redirect redirect,
+						   Execute exec);
 
     /**
      * Create a daemon wired to REDIRECT, and running EXEC.
      */
-    Daemon (Redirect redirect, Execute exec)
-    {
+    Daemon(Redirect redirect, Execute exec) {
 	super (daemon (redirect, exec));
     }
 
@@ -67,15 +65,12 @@ public class Daemon
      * Create a daemon wired to nothing; STDIN is closed, STDOUT/ERROR
      * are the same as for this process.
      */
-    public Daemon (Execute exec)
-    {
-	this (new Redirect ()
-	    {
-		protected void reopen ()
-		{
-		    FileDescriptor.in.close ();
+    public Daemon(Execute exec) {
+	this(new Redirect() {
+		protected void reopen() {
+		    FileDescriptor.in.close();
 		}
-		protected void close ()
+		protected void close()
 		{
 		}
 	    }, exec);
diff --git a/frysk-sys/frysk/sys/ProcessIdentifier.java b/frysk-sys/frysk/sys/ProcessIdentifier.java
index b7cc1df..40118c6 100644
--- a/frysk-sys/frysk/sys/ProcessIdentifier.java
+++ b/frysk-sys/frysk/sys/ProcessIdentifier.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2007, Red Hat Inc.
+// Copyright 2007, 2008, Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -42,28 +42,17 @@ package frysk.sys;
 /**
  * Identifies a process.
  */
-public class ProcessIdentifier
-    implements Comparable
-{
-    private int pid;
-    public ProcessIdentifier (int pid)
-    {
-	this.pid = pid;
-    }
+public abstract class ProcessIdentifier implements Comparable {
     public int hashCode () {
-	return pid;
-    }
-    public int intValue() {
-        return pid;
+	return intValue();
     }
-    public int compareTo (Object o)
-    {
-	return ((ProcessIdentifier)o).pid - this.pid;
+    public abstract int intValue();
+    public int compareTo (Object o) {
+	return this.intValue() - ((ProcessIdentifier)o).intValue();
     }
-    public boolean equals (Object o)
-    {
+    public boolean equals(Object o) {
 	if (o instanceof ProcessIdentifier)
-	    return ((ProcessIdentifier)o).pid == this.pid;
+	    return ((ProcessIdentifier)o).intValue() == this.intValue();
 	else
 	    return false;
     }
@@ -71,39 +60,36 @@ public class ProcessIdentifier
      * Represent the ProcessIdentifier textually.  Return the PID as a
      * number so that it can be used directly.
      */
-    public String toString ()
-    {
-	return Integer.toString (pid);
+    public String toString () {
+	return Integer.toString(intValue());
     }
 
     /**
      * Send a fatal signal (SIGKILL) to this process.
      */
     public void kill() {
-	Signal.KILL.kill(pid);
+	Signal.KILL.kill(intValue());
     }
 
     /**
      * Send a signal to THIS pid.
      */
     public void tkill(Signal signal) {
-	signal.tkill(pid);
+	signal.tkill(intValue());
     }
 
     /**
      * Perform a blocking drain of all wait events from this process.
      * Only returns when the process has disappeared.
      */
-    public void blockingDrain ()
-    {
-	Wait.drain (pid);
+    public void blockingDrain() {
+	Wait.drain(intValue());
     }
 
     /**
      * Perform a blocking wait for a single event from this process.
      */
-    public void blockingWait (WaitBuilder o)
-    {
-	Wait.waitAll (pid, o);
+    public void blockingWait(WaitBuilder o) {
+	Wait.waitAll(intValue(), o);
     }
 }
diff --git a/frysk-sys/frysk/CompilerVersion.java b/frysk-sys/frysk/sys/ProcessIdentifierDecorator.java
similarity index 86%
copy from frysk-sys/frysk/CompilerVersion.java
copy to frysk-sys/frysk/sys/ProcessIdentifierDecorator.java
index 9e1eb71..f1d3418 100644
--- a/frysk-sys/frysk/CompilerVersion.java
+++ b/frysk-sys/frysk/sys/ProcessIdentifierDecorator.java
@@ -37,12 +37,18 @@
 // version and license this file solely under the GPL without
 // exception.
 
-package frysk;
+package frysk.sys;
 
-public class CompilerVersion {
-
-    public static native int getVersion();
-    public static native int getMinorVersion();
-    public static native int getPatchLevel();
-    public static native int getRHRelease();
+/**
+ * Identifies a process.
+ */
+public class ProcessIdentifierDecorator extends ProcessIdentifier {
+    private final ProcessIdentifier pid;
+    ProcessIdentifierDecorator(ProcessIdentifier pid) {
+	super();
+	this.pid = pid;
+    }
+    public int intValue() {
+        return pid.intValue();
+    }
 }
diff --git a/frysk-core/frysk/testbed/IsaTestbed.java b/frysk-sys/frysk/sys/ProcessIdentifierFactory.java
similarity index 62%
copy from frysk-core/frysk/testbed/IsaTestbed.java
copy to frysk-sys/frysk/sys/ProcessIdentifierFactory.java
index 5ea3c66..b5227fa 100644
--- a/frysk-core/frysk/testbed/IsaTestbed.java
+++ b/frysk-sys/frysk/sys/ProcessIdentifierFactory.java
@@ -37,36 +37,60 @@
 // version and license this file solely under the GPL without
 // exception.
 
-package frysk.testbed;
+package frysk.sys;
 
-import frysk.isa.ISA;
-import frysk.isa.ElfMap;
-import frysk.Config;
+import java.util.WeakHashMap;
+import java.util.Map;
 
 /**
- * Return the ISA being used by the testbed.
+ * Generates ProcessIdentifiers (and ensures that they are unique).
  */
+public class ProcessIdentifierFactory {
 
-public class IsaTestbed {
+    private static class ConcreteProcessIdentifier extends ProcessIdentifier {
+	private final int pid;
+	ConcreteProcessIdentifier(int pid) {
+	    this.pid = pid;
+	}
+	public int intValue() {
+	    return pid;
+	}
+    }
 
     /**
-     * Return the default isa being used for testing.
+     * Class to use when searching for an existing pid in the cached
+     * process table.
      */
-    public static ISA getISA() {
-	return ElfMap.getISA(Config.getPkgLibFile("funit-slave"));
+    private static class ProcessIdentifierKey extends ProcessIdentifier {
+	ProcessIdentifierKey() {
+	    super();
+	}
+	int pid;
+	public int intValue() {
+	    return pid;
+	}
     }
-    
-    /**
-     * Return the 32-bit isa being used for 32-on-64 testing.
-     */
-    public static ISA getISA32() {
-	return ElfMap.getISA(Config.getPkgLib32File("funit-slave"));
+
+    private static final Map processTable = new WeakHashMap();
+    private static final ProcessIdentifierKey key = new ProcessIdentifierKey();
+
+    static ProcessIdentifier create(int pid) {
+	synchronized (processTable) {
+	    key.pid = pid;
+	    ProcessIdentifier processIdentifier
+		= (ProcessIdentifier) processTable.get(key);
+	    if (processIdentifier == null) {
+		processIdentifier = new ConcreteProcessIdentifier(pid);
+		processTable.put(processIdentifier, processIdentifier);
+	    }
+	    return processIdentifier;
+	}
     }
 
     /**
-     * Return the 64-bit isa being used for 32-on-64 testing.
+     * Is going away.
      */
-    public static ISA getISA64() {
-	return ElfMap.getISA(Config.getPkgLib64File("funit-slave"));
+    public static ProcessIdentifier createFIXME(int pid) {
+	return create(pid);
     }
 }
diff --git a/frysk-core/frysk/testbed/IsaTestbed.java b/frysk-sys/frysk/sys/TestProcessIdentifier.java
similarity index 71%
copy from frysk-core/frysk/testbed/IsaTestbed.java
copy to frysk-sys/frysk/sys/TestProcessIdentifier.java
index 5ea3c66..44c6daa 100644
--- a/frysk-core/frysk/testbed/IsaTestbed.java
+++ b/frysk-sys/frysk/sys/TestProcessIdentifier.java
@@ -37,36 +37,32 @@
 // version and license this file solely under the GPL without
 // exception.
 
-package frysk.testbed;
+package frysk.sys;
 
-import frysk.isa.ISA;
-import frysk.isa.ElfMap;
-import frysk.Config;
+import frysk.junit.TestCase;
 
 /**
- * Return the ISA being used by the testbed.
+ * Generates ProcessIdentifiers (and ensures that they are unique).
  */
+public class TestProcessIdentifier extends TestCase {
 
-public class IsaTestbed {
-
-    /**
-     * Return the default isa being used for testing.
-     */
-    public static ISA getISA() {
-	return ElfMap.getISA(Config.getPkgLibFile("funit-slave"));
+    public void testSingleton() {
+	assertSame("pid", ProcessIdentifierFactory.create(1),
+		   ProcessIdentifierFactory.create(1));
     }
-    
-    /**
-     * Return the 32-bit isa being used for 32-on-64 testing.
-     */
-    public static ISA getISA32() {
-	return ElfMap.getISA(Config.getPkgLib32File("funit-slave"));
+
+    public void testEquals() {
+	ProcessIdentifier one = ProcessIdentifierFactory.create(1);
+	ProcessIdentifier two = ProcessIdentifierFactory.create(2);
+	assertTrue("one == one", one.equals(one));
+	assertFalse("one != two", one.equals(two));
     }
 
-    /**
-     * Return the 64-bit isa being used for 32-on-64 testing.
-     */
-    public static ISA getISA64() {
-	return ElfMap.getISA(Config.getPkgLib64File("funit-slave"));
+    public void testCompareTo() {
+	ProcessIdentifier one = ProcessIdentifierFactory.create(1);
+	ProcessIdentifier two = ProcessIdentifierFactory.create(2);
+	assertTrue("one == one", one.compareTo(one) == 0);
+	assertTrue("one < two", one.compareTo(two) < 0);
+	assertTrue("two > one", two.compareTo(one) > 0);
     }
 }
diff --git a/frysk-sys/frysk/sys/cni/Child.cxx b/frysk-sys/frysk/sys/cni/Child.cxx
index f3f3358..26741bf 100644
--- a/frysk-sys/frysk/sys/cni/Child.cxx
+++ b/frysk-sys/frysk/sys/cni/Child.cxx
@@ -49,11 +49,13 @@
 
 #include "frysk/sys/cni/Errno.hxx"
 #include "frysk/sys/ProcessIdentifier.h"
+#include "frysk/sys/ProcessIdentifierFactory.h"
+#include "frysk/sys/ProcessIdentifierDecorator.h"
 #include "frysk/sys/Child.h"
 #include "frysk/sys/Redirect.h"
 #include "frysk/sys/Execute.h"
 
-jint
+frysk::sys::ProcessIdentifier*
 frysk::sys::Child::child (frysk::sys::Redirect* redirect,
 			  frysk::sys::Execute* exec)
 {
@@ -73,6 +75,6 @@ frysk::sys::Child::child (frysk::sys::Redirect* redirect,
     ::_exit (0);
   default:
     redirect->close ();
-    return pid;
+    return frysk::sys::ProcessIdentifierFactory::create(pid);
   }
 }
diff --git a/frysk-sys/frysk/sys/cni/Daemon.cxx b/frysk-sys/frysk/sys/cni/Daemon.cxx
index 6d1b547..f4b5d60 100644
--- a/frysk-sys/frysk/sys/cni/Daemon.cxx
+++ b/frysk-sys/frysk/sys/cni/Daemon.cxx
@@ -49,11 +49,13 @@
 
 #include "frysk/sys/cni/Errno.hxx"
 #include "frysk/sys/ProcessIdentifier.h"
+#include "frysk/sys/ProcessIdentifierFactory.h"
+#include "frysk/sys/ProcessIdentifierDecorator.h"
 #include "frysk/sys/Daemon.h"
 #include "frysk/sys/Redirect.h"
 #include "frysk/sys/Execute.h"
 
-jint
+frysk::sys::ProcessIdentifier*
 frysk::sys::Daemon::daemon (frysk::sys::Redirect* redirect,
 			    frysk::sys::Execute* exec)
 {
@@ -99,6 +101,6 @@ frysk::sys::Daemon::daemon (frysk::sys::Redirect* redirect,
       throwErrno (wait_errno, "waitpid", "process %d", v);
     // printf ("v %d pid %d\n", v, pid);
     redirect->close ();
-    return pid;
+    return frysk::sys::ProcessIdentifierFactory::create(pid);
   }
 }
diff --git a/frysk-sys/frysk/testbed/ChangeLog b/frysk-sys/frysk/testbed/ChangeLog
index 5421b87..b8df3fb 100644
--- a/frysk-sys/frysk/testbed/ChangeLog
+++ b/frysk-sys/frysk/testbed/ChangeLog
@@ -1,3 +1,7 @@
+2008-01-31  Andrew Cagney  <cagney@redhat.com>
+
+	* TearDownProcess.java: Use ProcessIdentifierFactory.
+
 2008-01-25  Andrew Cagney  <cagney@redhat.com>
 
 	* TearDownExpect.java: Extend Expect.
diff --git a/frysk-sys/frysk/testbed/TearDownProcess.java b/frysk-sys/frysk/testbed/TearDownProcess.java
index 33a73f3..f630a3a 100644
--- a/frysk-sys/frysk/testbed/TearDownProcess.java
+++ b/frysk-sys/frysk/testbed/TearDownProcess.java
@@ -40,6 +40,7 @@
 
 package frysk.testbed;
 
+import frysk.sys.ProcessIdentifierFactory;
 import frysk.junit.TestCase;
 import java.util.logging.Logger;
 import java.util.logging.Level;
@@ -116,9 +117,8 @@ public class TearDownProcess
      * Add the pid to the set of pidsToKillDuringTearDown that should
      * be killed off during tearDown.
      */
-    public static void add (int pid)
-    {
-	add (new ProcessIdentifier (pid));
+    public static void add(int pid) {
+	add(ProcessIdentifierFactory.createFIXME(pid));
     }
 
     /**
@@ -129,9 +129,8 @@ public class TearDownProcess
     {
 	return pidsToKillDuringTearDown.contains (pid);
     }
-    public static boolean contains (int pid)
-    {


hooks/post-receive
--
frysk system monitor/debugger


                 reply	other threads:[~2008-01-31 20:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080131202959.3124.qmail@sourceware.org \
    --to=cagney@sourceware.org \
    --cc=frysk-cvs@sourceware.org \
    --cc=frysk@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).