next up previous contents
Next: 4.1.7 Dumping event tables Up: 4.1.6 Frozen events Previous: 4.1.6 Frozen events

4.1.6.1 Freezing event tables

To freeze an event table we freeze each event in turn. Unlike in other containers, resource units are frozen eagerly, not lazily. The reason is that we expect few resource units and doing a lazy freeze/melt would degrade performance.

NOTE: XXX implement them all.

We need these methods to support freeze,

<Other protected methods of off_EventTbl. >+= (<-U) [<-D->]
// These are for freeze:
// Freeze dynamic resource state at curbuf in buf with avail bytes. 
virtual err_t freeze_state(char *buf, char *&curbuf, size_t &avail,
                           char *&curto, size_t &toavail,
                           const off_prtl_id_t &frozen_domain)
{
  // XXX complete this.

  (void)buf; (void)curbuf; (void)avail; (void)curto; (void)toavail;
  (void)frozen_domain;
  return ENOSYS;
}

// Copy static resource state in curbuf with toavail bytes. 
virtual err_t copy_state(char *&curto, size_t &toavail) const 
{
  (void)curto; (void)toavail;
  return ENOSYS;
}

as well as these others to support melt:

<Other protected methods of off_EventTbl. >+= (<-U) [<-D]
// These are for melt:
// Does resource cleanup. No external resource should be used after 
// return. 
virtual err_t cleanup(void)
{
  return ENOSYS;
}
// Restores the static state from a user supplied buffer. 
virtual err_t restore_state(char *&buf, size_t &bsize)
{
  (void)buf; (void)bsize;
  return ENOSYS;
}
// Restores dynamic resource state. 
virtual err_t melt_state(char *&buf, size_t &bsize, char *&from, size_t &size,
                         const off_prtl_id_t &melted_domain)
{
  (void)buf; (void)bsize; (void)from; (void)size; (void)melted_domain;
  return ENOSYS;
}

\subsubsection{Freezing events}

We need to implement only these methods:

<Other protected methods of off_Trap. >+= (<-U) [<-D]
// Copy static resource state in curbuf with toavail bytes. 
virtual err_t copy_state(char *&curto, size_t &toavail) const;

// Restores the static state from a user supplied buffer. 
virtual err_t restore_state(char *&buf, size_t &bsize);
// Restores dynamic resource state. 

And also for interrupts.

<Other protected methods of off_Irq. >+= (<-U) [<-D]
// Copy static resource state in curbuf with toavail bytes. 
virtual err_t copy_state(char *&curto, size_t &toavail) const;

// Restores the static state from a user supplied buffer. 
virtual err_t restore_state(char *&buf, size_t &bsize);
// Restores dynamic resource state. 

<off_Trap::copy_state implementation. >= (U->)
// Copy static resource state in curbuf with toavail bytes. 
err_t off_Trap::copy_state(char *&curto, size_t &toavail) const
{
  assert(valid());
  if (curto){
    if (toavail<sizeof(*this))
      return ENOSPC;
    *(off_Trap*)curto = *this;
    assert(((off_Trap*)curto)->valid());
    curto += sizeof(*this);
    toavail-=sizeof(*this);
  }
  return EOK;
}

Note how in this one we take care that the reference to the container is not affected by the state restore.

<off_Trap::restore_state implementation. >= (U->)
// Restores the static state from a user supplied buffer. 
err_t off_Trap::restore_state(char *&buf, size_t &bsize)
{
  off_Trap *other=(off_Trap*)buf;
  assert(valid());
  if (buf){
    off_TrapTbl *bank=(off_TrapTbl*)get_container();
    if (bsize < sizeof(*this)){
      return EINVAL;
    }
    assert(other->valid());
    *this=*other;
    set_container(bank);
    buf+=sizeof(*this);
    bsize-=sizeof(*this);
  }    
  return EOK;
}

<off_Irq::copy_state implementation. >= (U->)
// Copy static resource state in curbuf with toavail bytes. 
err_t off_Irq::copy_state(char *&curto, size_t &toavail) const
{
  assert(valid());
  if (curto){
    if (toavail<sizeof(*this))
      return ENOSPC;
    *(off_Irq*)curto = *this;
    assert(((off_Irq*)curto)->valid());
    curto += sizeof(*this);
    toavail-=sizeof(*this);
  }
  return EOK;
}

<off_Irq::restore_state implementation. >= (U->)
// Restores the static state from a user supplied buffer. 
err_t off_Irq::restore_state(char *&buf, size_t &bsize)
{
  off_Irq *other=(off_Irq*)buf;
  assert(valid());
  if (buf){
    off_IntTbl *bank=(off_IntTbl*)get_container();
    if (bsize < sizeof(*this)){
      return EINVAL;
    }
    assert(other->valid());
    *this=*other;
    set_container(bank);
    buf+=sizeof(*this);
    bsize-=sizeof(*this);
  }    
  return EOK;
}



Francisco J. Ballesteros
1998-05-25