Skip to content

Commit

Permalink
Add a lock signature
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Sep 4, 2024
1 parent 76e5ed9 commit 92fbec0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ await c.Indexes.CreateOrUpdateAsync(
);
}
);
o.AddRepository<RWLock>("locks");
o.AddRepository<RWLock>("locks", mapSetup: m => m.SetIgnoreExtraElements(true));
o.AddRepository<TrainSegmentPair>(
"train_segment_pairs",
init: c =>
Expand Down
1 change: 1 addition & 0 deletions src/Machine/src/Serval.Machine.Shared/Models/Lock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public record Lock
public required string Id { get; init; }
public DateTime? ExpiresAt { get; init; }
public required string HostId { get; init; }
public string CallingSignature { get; init; } = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,24 @@ public async Task<IAsyncDisposable> WriterLockAsync(
{
lifetime ??= _defaultLifetime;
string lockId = _idGenerator.GenerateId();
StackTrace stackTrace = new StackTrace();
string callingSignature =
$"Filename: {stackTrace.GetFrame(1)?.GetFileName()}, Method: {stackTrace.GetFrame(1)?.GetMethod()?.Name}";

if (!await TryAcquireWriterLock(lockId, lifetime, cancellationToken))
{
await _locks.UpdateAsync(
_id,
u => u.Add(rwl => rwl.WriterQueue, new Lock { Id = lockId, HostId = _hostId }),
u =>
u.Add(
rwl => rwl.WriterQueue,
new Lock
{
Id = lockId,
HostId = _hostId,
CallingSignature = callingSignature
}
),
cancellationToken: cancellationToken
);
try
Expand Down

0 comments on commit 92fbec0

Please sign in to comment.