Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions distsys/archetyperesource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ type ArchetypeResource interface {
// archetype is not running. Close will be called at most once by the MPCal
// Context.
Close() error
// FreshState will be called upon the first use of a resource during the execution of a
// critical section. It provides an ArchetypeResourceState whose purpose is to be used
// to perform operations during the execution of the critical section. A call to FreshState
// creates the expectation that there will be an eventual call to Commit/Abort on the
// resulting ArchetypeResourceState
// Note: FreshState is only meant to be used ONCE during a critical section for a resource
FreshState() ArchetypeResourceState
}

Expand Down Expand Up @@ -50,6 +56,10 @@ type ArchetypeResourceState interface {
// ErrCriticalSectionAborted.
// This makes no sense for a value-like resource, and should be blocked off with ArchetypeResourceLeafMixin in that case.
Index(index tla.TLAValue) (ArchetypeResourceComponent, error)
// ForkState provides a copy to the ArchetypeResourceState such that operations performed on other ArchetypeResourceStates
// with the same parent ArchetypeResource will not cause side effects for the current ArchetypeResourceState.
// ForkState will clone all the parts of a resource whose properties are NOT idempotent. A call to ForkState
// creates the expectation that there will be an eventual call to Commit/Abort on the resulting ArchetypeResourceState
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested rephrasing:

ForkState will clone all the parts of a resource whose properties are NOT idempotent.

ForkState should create a separate copy of any thread-local data held by the original ArcvhetypeResourceState. It is the responsibility of the implementation to ensure side-effects that are not thread-local are synchronized and maintained correctly, given that the two forked versions will be accessed by different goroutines.

ForkState() ArchetypeResourceState
}

Expand Down
34 changes: 0 additions & 34 deletions distsys/mpcalctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,6 @@ type ArchetypeResourceMakerStruct struct {
ConfigureFn func(res ArchetypeResource)
}

//type ForkedResourceNode struct {
// parent *ForkedResourceNode
// resourceStates map[ArchetypeResourceHandle]ArchetypeResource
// path string
//}

//type ForkedResourceTree struct {
// root *ForkedResourceNode
//}

var _ ArchetypeResourceMaker = ArchetypeResourceMakerStruct{}

func (mkStruct ArchetypeResourceMakerStruct) Make() ArchetypeResource {
Expand All @@ -142,9 +132,6 @@ type MPCalContext struct {

// state for ArchetypeInterface.NextFairnessCounter
fairnessCounter FairnessCounter
// Forked resource tree
//forkedResourceTree ForkedResourceTree
//branchScheduler BranchScheduler

jumpTable MPCalJumpTable
procTable MPCalProcTable
Expand Down Expand Up @@ -431,27 +418,6 @@ func (ctx *MPCalContext) ensureArchetypeResource(name string, maker ArchetypeRes
return handle
}

//func (ctx *MPCalContext) getResourceByHandle(handle ArchetypeResourceHandle) ArchetypeResource {
// //node := ctx.forkedResourceTree.root
// //for {
// // if node == nil {
// // panic(fmt.Errorf("could not find resource with name %v", handle))
// // }
// //
// // res, ok := node.resourceStates[handle]
// // if ok {
// // return res
// // }
// // node = node.parent
// //}
//
// //res, ok := ctx.resources[handle]
// //if !ok {
// // panic(fmt.Errorf("could not find resource with name %v", handle))
// //}
// //return res
//}

func (ctx *MPCalContext) getResourceByHandle(handle ArchetypeResourceHandle) ArchetypeResource {
res, ok := ctx.resources[handle]
if !ok {
Expand Down