Further server optimizations:
- merged request and reply structures
- build requests directly into the buffer to avoid a copy
diff --git a/scheduler/semaphore.c b/scheduler/semaphore.c
index 018606b..890efa8 100644
--- a/scheduler/semaphore.c
+++ b/scheduler/semaphore.c
@@ -16,8 +16,7 @@
*/
HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name )
{
- struct create_semaphore_request req;
- struct create_semaphore_reply reply;
+ struct create_semaphore_request *req = get_req_buffer();
/* Check parameters */
@@ -27,16 +26,14 @@
return 0;
}
- if (!name) name = "";
- req.initial = (unsigned int)initial;
- req.max = (unsigned int)max;
- req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
-
- CLIENT_SendRequest( REQ_CREATE_SEMAPHORE, -1, 2, &req, sizeof(req), name, strlen(name)+1 );
+ req->initial = (unsigned int)initial;
+ req->max = (unsigned int)max;
+ req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
+ lstrcpynA( req->name, name ? name : "", server_remaining(req->name) );
SetLastError(0);
- CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
- if (reply.handle == -1) return 0;
- return reply.handle;
+ server_call( REQ_CREATE_SEMAPHORE );
+ if (req->handle == -1) return 0;
+ return req->handle;
}
@@ -58,16 +55,14 @@
*/
HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name )
{
- struct open_semaphore_request req;
- struct open_semaphore_reply reply;
- int len = name ? strlen(name) + 1 : 0;
+ struct open_semaphore_request *req = get_req_buffer();
- req.access = access;
- req.inherit = inherit;
- CLIENT_SendRequest( REQ_OPEN_SEMAPHORE, -1, 2, &req, sizeof(req), name, len );
- CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
- if (reply.handle == -1) return 0; /* must return 0 on failure, not -1 */
- return reply.handle;
+ req->access = access;
+ req->inherit = inherit;
+ lstrcpynA( req->name, name ? name : "", server_remaining(req->name) );
+ server_call( REQ_OPEN_SEMAPHORE );
+ if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */
+ return req->handle;
}
@@ -88,18 +83,16 @@
*/
BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous )
{
- struct release_semaphore_request req;
- struct release_semaphore_reply reply;
+ struct release_semaphore_request *req = get_req_buffer();
if (count < 0)
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
- req.handle = handle;
- req.count = (unsigned int)count;
- CLIENT_SendRequest( REQ_RELEASE_SEMAPHORE, -1, 1, &req, sizeof(req) );
- if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE;
- if (previous) *previous = reply.prev_count;
+ req->handle = handle;
+ req->count = (unsigned int)count;
+ if (server_call( REQ_RELEASE_SEMAPHORE )) return FALSE;
+ if (previous) *previous = req->prev_count;
return TRUE;
}