~registry/glib/glib-2-30

« back to all changes in this revision

Viewing changes to glib/garray.c

  • Committer: Owen Taylor
  • Date: 1998-12-15 05:28:02 UTC
  • Revision ID: git-v1:931ea952650b013b834041b91b0c37a748ffd449
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
17
 * Boston, MA 02111-1307, USA.
18
18
 */
 
19
 
 
20
/* 
 
21
 * MT safe
 
22
 */
 
23
 
19
24
#include <string.h>
20
25
#include "glib.h"
21
26
 
40
45
static void g_array_maybe_expand (GRealArray *array,
41
46
                                  gint        len);
42
47
 
43
 
 
44
48
static GMemChunk *array_mem_chunk = NULL;
45
 
 
 
49
static G_LOCK_DEFINE(array_mem_chunk);
46
50
 
47
51
GArray*
48
52
g_array_new (gboolean zero_terminated,
51
55
{
52
56
  GRealArray *array;
53
57
 
 
58
  g_lock (array_mem_chunk);
54
59
  if (!array_mem_chunk)
55
60
    array_mem_chunk = g_mem_chunk_new ("array mem chunk",
56
61
                                       sizeof (GRealArray),
57
62
                                       1024, G_ALLOC_AND_FREE);
58
63
 
59
64
  array = g_chunk_new (GRealArray, array_mem_chunk);
 
65
  g_unlock (array_mem_chunk);
60
66
 
61
67
  array->data            = NULL;
62
68
  array->len             = 0;
75
81
  if (free_segment)
76
82
    g_free (array->data);
77
83
 
 
84
  g_lock (array_mem_chunk);
78
85
  g_mem_chunk_free (array_mem_chunk, array);
 
86
  g_unlock (array_mem_chunk);
79
87
}
80
88
 
81
89
GArray*
241
249
static void g_ptr_array_maybe_expand (GRealPtrArray *array,
242
250
                                      gint           len);
243
251
 
244
 
 
245
252
static GMemChunk *ptr_array_mem_chunk = NULL;
246
 
 
 
253
static G_LOCK_DEFINE(ptr_array_mem_chunk);
247
254
 
248
255
 
249
256
GPtrArray*
251
258
{
252
259
  GRealPtrArray *array;
253
260
 
 
261
  g_lock (ptr_array_mem_chunk);
254
262
  if (!ptr_array_mem_chunk)
255
263
    ptr_array_mem_chunk = g_mem_chunk_new ("array mem chunk",
256
264
                                           sizeof (GRealPtrArray),
257
265
                                           1024, G_ALLOC_AND_FREE);
258
266
 
259
267
  array = g_chunk_new (GRealPtrArray, ptr_array_mem_chunk);
 
268
  g_unlock (ptr_array_mem_chunk);
260
269
 
261
270
  array->pdata = NULL;
262
271
  array->len = 0;
274
283
  if (free_segment)
275
284
    g_free (array->pdata);
276
285
 
 
286
  g_lock (ptr_array_mem_chunk);
277
287
  g_mem_chunk_free (ptr_array_mem_chunk, array);
 
288
  g_unlock (ptr_array_mem_chunk);
278
289
}
279
290
 
280
291
static void