From: Rémi Bernon rbernon@codeweavers.com
--- server/atom.c | 72 +++++++++---------------------------------------- server/class.c | 42 ++++++++++++++++------------- server/object.h | 10 ++++--- server/window.c | 31 +++++++++++++-------- 4 files changed, 63 insertions(+), 92 deletions(-)
diff --git a/server/atom.c b/server/atom.c index 1f8b9cd5502..3a0992e33d5 100644 --- a/server/atom.c +++ b/server/atom.c @@ -117,6 +117,11 @@ void set_global_atom_table( struct object *obj ) grab_object( obj ); }
+struct atom_table *get_global_atom_table(void) +{ + return global_table; +} + /* retrieve an entry pointer from its atom */ static struct atom_entry *get_atom_entry( struct atom_table *table, atom_t atom ) { @@ -182,7 +187,7 @@ static struct atom_entry *find_atom_entry( struct atom_table *table, const struc }
/* add an atom to the table */ -static atom_t add_atom( struct atom_table *table, const struct unicode_str *str ) +atom_t add_atom( struct atom_table *table, const struct unicode_str *str ) { struct atom_entry *entry; unsigned short hash; @@ -244,7 +249,7 @@ static void delete_atom( struct atom_table *table, atom_t atom, int if_pinned ) }
/* find an atom in the table */ -static atom_t find_atom( struct atom_table *table, const struct unicode_str *str ) +atom_t find_atom( struct atom_table *table, const struct unicode_str *str ) { struct atom_entry *entry; unsigned short hash; @@ -269,73 +274,22 @@ static atom_t find_atom( struct atom_table *table, const struct unicode_str *str return entry->atom; }
-static struct atom_table *get_global_table( struct winstation *winstation, int create ) -{ - struct atom_table *table = winstation ? winstation->atom_table : global_table; - if (!table) - { - if (create) - { - table = (struct atom_table *)create_atom_table(); - if (winstation) winstation->atom_table = table; - else - { - global_table = table; - make_object_permanent( &global_table->obj ); - } - } - else set_error( STATUS_OBJECT_NAME_NOT_FOUND ); - } - return table; -} - -/* add an atom in the global table; used for window properties */ -atom_t add_global_atom( struct winstation *winstation, const struct unicode_str *str ) -{ - struct atom_table *table = get_global_table( winstation, 1 ); - if (!table) return 0; - return add_atom( table, str ); -} - -/* find an atom in the global table; used for window properties */ -atom_t find_global_atom( struct winstation *winstation, const struct unicode_str *str ) -{ - struct atom_table *table = get_global_table( winstation, 0 ); - struct atom_entry *entry; - unsigned short hash; - - if (!str->len || str->len > MAX_ATOM_LEN || !table) return 0; - - hash = hash_strW( str->str, str->len, ARRAY_SIZE(table->entries) ); - if (!(entry = find_atom_entry( table, str, hash ))) return 0; - return entry->atom; -} - /* increment the ref count of a global atom; used for window properties */ -int grab_global_atom( struct winstation *winstation, atom_t atom ) +int grab_atom( struct atom_table *table, atom_t atom ) { if (atom >= MIN_STR_ATOM) { - struct atom_table *table = get_global_table( winstation, 0 ); - if (table) - { - struct atom_entry *entry = get_atom_entry( table, atom ); - if (entry) entry->count++; - return (entry != NULL); - } - else return 0; + struct atom_entry *entry = get_atom_entry( table, atom ); + if (entry) entry->count++; + return (entry != NULL); } else return 1; }
/* decrement the ref count of a global atom; used for window properties */ -void release_global_atom( struct winstation *winstation, atom_t atom ) +void release_atom( struct atom_table *table, atom_t atom ) { - if (atom >= MIN_STR_ATOM) - { - struct atom_table *table = get_global_table( winstation, 0 ); - if (table) delete_atom( table, atom, 1 ); - } + if (atom >= MIN_STR_ATOM) delete_atom( table, atom, 1 ); }
/* add a global atom */ diff --git a/server/class.c b/server/class.c index 3231f366b26..090c8accaea 100644 --- a/server/class.c +++ b/server/class.c @@ -75,8 +75,10 @@ static struct window_class *create_class( struct process *process, int extra_byt
static void destroy_class( struct window_class *class ) { - release_global_atom( NULL, class->atom ); - release_global_atom( NULL, class->base_atom ); + struct atom_table *table = get_global_atom_table(); + + release_atom( table, class->atom ); + release_atom( table, class->base_atom ); list_remove( &class->entry ); release_object( class->process ); free( class ); @@ -137,8 +139,9 @@ int is_hwnd_message_class( struct window_class *class ) { static const WCHAR messageW[] = {'M','e','s','s','a','g','e'}; static const struct unicode_str name = { messageW, sizeof(messageW) }; + struct atom_table *table = get_global_atom_table();
- return (!class->local && class->atom == find_global_atom( NULL, &name )); + return (!class->local && class->atom == find_atom( table, &name )); }
int get_class_style( struct window_class *class ) @@ -161,58 +164,59 @@ DECL_HANDLER(create_class) { struct window_class *class; struct unicode_str name = get_req_unicode_str(); + struct atom_table *table = get_global_atom_table(); atom_t atom, base_atom;
if (name.len) { - atom = add_global_atom( NULL, &name ); + atom = add_atom( table, &name ); if (!atom) return; if (req->name_offset && req->name_offset < name.len / sizeof(WCHAR)) { name.str += req->name_offset; name.len -= req->name_offset * sizeof(WCHAR);
- base_atom = add_global_atom( NULL, &name ); + base_atom = add_atom( table, &name ); if (!base_atom) { - release_global_atom( NULL, atom ); + release_atom( table, atom ); return; } } else { base_atom = atom; - grab_global_atom( NULL, atom ); + grab_atom( table, atom ); } } else { base_atom = atom = req->atom; - if (!grab_global_atom( NULL, atom )) return; - grab_global_atom( NULL, base_atom ); + if (!grab_atom( table, atom )) return; + grab_atom( table, base_atom ); }
class = find_class( current->process, atom, req->instance ); if (class && !class->local == !req->local) { set_win32_error( ERROR_CLASS_ALREADY_EXISTS ); - release_global_atom( NULL, atom ); - release_global_atom( NULL, base_atom ); + release_atom( table, atom ); + release_atom( table, base_atom ); return; } if (req->extra < 0 || req->extra > 4096 || req->win_extra < 0 || req->win_extra > 4096) { /* don't allow stupid values here */ set_error( STATUS_INVALID_PARAMETER ); - release_global_atom( NULL, atom ); - release_global_atom( NULL, base_atom ); + release_atom( table, atom ); + release_atom( table, base_atom ); return; }
if (!(class = create_class( current->process, req->extra, req->local ))) { - release_global_atom( NULL, atom ); - release_global_atom( NULL, base_atom ); + release_atom( table, atom ); + release_atom( table, base_atom ); return; } class->atom = atom; @@ -229,9 +233,10 @@ DECL_HANDLER(destroy_class) { struct window_class *class; struct unicode_str name = get_req_unicode_str(); + struct atom_table *table = get_global_atom_table(); atom_t atom = req->atom;
- if (name.len) atom = find_global_atom( NULL, &name ); + if (name.len) atom = find_atom( table, &name );
if (!(class = find_class( current->process, atom, req->instance ))) set_win32_error( ERROR_CLASS_DOES_NOT_EXIST ); @@ -249,6 +254,7 @@ DECL_HANDLER(destroy_class) DECL_HANDLER(set_class_info) { struct window_class *class = get_window_class( req->window ); + struct atom_table *table = get_global_atom_table();
if (!class) return;
@@ -289,8 +295,8 @@ DECL_HANDLER(set_class_info)
if (req->flags & SET_CLASS_ATOM) { - if (!grab_global_atom( NULL, req->atom )) return; - release_global_atom( NULL, class->atom ); + if (!grab_atom( table, req->atom )) return; + release_atom( table, class->atom ); class->atom = req->atom; } if (req->flags & SET_CLASS_STYLE) class->style = req->style; diff --git a/server/object.h b/server/object.h index 7861b3e6c40..848f6dc977e 100644 --- a/server/object.h +++ b/server/object.h @@ -287,10 +287,12 @@ extern void init_signals(void); extern struct object *create_atom_table(void); extern void set_global_atom_table( struct object *obj );
-extern atom_t add_global_atom( struct winstation *winstation, const struct unicode_str *str ); -extern atom_t find_global_atom( struct winstation *winstation, const struct unicode_str *str ); -extern int grab_global_atom( struct winstation *winstation, atom_t atom ); -extern void release_global_atom( struct winstation *winstation, atom_t atom ); +struct atom_table; +extern struct atom_table *get_global_atom_table(void); +extern atom_t add_atom( struct atom_table *table, const struct unicode_str *str ); +extern atom_t find_atom( struct atom_table *table, const struct unicode_str *str ); +extern int grab_atom( struct atom_table *table, atom_t atom ); +extern void release_atom( struct atom_table *table, atom_t atom );
/* directory functions */
diff --git a/server/window.c b/server/window.c index 6b45633f66d..6af3aa8f622 100644 --- a/server/window.c +++ b/server/window.c @@ -471,6 +471,7 @@ static int add_handle_to_array( struct user_handle_array *array, user_handle_t h /* set a window property */ static void set_property( struct window *win, atom_t atom, lparam_t data, enum property_type type ) { + struct atom_table *table = get_global_atom_table(); int i, free = -1; struct property *new_props;
@@ -491,7 +492,7 @@ static void set_property( struct window *win, atom_t atom, lparam_t data, enum p }
/* need to add an entry */ - if (!grab_global_atom( NULL, atom )) return; + if (!grab_atom( table, atom )) return; if (free == -1) { /* no free entry */ @@ -502,7 +503,7 @@ static void set_property( struct window *win, atom_t atom, lparam_t data, enum p sizeof(*new_props) * (win->prop_alloc + 16) ))) { set_error( STATUS_NO_MEMORY ); - release_global_atom( NULL, atom ); + release_atom( table, atom ); return; } win->prop_alloc += 16; @@ -518,6 +519,7 @@ static void set_property( struct window *win, atom_t atom, lparam_t data, enum p /* remove a window property */ static lparam_t remove_property( struct window *win, atom_t atom ) { + struct atom_table *table = get_global_atom_table(); int i;
for (i = 0; i < win->prop_inuse; i++) @@ -525,7 +527,7 @@ static lparam_t remove_property( struct window *win, atom_t atom ) if (win->properties[i].type == PROP_TYPE_FREE) continue; if (win->properties[i].atom == atom) { - release_global_atom( NULL, atom ); + release_atom( table, atom ); win->properties[i].type = PROP_TYPE_FREE; return win->properties[i].data; } @@ -551,13 +553,14 @@ static lparam_t get_property( struct window *win, atom_t atom ) /* destroy all properties of a window */ static inline void destroy_properties( struct window *win ) { + struct atom_table *table = get_global_atom_table(); int i;
if (!win->properties) return; for (i = 0; i < win->prop_inuse; i++) { if (win->properties[i].type == PROP_TYPE_FREE) continue; - release_global_atom( NULL, win->properties[i].atom ); + release_atom( table, win->properties[i].atom ); } free( win->properties ); } @@ -2200,6 +2203,7 @@ DECL_HANDLER(create_window) { struct window *win, *parent = NULL, *owner = NULL; struct unicode_str cls_name = get_req_unicode_str(); + struct atom_table *table = get_global_atom_table(); unsigned int dpi_context; atom_t atom;
@@ -2229,7 +2233,7 @@ DECL_HANDLER(create_window) owner = owner->parent; }
- atom = cls_name.len ? find_global_atom( NULL, &cls_name ) : req->atom; + atom = cls_name.len ? find_atom( table, &cls_name ) : req->atom;
if (!(win = create_window( parent, owner, atom, req->class_instance, req->instance ))) return;
@@ -2314,7 +2318,8 @@ DECL_HANDLER(get_desktop_window) { static const WCHAR messageW[] = {'M','e','s','s','a','g','e'}; static const struct unicode_str name = { messageW, sizeof(messageW) }; - atom_t atom = add_global_atom( NULL, &name ); + struct atom_table *table = get_global_atom_table(); + atom_t atom = add_atom( table, &name ); if (atom && (desktop->msg_window = create_window( NULL, NULL, atom, 0, 0 ))) { detach_window_thread( desktop->msg_window ); @@ -2528,11 +2533,12 @@ DECL_HANDLER(get_class_windows) struct desktop *desktop = NULL; struct window *parent = NULL, *win = NULL; struct unicode_str cls_name = get_req_unicode_str(); + struct atom_table *table = get_global_atom_table(); atom_t atom = req->atom; user_handle_t *data; unsigned int count = 0, max_count = get_reply_max_size() / sizeof(*data);
- if (cls_name.len && !(atom = find_global_atom( NULL, &cls_name ))) return; + if (cls_name.len && !(atom = find_atom( table, &cls_name ))) return; if (req->parent && !(parent = get_window( req->parent ))) return;
if (req->child) @@ -3072,17 +3078,18 @@ DECL_HANDLER(redraw_window) DECL_HANDLER(set_window_property) { struct unicode_str name = get_req_unicode_str(); + struct atom_table *table = get_global_atom_table(); struct window *win = get_window( req->window );
if (!win) return;
if (name.len) { - atom_t atom = add_global_atom( NULL, &name ); + atom_t atom = add_atom( table, &name ); if (atom) { set_property( win, atom, req->data, PROP_TYPE_STRING ); - release_global_atom( NULL, atom ); + release_atom( table, atom ); } } else set_property( win, req->atom, req->data, PROP_TYPE_ATOM ); @@ -3093,11 +3100,12 @@ DECL_HANDLER(set_window_property) DECL_HANDLER(remove_window_property) { struct unicode_str name = get_req_unicode_str(); + struct atom_table *table = get_global_atom_table(); struct window *win = get_window( req->window );
if (win) { - atom_t atom = name.len ? find_global_atom( NULL, &name ) : req->atom; + atom_t atom = name.len ? find_atom( table, &name ) : req->atom; if (atom) reply->data = remove_property( win, atom ); } } @@ -3107,11 +3115,12 @@ DECL_HANDLER(remove_window_property) DECL_HANDLER(get_window_property) { struct unicode_str name = get_req_unicode_str(); + struct atom_table *table = get_global_atom_table(); struct window *win = get_window( req->window );
if (win) { - atom_t atom = name.len ? find_global_atom( NULL, &name ) : req->atom; + atom_t atom = name.len ? find_atom( table, &name ) : req->atom; if (atom) reply->data = get_property( win, atom ); } }