diff options
author | Owen Taylor <otaylor@src.gnome.org> | 1998-12-15 05:28:02 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 1998-12-15 05:28:02 +0000 |
commit | 931ea952650b013b834041b91b0c37a748ffd449 (patch) | |
tree | 0c97c450b0e07953d836f1603c6fcb0357a58149 /gslist.c | |
parent | c8ba100dab8949c49097f11004c09ef36ea5136f (diff) | |
download | glib-931ea952650b013b834041b91b0c37a748ffd449.tar.gz |
This commit merges the glib-threads branch into the main
branch. See the ChangeLog for details of the changes.
In brief overview:
- The set of threading functions can be set
- A default implementation is provided in -lgthread
- All static data structures are locked using these
functions if g_thread_init() is called.
Diffstat (limited to 'gslist.c')
-rw-r--r-- | gslist.c | 37 |
1 files changed, 33 insertions, 4 deletions
@@ -16,6 +16,11 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ + +/* + * MT safe + */ + #include "glib.h" @@ -30,10 +35,12 @@ struct _GAllocator /* from gmem.c */ GSList *free_lists; /* implementation specific */ }; +static G_LOCK_DEFINE(current_allocator); static GAllocator *current_allocator = NULL; -void -g_slist_push_allocator (GAllocator *allocator) +/* HOLDS: current_allocator_lock */ +static void +g_slist_validate_allocator (GAllocator *allocator) { g_return_if_fail (allocator != NULL); g_return_if_fail (allocator->is_unused == TRUE); @@ -58,13 +65,22 @@ g_slist_push_allocator (GAllocator *allocator) } allocator->is_unused = FALSE; +} + +void +g_slist_push_allocator (GAllocator *allocator) +{ + g_slist_validate_allocator (allocator); + g_lock (current_allocator); allocator->last = current_allocator; current_allocator = allocator; + g_unlock (current_allocator); } void g_slist_pop_allocator (void) { + g_lock (current_allocator); if (current_allocator) { GAllocator *allocator; @@ -74,6 +90,7 @@ g_slist_pop_allocator (void) allocator->last = NULL; allocator->is_unused = TRUE; } + g_unlock (current_allocator); } GSList* @@ -81,9 +98,15 @@ g_slist_alloc (void) { GSList *list; + g_lock (current_allocator); if (!current_allocator) - g_slist_push_allocator (g_allocator_new ("GLib default GSList allocator", 1024)); - + { + GAllocator *allocator = g_allocator_new ("GLib default GSList allocator", + 1024); + g_slist_validate_allocator (allocator); + allocator->last = NULL; + current_allocator = allocator; + } if (!current_allocator->free_lists) { list = g_chunk_new (GSList, current_allocator->mem_chunk); @@ -103,6 +126,8 @@ g_slist_alloc (void) current_allocator->free_lists = list->next; } } + g_unlock (current_allocator); + list->next = NULL; return list; @@ -114,8 +139,10 @@ g_slist_free (GSList *list) if (list) { list->data = list->next; + g_lock (current_allocator); list->next = current_allocator->free_lists; current_allocator->free_lists = list; + g_unlock (current_allocator); } } @@ -125,8 +152,10 @@ g_slist_free_1 (GSList *list) if (list) { list->data = NULL; + g_lock (current_allocator); list->next = current_allocator->free_lists; current_allocator->free_lists = list; + g_unlock (current_allocator); } } |