Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /sml/trunk/src/MLRISC/library/transaction-log.sml
ViewVC logotype

View of /sml/trunk/src/MLRISC/library/transaction-log.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 245 - (download) (annotate)
Sat Apr 17 18:47:12 1999 UTC (20 years, 5 months ago) by monnier
Original Path: sml/branches/SMLNJ/src/MLRISC/library/transaction-log.sml
File size: 1121 byte(s)
version 110.16
structure TransactionLog : TRANSACTION_LOG =
struct
   exception TransactionLog

   type version    = int
   val version     = ref 0
   val log         = ref [] : (version * { rollback : version -> unit,
					   commit   : version -> unit
					 } list ref) list ref
   fun add_object f =
       case !log of
	  (ver,trail)::_ => trail := f :: !trail 
       |  []             => raise TransactionLog

   fun init() = (version := 0; log := [])

   fun begin () =
   let val new_ver = !version+1
   in  version := new_ver;
       log := (new_ver,ref []) :: !log
   end

   fun abort () =
   let val old_ver = !version - 1
   in  case !log of
	  (_,ref trail)::rest => 
	     (app (fn {rollback,...} => rollback old_ver) trail;
              version := old_ver;
	      log := rest) 
       |  []                  => raise TransactionLog
   end

   fun commit () =
   let val old_ver = !version - 1
   in  case !log of
	  (_,ref trail)::rest => 
	     (app (fn {commit,...} => commit old_ver) trail;
              version := old_ver;
	      log := rest) 
       |  []      => raise TransactionLog
   end
end

(*
 * $Log$
 *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0