You've already forked wine-staging
mirror of
https://gitlab.winehq.org/wine/wine-staging.git
synced 2025-04-13 14:42:51 -07:00
Move 12-FD_Cache to ntdll-FD_Cache.
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
From d1fa972e77cab4a5529631371dff0c80a04a8ad5 Mon Sep 17 00:00:00 2001
|
||||
From: Sebastian Lackner <sebastian@fds-team.de>
|
||||
Date: Sat, 31 May 2014 21:02:04 +0200
|
||||
Subject: ntdll: Use lockfree implementation for get_cached_fd.
|
||||
|
||||
---
|
||||
dlls/ntdll/server.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++----
|
||||
1 file changed, 46 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/dlls/ntdll/server.c b/dlls/ntdll/server.c
|
||||
index f3c6b38..75988ec 100644
|
||||
--- a/dlls/ntdll/server.c
|
||||
+++ b/dlls/ntdll/server.c
|
||||
@@ -73,6 +73,8 @@
|
||||
|
||||
#include "ntstatus.h"
|
||||
#define WIN32_NO_STATUS
|
||||
+#include "windef.h"
|
||||
+#include "winnt.h"
|
||||
#include "wine/library.h"
|
||||
#include "wine/server.h"
|
||||
#include "wine/debug.h"
|
||||
@@ -795,6 +797,10 @@ struct fd_cache_entry
|
||||
unsigned int options : 24;
|
||||
};
|
||||
|
||||
+#if !defined(__powerpc__)
|
||||
+C_ASSERT( sizeof(struct fd_cache_entry) == sizeof(LONG64) );
|
||||
+#endif
|
||||
+
|
||||
#define FD_CACHE_BLOCK_SIZE (65536 / sizeof(struct fd_cache_entry))
|
||||
#define FD_CACHE_ENTRIES 128
|
||||
|
||||
@@ -818,7 +824,6 @@ static BOOL add_fd_to_cache( HANDLE handle, int fd, enum server_fd_type type,
|
||||
unsigned int access, unsigned int options )
|
||||
{
|
||||
unsigned int entry, idx = handle_to_index( handle, &entry );
|
||||
- int prev_fd;
|
||||
|
||||
if (entry >= FD_CACHE_ENTRIES)
|
||||
{
|
||||
@@ -837,12 +842,31 @@ static BOOL add_fd_to_cache( HANDLE handle, int fd, enum server_fd_type type,
|
||||
fd_cache[entry] = ptr;
|
||||
}
|
||||
}
|
||||
+
|
||||
+#if defined(__powerpc__)
|
||||
/* store fd+1 so that 0 can be used as the unset value */
|
||||
- prev_fd = interlocked_xchg( &fd_cache[entry][idx].fd, fd + 1 ) - 1;
|
||||
+ fd = interlocked_xchg( &fd_cache[entry][idx].fd, fd + 1 );
|
||||
+ assert( !fd );
|
||||
fd_cache[entry][idx].type = type;
|
||||
fd_cache[entry][idx].access = access;
|
||||
fd_cache[entry][idx].options = options;
|
||||
- if (prev_fd != -1) close( prev_fd );
|
||||
+#else
|
||||
+ {
|
||||
+ struct fd_cache_entry old_cache, new_cache;
|
||||
+
|
||||
+ /* store fd+1 so that 0 can be used as the unset value */
|
||||
+ new_cache.fd = fd + 1;
|
||||
+ new_cache.type = type;
|
||||
+ new_cache.access = access;
|
||||
+ new_cache.options = options;
|
||||
+
|
||||
+ /* we're holding the lock and have checked the content before, so the cache always contains the latest value */
|
||||
+ old_cache = fd_cache[entry][idx];
|
||||
+ assert( !old_cache.fd );
|
||||
+ *(LONG64 *)&new_cache = interlocked_cmpxchg64( (LONG64 *)&fd_cache[entry][idx], *(LONG64 *)&new_cache, *(LONG64 *)&old_cache );
|
||||
+ assert( !memcmp(&old_cache, &new_cache, sizeof(struct fd_cache_entry)) );
|
||||
+ }
|
||||
+#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -850,7 +874,7 @@ static BOOL add_fd_to_cache( HANDLE handle, int fd, enum server_fd_type type,
|
||||
/***********************************************************************
|
||||
* get_cached_fd
|
||||
*
|
||||
- * Caller must hold fd_cache_section.
|
||||
+ * Caller must hold fd_cache_section on PowerPC processor architecture.
|
||||
*/
|
||||
static inline int get_cached_fd( HANDLE handle, enum server_fd_type *type,
|
||||
unsigned int *access, unsigned int *options )
|
||||
@@ -860,10 +884,19 @@ static inline int get_cached_fd( HANDLE handle, enum server_fd_type *type,
|
||||
|
||||
if (entry < FD_CACHE_ENTRIES && fd_cache[entry])
|
||||
{
|
||||
+ #if defined(__powerpc__)
|
||||
fd = fd_cache[entry][idx].fd - 1;
|
||||
if (type) *type = fd_cache[entry][idx].type;
|
||||
if (access) *access = fd_cache[entry][idx].access;
|
||||
if (options) *options = fd_cache[entry][idx].options;
|
||||
+ #else
|
||||
+ struct fd_cache_entry cache;
|
||||
+ *(LONG64 *)&cache = interlocked_cmpxchg64( (LONG64 *)&fd_cache[entry][idx], 0, 0 );
|
||||
+ fd = cache.fd - 1;
|
||||
+ if (type) *type = cache.type;
|
||||
+ if (access) *access = cache.access;
|
||||
+ if (options) *options = cache.options;
|
||||
+ #endif
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
@@ -901,6 +934,11 @@ int server_get_unix_fd( HANDLE handle, unsigned int wanted_access, int *unix_fd,
|
||||
*needs_close = 0;
|
||||
wanted_access &= FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA;
|
||||
|
||||
+#if !defined(__powerpc__)
|
||||
+ fd = get_cached_fd( handle, type, &access, options );
|
||||
+ if (fd != -1) goto done_unlocked;
|
||||
+#endif
|
||||
+
|
||||
server_enter_uninterrupted_section( &fd_cache_section, &sigset );
|
||||
|
||||
fd = get_cached_fd( handle, type, &access, options );
|
||||
@@ -928,6 +966,10 @@ int server_get_unix_fd( HANDLE handle, unsigned int wanted_access, int *unix_fd,
|
||||
|
||||
done:
|
||||
server_leave_uninterrupted_section( &fd_cache_section, &sigset );
|
||||
+
|
||||
+#if !defined(__powerpc__)
|
||||
+done_unlocked:
|
||||
+#endif
|
||||
if (!ret && ((access & wanted_access) != wanted_access))
|
||||
{
|
||||
ret = STATUS_ACCESS_DENIED;
|
||||
--
|
||||
1.7.9.5
|
||||
|
4
patches/ntdll-FD_Cache/definition
Normal file
4
patches/ntdll-FD_Cache/definition
Normal file
@@ -0,0 +1,4 @@
|
||||
Author: Sebastian Lackner
|
||||
Subject: Use lockfree implementation for get_cached_fd.
|
||||
Revision: 4
|
||||
Fixes: Lockfree algorithm for filedescriptor cache (improves file access speed)
|
Reference in New Issue
Block a user