summaryrefslogtreecommitdiff
path: root/gdk/gdkthreads.c
blob: d83375b57e0fbe06d8eec39975fcf4c925442c08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* GDK - The GIMP Drawing Kit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#include "../config.h"
#include "gdk.h"
#include "gdkprivate.h"

#ifdef USE_PTHREADS
#include <unistd.h>
#include <pthread.h>

pthread_mutex_t gdk_threads_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif /* USE_PTHREADS */

gboolean
gdk_threads_init (void)
{
#ifdef USE_PTHREADS  
  pipe (gdk_threads_pipe);
  gdk_using_threads = TRUE;
  return TRUE;
#else
  return FALSE;
#endif
}

void
gdk_threads_enter (void)
{
#ifdef USE_PTHREADS
  pthread_mutex_lock (&gdk_threads_mutex);
#endif  
}

void
gdk_threads_leave (void)
{
#ifdef USE_PTHREADS
  pthread_mutex_unlock (&gdk_threads_mutex);
#endif  
}

void          
gdk_threads_wake (void)
{
#ifdef USE_PTHREADS
  if (gdk_select_waiting)
    {
      gdk_select_waiting = FALSE;
      write (gdk_threads_pipe[1], "A", 1);
    }
#endif  
}