swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rescheduling


From: Marcus G. Daniels
Subject: Re: rescheduling
Date: 21 Apr 1999 10:44:54 -0700

>>>>> "B" == Benedikt Stefansson <address@hidden> writes:

B> The harder part is if method calls have been scheduled in the
B> future with a specific object as target which now may be dropped
B> before the message call is reached. I have not figured out a clean
B> way to find and drop the specific method call from the schedule,
B> maybe someone else can provide a debugged example.

Here's one way.  

The two main points are:
   1) Use of addRef:withArgument: and notifyFunction
   2) Conservative use of remove: in notifyFunction
   
[apologies to Stevie Wonder]

#import <simtools.h>
#import <activity.h>
#import <objectbase/SwarmObject.h>

@interface TargetObject: SwarmObject
- printTime;
@end

@implementation TargetObject
- printTime
{
  printf (">address@hidden", getCurrentTime ());
  return self;
}
@end

@interface Controller: SwarmObject
{
  id <Schedule> schedule;
  id targetObject;
}
+ createBegin: aZone;
- (id <Schedule>)getSchedule;
- scheduleStuff;
- (void)dropTarget;
- ponderTheUniverse;
- go;
@end

static void
notifyFunction (id obj, id unused, void *arg)
{
  id controller = (id) arg;
  id <Schedule> schedule = [controller getSchedule];
  id action;
  
  do {
    id <MapIndex> index = [schedule begin: scratchZone];

    while ((action = [index next]))
      {
        if ((timeval_t) [index getKey] > getCurrentTime ())
          {
            if ([action respondsTo: M(getTarget)])
              if (obj == [action getTarget])
                {
                  printf (">Removal of address@hidden (target=%s)\n",
                          (timeval_t) [index getKey],
                          [[action getTarget] name]);
                  [schedule remove: action];
                  break;
                }
          }
      }
    [index drop];
  } while (action);
}

@implementation Controller
+ createBegin: aZone
{
  Controller *obj = [super createBegin: aZone];

  obj->targetObject = [TargetObject create: aZone];
  [obj->targetObject addRef: notifyFunction withArgument: obj];

  return obj;
}

- scheduleStuff
{
  schedule = [Schedule create: globalZone];

  [schedule at: 0 createActionTo: targetObject message: M(printTime)];
  [schedule at: 1 createActionTo: self message: M(dropTarget)];
  [schedule at: 2 createActionTo: self message: M(ponderTheUniverse)];
  [schedule at: 3 createActionTo: self message: M(ponderTheUniverse)];
  [schedule at: 4 createActionTo: targetObject message: M(printTime)];
  [schedule at: 5 createActionTo: self message: M(ponderTheUniverse)];
  [schedule at: 6 createActionTo: self message: M(ponderTheUniverse)];
  [schedule at: 7 createActionTo: self message: M(ponderTheUniverse)];
  [schedule at: 8  createActionTo: self message: M(ponderTheUniverse)];
  [schedule at: 9  createActionTo: self message: M(ponderTheUniverse)];
  return self;
}

- ponderTheUniverse
{
  timeval_t t = getCurrentTime ();
  const char *strs[] = {
    "<oink>",
    "<frob>",
    "\nVery superstitious, wash your face and hands",
    "Rid me of the problem, do all that you can",
    "<snort>",
    "Keep me in a daydream, keep me goin' strong",
    "You don't wanna save me, sad is my song",
    "\nWhen you believe in things that you don't understand",
    "Then you suffer",
    "Superstition ain't the way"
  };
  printf ("%s\n", strs[t]);
}

- (id <Schedule>)getSchedule
{
  return schedule;
}

- (void)dropTarget
{
  [targetObject drop];
}

- go
{
  return [[schedule activateIn: nil] run];
}
@end

int 
main (int argc, const char **argv)
{
  id controller;
  
  initSwarmBatch (argc, argv);

  controller = [Controller create: globalZone];

  [controller scheduleStuff];
  [controller go];
  
  return 0;
}

/*
Local Variables:
compile-command: "/opt/egcs/bin/gcc -o s -g -Wno-import 
-L/opt/SUNWtcl/8.0/sun4/lib -R/opt/SUNWtcl/8.0/sun4/lib -L/opt/SDGblt/2.4g/lib 
-R/opt/SDGblt/2.4g/lib -L/opt/SDGlibffi/1.20/lib -R/opt/SDGlibffi/1.20/lib 
-L/opt/SDGswarm/1.4.1/lib -L/opt/SDGzlib/1.1.3/lib -L/usr/local/X11/lib 
-R/usr/local/X11/lib -L/usr/openwin/lib -R/usr/openwin/lib 
-L/opt/SDGhdf5/1.0.1/lib -I/opt/SDGswarm/1.4.1/include s.m -lanalysis 
-lsimtools -lsimtoolsgui -lactivity -ltkobjc -lrandom -lobjectbase  -ldefobj 
-lcollections -lmisc  -ltclobjc -ltk8.0 -ltcl8.0 -lBLT -lsocket -ldl -lnsl 
-L/usr/openwin/lib -lhdf5 -lpng -lz -lXpm -lX11 -lffi -lm -lobjc -lpthread 
-lposix4"
End:
*/

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]