/* * portability.c: Miscellaneous stuff needed for porting to other platforms * * Copyright (C) 2003, Olaf Kirch * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser 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 "internal.h" #include #include #if defined(HAVE_PTHREAD) #include sc_mutex_t * sc_mutex_new(void) { pthread_mutex_t *mutex; mutex = (pthread_mutex_t *) malloc(sizeof(*mutex)); assert(mutex); pthread_mutex_init(mutex, NULL); return (sc_mutex_t *) mutex; } void sc_mutex_lock(sc_mutex_t *p) { pthread_mutex_lock((pthread_mutex_t *) p); } void sc_mutex_unlock(sc_mutex_t *p) { pthread_mutex_unlock((pthread_mutex_t *) p); } void sc_mutex_free(sc_mutex_t *p) { pthread_mutex_destroy((pthread_mutex_t *) p); free(p); } #elif defined(_WIN32) sc_mutex_t * sc_mutex_new(void) { CRITICAL_SECTION *mutex; mutex = (CRITICAL_SECTION *) malloc(sizeof(*m)); assert(mutex); InitializeCriticalSection(mutex); return (sc_mutex_t *) mutex; } void sc_mutex_lock(sc_mutex_t *p) { EnterCriticalSection((CRITICAL_SECTION *) p); } void sc_mutex_unlock(sc_mutex_t *p) { LeaveCriticalSection((CRITICAL_SECTION *) p); } void sc_mutex_free(sc_mutex_t *p) { DeleteCriticalSection((CRITICAL_SECTION *) p); free(p); } #else sc_mutex_t * sc_mutex_new(void) { *p = NULL; } void sc_mutex_lock(sc_mutex_t *p) { /* NOP */ } void sc_mutex_unlock(sc_mutex_t *p) { /* NOP */ } void sc_mutex_free(sc_mutex_t *p) { /* NOP */ } #endif