1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2010 Index Data
3 * See the file LICENSE for details.
8 * \brief Implements MUTEX functions
20 #include <yaz/xmalloc.h>
23 #include <yaz/mutex.h>
39 CRITICAL_SECTION m_handle;
41 #elif YAZ_POSIX_THREADS
43 pthread_mutex_t m_handle;
55 YAZ_EXPORT void yaz_mutex_create(YAZ_MUTEX *p)
59 *p = (YAZ_MUTEX) malloc(sizeof(**p));
61 InitializeCriticalSection(&(*p)->m_handle);
62 #elif YAZ_POSIX_THREADS
63 pthread_mutex_init(&(*p)->m_handle, 0);
65 pth_mutex_init(&(*p)->m_handle);
70 YAZ_EXPORT void yaz_mutex_enter(YAZ_MUTEX p)
75 EnterCriticalSection(&p->m_handle);
76 #elif YAZ_POSIX_THREADS
77 pthread_mutex_lock(&p->m_handle);
82 YAZ_EXPORT void yaz_mutex_leave(YAZ_MUTEX p)
87 LeaveCriticalSection(&p->m_handle);
88 #elif YAZ_POSIX_THREADS
89 pthread_mutex_unlock(&p->m_handle);
94 YAZ_EXPORT void yaz_mutex_destroy(YAZ_MUTEX *p)
99 DeleteCriticalSection(&(*p)->m_handle);
109 * c-file-style: "Stroustrup"
110 * indent-tabs-mode: nil
112 * vim: shiftwidth=4 tabstop=8 expandtab