Anonymous user
Singleton: Difference between revisions
m
→{{header|Caché ObjectScript}}
Line 332:
Quit $$$NULLOREF
}
If pConcurrency = -1 Set pConcurrency = $
// acquire lock for global singleton object
Set lockTO = $ZUtil(115,4), lockOK = 1
If
Lock +^CacheTempUser("Singleton", ..%ClassName(1))#"S":lockTO Set lockOK = $Test
} ElseIf pConcurrency = 4 {
Lock +^CacheTempUser("Singleton", ..%ClassName(1)):lockTO Set lockOK = $Test
}
If 'lockOK {
Line 380 ⟶ 378:
Method Set() As %Status
{
// check for version change
// serialise local singleton object if changes have occurred▼
Set oRef0 = ..%Open(oId0,, .sc)
If $$$ISERR(sc) Quit sc
If oRef0.Version = ..Version {
Set ..Version = ..Version + 1
} Else {
} ▼
Set sc = ..%GetSwizzleObject(,.oId) If $$$ISERR(sc) Quit sc
//
Lock +^CacheTempUser("Singleton", ..%ClassName(1)):lockTO
▲ Set lockTO = $ZUtil(115,4)
▲ If '$Test Quit $$$ERROR($$$LockFailedToAcquireExclusive, ..%ClassName(1))
▲ }
// update global singleton object and release lock
Set ^CacheTempUser("Singleton", ..%ClassName(1)) = oId
Lock -^CacheTempUser("Singleton", ..%ClassName(1))
▲ Lock -^CacheTempUser("Singleton", ..%ClassName(1))
▲ }
Quit $$$OK
}
Line 421 ⟶ 424:
Property Concurrency As %Integer [ Private, Transient ];
Property Version As %Integer [ Private ];
}
|