Made server communication faster by using a shared memory block.
A few other optimizations in request processing in the server.
Moved automatically generated request definitions to server.h and
removed include/server/request.h.
diff --git a/server/mutex.c b/server/mutex.c
index 2adaacb..f171d95 100644
--- a/server/mutex.c
+++ b/server/mutex.c
@@ -13,6 +13,7 @@
#include "handle.h"
#include "thread.h"
+#include "request.h"
struct mutex
{
@@ -27,10 +28,10 @@
static void mutex_dump( struct object *obj, int verbose );
static int mutex_signaled( struct object *obj, struct thread *thread );
static int mutex_satisfied( struct object *obj, struct thread *thread );
-static void mutex_destroy( struct object *obj );
static const struct object_ops mutex_ops =
{
+ sizeof(struct mutex),
mutex_dump,
add_queue,
remove_queue,
@@ -40,26 +41,27 @@
no_write_fd,
no_flush,
no_get_file_info,
- mutex_destroy
+ no_destroy
};
-static struct object *create_mutex( const char *name, int owned )
+static struct mutex *create_mutex( const char *name, size_t len, int owned )
{
struct mutex *mutex;
- if (!(mutex = (struct mutex *)create_named_object( name, &mutex_ops, sizeof(*mutex) )))
- return NULL;
- if (GET_ERROR() != ERROR_ALREADY_EXISTS)
+ if ((mutex = create_named_object( &mutex_ops, name, len )))
{
- /* initialize it if it didn't already exist */
- mutex->count = 0;
- mutex->owner = NULL;
- mutex->abandoned = 0;
- mutex->next = mutex->prev = NULL;
- if (owned) mutex_satisfied( &mutex->obj, current );
+ if (get_error() != ERROR_ALREADY_EXISTS)
+ {
+ /* initialize it if it didn't already exist */
+ mutex->count = 0;
+ mutex->owner = NULL;
+ mutex->abandoned = 0;
+ mutex->next = mutex->prev = NULL;
+ if (owned) mutex_satisfied( &mutex->obj, current );
+ }
}
- return &mutex->obj;
+ return mutex;
}
/* release a mutex once the recursion count is 0 */
@@ -75,23 +77,6 @@
wake_up( &mutex->obj, 0 );
}
-static int release_mutex( int handle )
-{
- struct mutex *mutex;
-
- if (!(mutex = (struct mutex *)get_handle_obj( current->process, handle,
- MUTEX_MODIFY_STATE, &mutex_ops )))
- return 0;
- if (!mutex->count || (mutex->owner != current))
- {
- SET_ERROR( ERROR_NOT_OWNER );
- return 0;
- }
- if (!--mutex->count) do_release( mutex, current );
- release_object( mutex );
- return 1;
-}
-
void abandon_mutexes( struct thread *thread )
{
while (thread->mutex)
@@ -138,46 +123,40 @@
return 1;
}
-static void mutex_destroy( struct object *obj )
-{
- struct mutex *mutex = (struct mutex *)obj;
- assert( obj->ops == &mutex_ops );
- free( mutex );
-}
-
/* create a mutex */
DECL_HANDLER(create_mutex)
{
- struct create_mutex_reply reply = { -1 };
- struct object *obj;
- char *name = (char *)data;
- if (!len) name = NULL;
- else CHECK_STRING( "create_mutex", name, len );
+ size_t len = get_req_strlen();
+ struct create_mutex_reply *reply = push_reply_data( current, sizeof(*reply) );
+ struct mutex *mutex;
- obj = create_mutex( name, req->owned );
- if (obj)
+ if ((mutex = create_mutex( get_req_data( len + 1 ), len, req->owned )))
{
- reply.handle = alloc_handle( current->process, obj, MUTEX_ALL_ACCESS, req->inherit );
- release_object( obj );
+ reply->handle = alloc_handle( current->process, mutex, MUTEX_ALL_ACCESS, req->inherit );
+ release_object( mutex );
}
- send_reply( current, -1, 1, &reply, sizeof(reply) );
+ else reply->handle = -1;
}
/* open a handle to a mutex */
DECL_HANDLER(open_mutex)
{
- struct open_mutex_reply reply;
- char *name = (char *)data;
- if (!len) name = NULL;
- else CHECK_STRING( "open_mutex", name, len );
-
- reply.handle = open_object( name, &mutex_ops, req->access, req->inherit );
- send_reply( current, -1, 1, &reply, sizeof(reply) );
+ size_t len = get_req_strlen();
+ struct open_mutex_reply *reply = push_reply_data( current, sizeof(*reply) );
+ reply->handle = open_object( get_req_data( len + 1 ), len, &mutex_ops,
+ req->access, req->inherit );
}
/* release a mutex */
DECL_HANDLER(release_mutex)
{
- if (release_mutex( req->handle )) CLEAR_ERROR();
- send_reply( current, -1, 0 );
+ struct mutex *mutex;
+
+ if ((mutex = (struct mutex *)get_handle_obj( current->process, req->handle,
+ MUTEX_MODIFY_STATE, &mutex_ops )))
+ {
+ if (!mutex->count || (mutex->owner != current)) set_error( ERROR_NOT_OWNER );
+ else if (!--mutex->count) do_release( mutex, current );
+ release_object( mutex );
+ }
}