2 Copyright (C) 2001 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 2004, 2007 g10 Code GmbH
5 This file is part of GPGME.
7 GPGME is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of
10 the License, or (at your option) any later version.
12 GPGME is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31 #ifdef HAVE_SYS_TIME_H
32 # include <sys/time.h>
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
44 sema_fatal (const char *text)
46 fprintf (stderr, "sema.c: %s\n", text);
52 critsect_init (struct critsect_s *s)
55 static CRITICAL_SECTION init_lock;
56 static int initialized;
59 /* The very first time we call this function, we assume that
60 only one thread is running, so that we can bootstrap the
62 InitializeCriticalSection (&init_lock);
66 return; /* we just want to initialize ourself */
68 /* first test whether it is really not initialized */
69 EnterCriticalSection (&init_lock);
71 LeaveCriticalSection (&init_lock);
75 mp = malloc ( sizeof *mp );
77 LeaveCriticalSection (&init_lock);
78 sema_fatal ("out of core while creating critical section lock");
80 InitializeCriticalSection (mp);
82 LeaveCriticalSection (&init_lock);
86 _gpgme_sema_subsystem_init ()
88 /* fixme: we should check that there is only one thread running */
94 _gpgme_sema_cs_enter ( struct critsect_s *s )
98 EnterCriticalSection ( (CRITICAL_SECTION*)s->priv );
102 _gpgme_sema_cs_leave (struct critsect_s *s)
106 LeaveCriticalSection ((CRITICAL_SECTION*)s->priv);
110 _gpgme_sema_cs_destroy ( struct critsect_s *s )
113 DeleteCriticalSection ((CRITICAL_SECTION*)s->priv);