22using System ;
33using System . Collections . Generic ;
44using System . IO ;
5- using System . Threading ;
6- #if NETFRAMEWORK
75using System . Security . AccessControl ;
86using System . Security . Principal ;
9- #endif
7+ using System . Threading ;
108
119namespace LiteDB
1210{
@@ -25,24 +23,30 @@ public SharedEngine(EngineSettings settings)
2523
2624 try
2725 {
28- #if NETFRAMEWORK
29- var allowEveryoneRule = new MutexAccessRule ( new SecurityIdentifier ( WellKnownSidType . WorldSid , null ) ,
30- MutexRights . FullControl , AccessControlType . Allow ) ;
31-
32- var securitySettings = new MutexSecurity ( ) ;
33- securitySettings . AddAccessRule ( allowEveryoneRule ) ;
34-
35- _mutex = new Mutex ( false , "Global\\ " + name + ".Mutex" , out _ , securitySettings ) ;
36- #else
37- _mutex = new Mutex ( false , "Global\\ " + name + ".Mutex" ) ;
38- #endif
26+ _mutex = CreateMutex ( name ) ;
3927 }
4028 catch ( NotSupportedException ex )
4129 {
4230 throw new PlatformNotSupportedException ( "Shared mode is not supported in platforms that do not implement named mutex." , ex ) ;
4331 }
4432 }
4533
34+ private static Mutex CreateMutex ( string name )
35+ {
36+ if ( ! OperatingSystem . IsWindows ( ) )
37+ {
38+ return new Mutex ( false , "Global\\ " + name + ".Mutex" ) ;
39+ }
40+
41+ var allowEveryoneRule = new MutexAccessRule ( new SecurityIdentifier ( WellKnownSidType . WorldSid , null ) ,
42+ MutexRights . FullControl , AccessControlType . Allow ) ;
43+
44+ var securitySettings = new MutexSecurity ( ) ;
45+ securitySettings . AddAccessRule ( allowEveryoneRule ) ;
46+
47+ return MutexAcl . Create ( false , "Global\\ " + name + ".Mutex" , out _ , securitySettings ) ;
48+ }
49+
4650 /// <summary>
4751 /// Open database in safe mode
4852 /// </summary>
0 commit comments