@@ -109,7 +109,7 @@ static int shm_addrs_size; /* length of the allocated shm_addrs array */
109109static long pagesize ;
110110
111111static NTSTATUS create_esync ( enum esync_type type , HANDLE * handle ,
112- ACCESS_MASK access , const OBJECT_ATTRIBUTES * attr , int initval );
112+ ACCESS_MASK access , const OBJECT_ATTRIBUTES * attr , int initval , int max );
113113
114114void esync_init (void )
115115{
@@ -121,7 +121,7 @@ void esync_init(void)
121121 HANDLE handle ;
122122 NTSTATUS ret ;
123123
124- ret = create_esync ( 0 , & handle , 0 , NULL , 0 );
124+ ret = create_esync ( 0 , & handle , 0 , NULL , 0 , 0 );
125125 if (ret != STATUS_NOT_IMPLEMENTED )
126126 {
127127 ERR ("Server is running with WINEESYNC but this process is not, please enable WINEESYNC or restart wineserver.\n" );
@@ -320,7 +320,7 @@ NTSTATUS esync_close( HANDLE handle )
320320}
321321
322322static NTSTATUS create_esync ( enum esync_type type , HANDLE * handle ,
323- ACCESS_MASK access , const OBJECT_ATTRIBUTES * attr , int initval )
323+ ACCESS_MASK access , const OBJECT_ATTRIBUTES * attr , int initval , int max )
324324{
325325 NTSTATUS ret ;
326326 data_size_t len ;
@@ -340,6 +340,7 @@ static NTSTATUS create_esync( enum esync_type type, HANDLE *handle,
340340 req -> access = access ;
341341 req -> initval = initval ;
342342 req -> type = type ;
343+ req -> max = max ;
343344 wine_server_add_data ( req , objattr , len );
344345 ret = wine_server_call ( req );
345346 if (!ret || ret == STATUS_OBJECT_NAME_EXISTS )
@@ -404,60 +405,21 @@ static NTSTATUS open_esync( enum esync_type type, HANDLE *handle,
404405 return ret ;
405406}
406407
407- RTL_CRITICAL_SECTION shm_init_section ;
408- static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
409- {
410- 0 , 0 , & shm_init_section ,
411- { & critsect_debug .ProcessLocksList , & critsect_debug .ProcessLocksList },
412- 0 , 0 , { (DWORD_PTR )(__FILE__ ": shm_init_section" ) }
413- };
414- RTL_CRITICAL_SECTION shm_init_section = { & critsect_debug , -1 , 0 , 0 , 0 , 0 };
415-
416408NTSTATUS esync_create_semaphore (HANDLE * handle , ACCESS_MASK access ,
417409 const OBJECT_ATTRIBUTES * attr , LONG initial , LONG max )
418410{
419- NTSTATUS ret ;
420-
421411 TRACE ("name %s, initial %d, max %d.\n" ,
422412 attr ? debugstr_us (attr -> ObjectName ) : "<no name>" , initial , max );
423413
424- /* We need this lock to protect against a potential (though unlikely) race:
425- * if a different process tries to open a named object and manages to use
426- * it between the time we get back from the server and the time we
427- * initialize the shared memory, it'll have uninitialized values for the
428- * object's state. That requires us to be REALLY slow, but we're not taking
429- * any chances. Synchronize on the CS here so that we're sure to be ready
430- * before anyone else can open the object. */
431- RtlEnterCriticalSection ( & shm_init_section );
432-
433- ret = create_esync ( ESYNC_SEMAPHORE , handle , access , attr , initial );
434- if (!ret )
435- {
436- /* Initialize the shared memory portion.
437- * Note we store max here (even though we don't need to) just to keep
438- * it the same size as the mutex's shm portion. */
439- struct esync * obj = get_cached_object ( * handle );
440- struct semaphore * semaphore = obj -> shm ;
441- semaphore -> max = max ;
442- semaphore -> count = initial ;
443- }
444-
445- RtlLeaveCriticalSection ( & shm_init_section );
446-
447- return ret ;
414+ return create_esync ( ESYNC_SEMAPHORE , handle , access , attr , initial , max );
448415}
449416
450417NTSTATUS esync_open_semaphore ( HANDLE * handle , ACCESS_MASK access ,
451418 const OBJECT_ATTRIBUTES * attr )
452419{
453- NTSTATUS ret ;
454-
455420 TRACE ("name %s.\n" , debugstr_us (attr -> ObjectName ));
456421
457- RtlEnterCriticalSection ( & shm_init_section );
458- ret = open_esync ( ESYNC_SEMAPHORE , handle , access , attr );
459- RtlLeaveCriticalSection ( & shm_init_section );
460- return ret ;
422+ return open_esync ( ESYNC_SEMAPHORE , handle , access , attr );
461423}
462424
463425NTSTATUS esync_release_semaphore ( HANDLE handle , ULONG count , ULONG * prev )
@@ -523,41 +485,20 @@ NTSTATUS esync_create_event( HANDLE *handle, ACCESS_MASK access,
523485 const OBJECT_ATTRIBUTES * attr , EVENT_TYPE event_type , BOOLEAN initial )
524486{
525487 enum esync_type type = (event_type == SynchronizationEvent ? ESYNC_AUTO_EVENT : ESYNC_MANUAL_EVENT );
526- NTSTATUS ret ;
527488
528489 TRACE ("name %s, %s-reset, initial %d.\n" ,
529490 attr ? debugstr_us (attr -> ObjectName ) : "<no name>" ,
530491 event_type == NotificationEvent ? "manual" : "auto" , initial );
531492
532- RtlEnterCriticalSection ( & shm_init_section );
533-
534- ret = create_esync ( type , handle , access , attr , initial );
535-
536- if (!ret )
537- {
538- /* Initialize the shared memory portion. */
539- struct esync * obj = get_cached_object ( * handle );
540- struct event * event = obj -> shm ;
541- event -> signaled = initial ;
542- event -> locked = 0 ;
543- }
544-
545- RtlLeaveCriticalSection ( & shm_init_section );
546-
547- return ret ;
493+ return create_esync ( type , handle , access , attr , initial , 0 );
548494}
549495
550496NTSTATUS esync_open_event ( HANDLE * handle , ACCESS_MASK access ,
551497 const OBJECT_ATTRIBUTES * attr )
552498{
553- NTSTATUS ret ;
554-
555499 TRACE ("name %s.\n" , debugstr_us (attr -> ObjectName ));
556500
557- RtlEnterCriticalSection ( & shm_init_section );
558- ret = open_esync ( ESYNC_AUTO_EVENT , handle , access , attr ); /* doesn't matter which */
559- RtlLeaveCriticalSection ( & shm_init_section );
560- return ret ;
501+ return open_esync ( ESYNC_AUTO_EVENT , handle , access , attr ); /* doesn't matter which */
561502}
562503
563504static inline void small_pause (void )
@@ -740,39 +681,18 @@ NTSTATUS esync_query_event( HANDLE handle, EVENT_INFORMATION_CLASS class,
740681NTSTATUS esync_create_mutex ( HANDLE * handle , ACCESS_MASK access ,
741682 const OBJECT_ATTRIBUTES * attr , BOOLEAN initial )
742683{
743- NTSTATUS ret ;
744-
745684 TRACE ("name %s, initial %d.\n" ,
746685 attr ? debugstr_us (attr -> ObjectName ) : "<no name>" , initial );
747686
748- RtlEnterCriticalSection ( & shm_init_section );
749-
750- ret = create_esync ( ESYNC_MUTEX , handle , access , attr , initial ? 0 : 1 );
751- if (!ret )
752- {
753- /* Initialize the shared memory portion. */
754- struct esync * obj = get_cached_object ( * handle );
755- struct mutex * mutex = obj -> shm ;
756- mutex -> tid = initial ? GetCurrentThreadId () : 0 ;
757- mutex -> count = initial ? 1 : 0 ;
758- }
759-
760- RtlLeaveCriticalSection ( & shm_init_section );
761-
762- return ret ;
687+ return create_esync ( ESYNC_MUTEX , handle , access , attr , initial ? 0 : 1 , 0 );
763688}
764689
765690NTSTATUS esync_open_mutex ( HANDLE * handle , ACCESS_MASK access ,
766691 const OBJECT_ATTRIBUTES * attr )
767692{
768- NTSTATUS ret ;
769-
770693 TRACE ("name %s.\n" , debugstr_us (attr -> ObjectName ));
771694
772- RtlEnterCriticalSection ( & shm_init_section );
773- ret = open_esync ( ESYNC_MUTEX , handle , access , attr );
774- RtlLeaveCriticalSection ( & shm_init_section );
775- return ret ;
695+ return open_esync ( ESYNC_MUTEX , handle , access , attr );
776696}
777697
778698NTSTATUS esync_release_mutex ( HANDLE * handle , LONG * prev )
0 commit comments