2007-11-04 03:34:51 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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 General Public License for more details.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "qthreads.h"
|
|
|
|
#include "mutex.h"
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===================================================================
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
WIN32
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
===================================================================
|
|
|
|
*/
|
2008-07-25 07:31:37 +00:00
|
|
|
#ifdef WIN32
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define USED
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void MutexLock( mutex_t *m ){
|
2007-11-04 03:34:51 +00:00
|
|
|
CRITICAL_SECTION *crit;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !m ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
crit = (CRITICAL_SECTION *) m;
|
2012-03-17 20:01:54 +00:00
|
|
|
EnterCriticalSection( crit );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void MutexUnlock( mutex_t *m ){
|
2007-11-04 03:34:51 +00:00
|
|
|
CRITICAL_SECTION *crit;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !m ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
crit = (CRITICAL_SECTION *) m;
|
2012-03-17 20:01:54 +00:00
|
|
|
LeaveCriticalSection( crit );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
mutex_t *MutexAlloc( void ){
|
2007-11-04 03:34:51 +00:00
|
|
|
CRITICAL_SECTION *crit;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numthreads == 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return NULL;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
crit = (CRITICAL_SECTION *) safe_malloc( sizeof( CRITICAL_SECTION ) );
|
|
|
|
InitializeCriticalSection( crit );
|
2007-11-04 03:34:51 +00:00
|
|
|
return (void *) crit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===================================================================
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
OSF1
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
===================================================================
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#ifdef __osf__
|
2012-03-17 20:01:54 +00:00
|
|
|
#define USED
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void MutexLock( mutex_t *m ){
|
|
|
|
pthread_mutex_t *my_mutex;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !m ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
my_mutex = (pthread_mutex_t *) m;
|
2012-03-17 20:01:54 +00:00
|
|
|
pthread_mutex_lock( my_mutex );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void MutexUnlock( mutex_t *m ){
|
|
|
|
pthread_mutex_t *my_mutex;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !m ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
my_mutex = (pthread_mutex_t *) m;
|
2012-03-17 20:01:54 +00:00
|
|
|
pthread_mutex_unlock( my_mutex );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
mutex_t *MutexAlloc( void ){
|
|
|
|
pthread_mutex_t *my_mutex;
|
|
|
|
pthread_mutexattr_t mattrib;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numthreads == 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return NULL;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
my_mutex = safe_malloc( sizeof( *my_mutex ) );
|
|
|
|
if ( pthread_mutexattr_create( &mattrib ) == -1 ) {
|
|
|
|
Error( "pthread_mutex_attr_create failed" );
|
|
|
|
}
|
|
|
|
if ( pthread_mutexattr_setkind_np( &mattrib, MUTEX_FAST_NP ) == -1 ) {
|
|
|
|
Error( "pthread_mutexattr_setkind_np failed" );
|
|
|
|
}
|
|
|
|
if ( pthread_mutex_init( my_mutex, mattrib ) == -1 ) {
|
|
|
|
Error( "pthread_mutex_init failed" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
return (void *) my_mutex;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===================================================================
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
IRIX
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
===================================================================
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#ifdef _MIPS_ISA
|
|
|
|
#define USED
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#include <task.h>
|
|
|
|
#include <abi_mutex.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/prctl.h>
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void MutexLock( mutex_t *m ){
|
2007-11-04 03:34:51 +00:00
|
|
|
abilock_t *lck;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !m ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
lck = (abilock_t *) m;
|
2012-03-17 20:01:54 +00:00
|
|
|
spin_lock( lck );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void MutexUnlock( mutex_t *m ){
|
2007-11-04 03:34:51 +00:00
|
|
|
abilock_t *lck;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !m ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
lck = (abilock_t *) m;
|
2012-03-17 20:01:54 +00:00
|
|
|
release_lock( lck );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
mutex_t *MutexAlloc( void ){
|
2007-11-04 03:34:51 +00:00
|
|
|
abilock_t *lck;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numthreads == 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return NULL;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
lck = (abilock_t *) safe_malloc( sizeof( abilock_t ) );
|
|
|
|
init_lock( lck );
|
2007-11-04 03:34:51 +00:00
|
|
|
return (void *) lck;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=======================================================================
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
SINGLE THREAD
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
=======================================================================
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#ifndef USED
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void MutexLock( mutex_t *m ){
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void MutexUnlock( mutex_t *m ){
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
mutex_t *MutexAlloc( void ){
|
2007-11-04 03:34:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|