Ploxi
Ploxi
CC#
Created by Ploxi on 5/30/2024 in #help
asp - Calling another api endpoint
I mean parsing the headers is ez but how do i find the endpoint for the route
6 replies
CC#
Created by Ploxi on 5/30/2024 in #help
asp - Calling another api endpoint
@WEIRD FLEX i mean i have the raw http request as a stream and want to execute the request it represents
6 replies
CC#
Created by Ploxi on 4/29/2024 in #help
Best Practices for Instantiating Objects in C# Source Generators
So basically the sourcegen is generating methods that call the existing ones in the service and needs a way of newing up the args in a way that is kinda interceptable
7 replies
CC#
Created by Ploxi on 4/29/2024 in #help
Best Practices for Instantiating Objects in C# Source Generators
Ok just reread the issue and its really bad described - sry 😅
7 replies
CC#
Created by Ploxi on 4/29/2024 in #help
Best Practices for Instantiating Objects in C# Source Generators
Depends on the option. The delegate sln would create a delegate in the generated source and the user could overwrite the value in the ctor. In the attrib sln, the sourcegen would simply use new() unless a method exists in the user code that is attributed
7 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
Like so?
public void AddThreadSafe(string key, TStatus value)
{
while (true)
{
var currentMap = Volatile.Read(ref _mappings);

var newMap = new Dictionary<string, TStatus>(currentMap, StringComparer.OrdinalIgnoreCase);

// true, if another thread added the value already
var hasAdded = !newMap.TryAdd(key, value);
if (hasAdded || Interlocked.CompareExchange(ref _mappings, newMap, currentMap) == currentMap)
{
break;
}
}
}
public void AddThreadSafe(string key, TStatus value)
{
while (true)
{
var currentMap = Volatile.Read(ref _mappings);

var newMap = new Dictionary<string, TStatus>(currentMap, StringComparer.OrdinalIgnoreCase);

// true, if another thread added the value already
var hasAdded = !newMap.TryAdd(key, value);
if (hasAdded || Interlocked.CompareExchange(ref _mappings, newMap, currentMap) == currentMap)
{
break;
}
}
}
53 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
Do i only need volatile.read in the threadsafe add?
53 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
I will extract the map parts out into a nonstatic class and test that one
53 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
Succeeds
53 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
thats why Obsolete: Scream at them not to use it 😄
53 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
EditorBrowseable is so useless when the caller is in the same project
53 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
#region UnitTestCode
[Obsolete("Do not use, only for test")]
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
internal static Dictionary<string, UpdateQueueStatus> GetMappings() => _mappings;


#endregion
#region UnitTestCode
[Obsolete("Do not use, only for test")]
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
internal static Dictionary<string, UpdateQueueStatus> GetMappings() => _mappings;


#endregion
53 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
yes
53 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
The static initializer initializes all known states. There are currently no unknowns. Unknowns (aka Parse adds to the map) will only happen when the caller is "newer", so i dont have to touch every program when implementing a new state
53 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
57 tests passed
53 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
like every state should already be known
53 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
cause parsing when the _mappings dont have an entry is the super unhappy path
53 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
but i wont have those
53 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
xD
53 replies
CC#
Created by Ploxi on 2/7/2024 in #help
Threadsafety and Interlocked.CompareExchange
thank you!
53 replies