Move g_private_new() to common code

The implementations for posix and win32 were identical, so
move it to gthread.c, to go with g_mutex_new() and g_cond_new().
This commit is contained in:
Matthias Clasen 2011-09-18 21:24:25 -04:00 committed by Ryan Lortie
parent dffca80846
commit 862e086b79
3 changed files with 37 additions and 52 deletions

View File

@ -387,45 +387,6 @@ g_cond_timedwait (GCond *cond,
/* {{{1 GPrivate */
/**
* g_private_new:
* @destructor: a function to destroy the data keyed to
* the #GPrivate when a thread ends
*
* Creates a new #GPrivate. If @destructor is non-%NULL, it is a
* pointer to a destructor function. Whenever a thread ends and the
* corresponding pointer keyed to this instance of #GPrivate is
* non-%NULL, the destructor is called with this pointer as the
* argument.
*
* <note><para>
* #GStaticPrivate is a better choice for most uses.
* </para></note>
*
* <note><para>@destructor is used quite differently from @notify in
* g_static_private_set().</para></note>
*
* <note><para>A #GPrivate cannot be freed. Reuse it instead, if you
* can, to avoid shortage, or use #GStaticPrivate.</para></note>
*
* <note><para>This function will abort if g_thread_init() has not been
* called yet.</para></note>
*
* Returns: a newly allocated #GPrivate
*/
GPrivate *
g_private_new (GDestroyNotify notify)
{
GPrivate *key;
key = malloc (sizeof (GPrivate));
if G_UNLIKELY (key == NULL)
g_thread_abort (errno, "malloc");
g_private_init (key, notify);
return key;
}
void
g_private_init (GPrivate *key,
GDestroyNotify notify)

View File

@ -245,19 +245,6 @@ struct _GPrivateDestructor
static GPrivateDestructor * volatile g_private_destructors;
GPrivate *
g_private_new (GDestroyNotify notify)
{
GPrivate *key;
key = malloc (sizeof (GPrivate));
if G_UNLIKELY (key == NULL)
g_thread_abort (errno, "malloc");
g_private_init (key, notify);
return key;
}
void
g_private_init (GPrivate *key,
GDestroyNotify notify)

View File

@ -2438,3 +2438,40 @@ g_cond_free (GCond *cond)
g_cond_clear (cond);
g_slice_free (GCond, cond);
}
/**
* g_private_new:
* @destructor: a function to destroy the data keyed to
* the #GPrivate when a thread ends
*
* Creates a new #GPrivate. If @destructor is non-%NULL, it is a
* pointer to a destructor function. Whenever a thread ends and the
* corresponding pointer keyed to this instance of #GPrivate is
* non-%NULL, the destructor is called with this pointer as the
* argument.
*
* <note><para>
* #GStaticPrivate is a better choice for most uses.
* </para></note>
*
* <note><para>@destructor is used quite differently from @notify in
* g_static_private_set().</para></note>
*
* <note><para>A #GPrivate cannot be freed. Reuse it instead, if you
* can, to avoid shortage, or use #GStaticPrivate.</para></note>
*
* <note><para>This function will abort if g_thread_init() has not been
* called yet.</para></note>
*
* Returns: a newly allocated #GPrivate
*/
GPrivate *
g_private_new (GDestroyNotify notify)
{
GPrivate *key;
key = malloc (sizeof (GPrivate));
g_private_init (key, notify);
return key;
}