Commit 72fc2cea authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Use pthread mutexes for uninterrupted sections in the Unix library.

parent ceeb11d2
......@@ -112,15 +112,7 @@ timeout_t server_start_time = 0; /* time of server startup */
sigset_t server_block_set; /* signals to block during server calls */
static int fd_socket = -1; /* socket to exchange file descriptors with the server */
static pid_t server_pid;
static RTL_CRITICAL_SECTION fd_cache_section;
static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
{
0, 0, &fd_cache_section,
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": fd_cache_section") }
};
static RTL_CRITICAL_SECTION fd_cache_section = { &critsect_debug, -1, 0, 0, 0, 0 };
static pthread_mutex_t fd_cache_mutex = PTHREAD_MUTEX_INITIALIZER;
/* atomically exchange a 64-bit value */
static inline LONG64 interlocked_xchg64( LONG64 *dest, LONG64 val )
......@@ -303,19 +295,19 @@ unsigned int CDECL wine_server_call( void *req_ptr )
/***********************************************************************
* server_enter_uninterrupted_section
*/
void server_enter_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset_t *sigset )
void server_enter_uninterrupted_section( pthread_mutex_t *mutex, sigset_t *sigset )
{
pthread_sigmask( SIG_BLOCK, &server_block_set, sigset );
RtlEnterCriticalSection( cs );
pthread_mutex_lock( mutex );
}
/***********************************************************************
* server_leave_uninterrupted_section
*/
void server_leave_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset_t *sigset )
void server_leave_uninterrupted_section( pthread_mutex_t *mutex, sigset_t *sigset )
{
RtlLeaveCriticalSection( cs );
pthread_mutex_unlock( mutex );
pthread_sigmask( SIG_SETMASK, sigset, NULL );
}
......@@ -1002,7 +994,7 @@ int server_get_unix_fd( HANDLE handle, unsigned int wanted_access, int *unix_fd,
ret = get_cached_fd( handle, &fd, type, &access, options );
if (ret != STATUS_INVALID_HANDLE) goto done;
server_enter_uninterrupted_section( &fd_cache_section, &sigset );
server_enter_uninterrupted_section( &fd_cache_mutex, &sigset );
ret = get_cached_fd( handle, &fd, type, &access, options );
if (ret == STATUS_INVALID_HANDLE)
{
......@@ -1030,7 +1022,7 @@ int server_get_unix_fd( HANDLE handle, unsigned int wanted_access, int *unix_fd,
}
SERVER_END_REQ;
}
server_leave_uninterrupted_section( &fd_cache_section, &sigset );
server_leave_uninterrupted_section( &fd_cache_mutex, &sigset );
done:
if (!ret && ((access & wanted_access) != wanted_access))
......
......@@ -1934,16 +1934,7 @@ struct ldt_copy
} __wine_ldt_copy;
static WORD gdt_fs_sel;
static RTL_CRITICAL_SECTION ldt_section;
static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
{
0, 0, &ldt_section,
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": ldt_section") }
};
static RTL_CRITICAL_SECTION ldt_section = { &critsect_debug, -1, 0, 0, 0, 0 };
static pthread_mutex_t ldt_mutex = PTHREAD_MUTEX_INITIALIZER;
static const LDT_ENTRY null_entry;
static inline void *ldt_get_base( LDT_ENTRY ent )
......@@ -2110,10 +2101,10 @@ NTSTATUS WINAPI NtSetLdtEntries( ULONG sel1, LDT_ENTRY entry1, ULONG sel2, LDT_E
if (sel1 && (sel1 >> 3) < first_ldt_entry) return STATUS_INVALID_LDT_DESCRIPTOR;
if (sel2 && (sel2 >> 3) < first_ldt_entry) return STATUS_INVALID_LDT_DESCRIPTOR;
server_enter_uninterrupted_section( &ldt_section, &sigset );
server_enter_uninterrupted_section( &ldt_mutex, &sigset );
if (sel1) ldt_set_entry( sel1, entry1 );
if (sel2) ldt_set_entry( sel2, entry2 );
server_leave_uninterrupted_section( &ldt_section, &sigset );
server_leave_uninterrupted_section( &ldt_mutex, &sigset );
return STATUS_SUCCESS;
}
......@@ -2165,14 +2156,14 @@ NTSTATUS signal_alloc_thread( TEB *teb )
}
else
{
server_enter_uninterrupted_section( &ldt_section, &sigset );
server_enter_uninterrupted_section( &ldt_mutex, &sigset );
for (idx = first_ldt_entry; idx < LDT_SIZE; idx++)
{
if (__wine_ldt_copy.flags[idx]) continue;
ldt_set_entry( (idx << 3) | 7, entry );
break;
}
server_leave_uninterrupted_section( &ldt_section, &sigset );
server_leave_uninterrupted_section( &ldt_mutex, &sigset );
if (idx == LDT_SIZE) return STATUS_TOO_MANY_THREADS;
}
thread_data->fs = (idx << 3) | 7;
......@@ -2193,9 +2184,9 @@ void signal_free_thread( TEB *teb )
if (gdt_fs_sel) return;
server_enter_uninterrupted_section( &ldt_section, &sigset );
server_enter_uninterrupted_section( &ldt_mutex, &sigset );
__wine_ldt_copy.flags[thread_data->fs >> 3] = 0;
server_leave_uninterrupted_section( &ldt_section, &sigset );
server_leave_uninterrupted_section( &ldt_mutex, &sigset );
}
......
......@@ -21,6 +21,7 @@
#ifndef __NTDLL_UNIX_PRIVATE_H
#define __NTDLL_UNIX_PRIVATE_H
#include <pthread.h>
#include "unixlib.h"
#include "wine/list.h"
......@@ -162,8 +163,8 @@ extern void start_server( BOOL debug ) DECLSPEC_HIDDEN;
extern ULONG_PTR get_image_address(void) DECLSPEC_HIDDEN;
extern unsigned int server_call_unlocked( void *req_ptr ) DECLSPEC_HIDDEN;
extern void server_enter_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset_t *sigset ) DECLSPEC_HIDDEN;
extern void server_leave_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset_t *sigset ) DECLSPEC_HIDDEN;
extern void server_enter_uninterrupted_section( pthread_mutex_t *mutex, sigset_t *sigset ) DECLSPEC_HIDDEN;
extern void server_leave_uninterrupted_section( pthread_mutex_t *mutex, sigset_t *sigset ) DECLSPEC_HIDDEN;
extern unsigned int server_select( const select_op_t *select_op, data_size_t size, UINT flags,
timeout_t abs_timeout, CONTEXT *context, RTL_CRITICAL_SECTION *cs,
user_apc_t *user_apc ) DECLSPEC_HIDDEN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment