Skip to content

Commit b5ba379

Browse files
committed
fix 5
1 parent ceb3664 commit b5ba379

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

src/Mapster/TypeAdapterConfig/TypeAdapterConfig.cs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ internal TypeAdapterConfig(bool IsGlobal) : this()
4646
public TypeAdapterConfig()
4747
{
4848
Configure = new(true);
49-
AdaptMutex = new(false);
49+
AdaptMutex = new(true);
5050
Rules = TypeAdapterConfigFactory.RulesTemplate.ToList();
5151
var settings = new TypeAdapterSettings();
5252
ConfigCompile = new ConfigCompileStorage(this);
@@ -66,15 +66,6 @@ public TypeAdapterConfig()
6666
/// <returns></returns>
6767
public TypeAdapterSetter ForType(Type sourceType, Type destinationType)
6868
{
69-
if (ConcurencyEnviroment &&
70-
WaitHandle.WaitAll(new WaitHandle[] { AdaptMutex, Configure }, 0, false))
71-
{
72-
AdaptMutex.Reset();
73-
Configure.Set();
74-
Configure.WaitOne();
75-
}
76-
77-
7869
var key = new TypeTuple(sourceType, destinationType);
7970
var settings = this.GetSettings(key);
8071
return new TypeAdapterSetter(settings, this);
@@ -88,28 +79,17 @@ public TypeAdapterSetter ForType(Type sourceType, Type destinationType)
8879
/// <returns></returns>
8980
public TypeAdapterSetter<TSource, TDestination> ForType<TSource, TDestination>()
9081
{
91-
92-
93-
if (ConcurencyEnviroment &&
94-
WaitHandle.WaitAll(new WaitHandle[] { AdaptMutex, Configure }, 0, false))
95-
{
96-
AdaptMutex.Reset();
97-
Configure.Set();
98-
Configure.WaitOne();
99-
}
100-
10182
var key = new TypeTuple(typeof(TSource), typeof(TDestination));
10283
var settings = this.GetSettings(key);
10384
return new TypeAdapterSetter<TSource, TDestination>(settings, this);
10485
}
10586

10687
public LambdaExpression CreateMapExpression(TypeTuple tuple, MapType mapType)
10788
{
108-
if (ConcurencyEnviroment && WaitHandle.WaitAll(new WaitHandle[] { AdaptMutex, Configure }))
89+
if (ConcurencyEnviroment)
10990
{
110-
AdaptMutex.Set();
111-
Configure.Reset();
112-
AdaptMutex.WaitOne();
91+
Configure.WaitOne(-1);
92+
AdaptMutex.WaitOne(-1, false);
11393
}
11494

11595
var context = new CompileContext(this);

src/Mapster/TypeAdapterConfig/TypeAdapterConfigTSetterExtentions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ public static class TypeAdapterConfigTSetterExtentions
1515
/// <returns></returns>
1616
public static TypeAdapterSetter NewConfig(this ITypeAdapterConfig config, Type sourceType, Type destinationType)
1717
{
18+
if (config.ConcurencyEnviroment)
19+
{
20+
config.AdaptMutex.WaitOne(-1);
21+
config.Configure.WaitOne(-1, false);
22+
}
23+
1824
config.Remove(sourceType, destinationType);
1925
return config.ForType(sourceType, destinationType);
2026
}
@@ -27,6 +33,12 @@ public static TypeAdapterSetter NewConfig(this ITypeAdapterConfig config, Type s
2733
/// <returns></returns>
2834
public static TypeAdapterSetter<TSource, TDestination> NewConfig<TSource, TDestination>(this ITypeAdapterConfig config)
2935
{
36+
if (config.ConcurencyEnviroment)
37+
{
38+
config.AdaptMutex.WaitOne(-1);
39+
config.Configure.WaitOne(-1, false);
40+
}
41+
3042
config.Remove(typeof(TSource), typeof(TDestination));
3143
return config.ForType<TSource, TDestination>();
3244
}

0 commit comments

Comments
 (0)