Removing xe_mutex_t.

This commit is contained in:
Ben Vanik
2014-08-16 00:56:50 -07:00
parent 96fb484dd9
commit bca49bed4b
23 changed files with 101 additions and 276 deletions

View File

@@ -1,27 +0,0 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_CORE_MUTEX_H_
#define XENIA_CORE_MUTEX_H_
#include <xenia/common.h>
typedef struct xe_mutex xe_mutex_t;
xe_mutex_t* xe_mutex_alloc(uint32_t spin_count = 10000);
void xe_mutex_free(xe_mutex_t* mutex);
int xe_mutex_lock(xe_mutex_t* mutex);
int xe_mutex_trylock(xe_mutex_t* mutex);
int xe_mutex_unlock(xe_mutex_t* mutex);
#endif // XENIA_CORE_MUTEX_H_

View File

@@ -1,60 +0,0 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <xenia/core/mutex.h>
struct xe_mutex {
pthread_mutex_t value;
};
xe_mutex_t* xe_mutex_alloc(uint32_t spin_count) {
xe_mutex_t* mutex = (xe_mutex_t*)xe_calloc(sizeof(xe_mutex_t));
int result = pthread_mutex_init(&mutex->value, NULL);
switch (result) {
case ENOMEM:
case EINVAL:
xe_free(mutex);
return NULL;
}
return mutex;
}
void xe_mutex_free(xe_mutex_t* mutex) {
int result = pthread_mutex_destroy(&mutex->value);
switch (result) {
case EBUSY:
case EINVAL:
break;
default:
break;
}
xe_free(mutex);
}
int xe_mutex_lock(xe_mutex_t* mutex) {
return pthread_mutex_lock(&mutex->value) == EINVAL ? 1 : 0;
}
int xe_mutex_trylock(xe_mutex_t* mutex) {
int result = pthread_mutex_trylock(&mutex->value);
switch (result) {
case EBUSY:
case EINVAL:
return 1;
default:
return 0;
}
}
int xe_mutex_unlock(xe_mutex_t* mutex) {
return pthread_mutex_unlock(&mutex->value) == EINVAL ? 1 : 0;
}

View File

@@ -1,50 +0,0 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <xenia/core/mutex.h>
struct xe_mutex {
CRITICAL_SECTION value;
};
xe_mutex_t* xe_mutex_alloc(uint32_t spin_count) {
xe_mutex_t* mutex = (xe_mutex_t*)xe_calloc(sizeof(xe_mutex_t));
if (spin_count) {
InitializeCriticalSectionAndSpinCount(&mutex->value, spin_count);
} else {
InitializeCriticalSection(&mutex->value);
}
return mutex;
}
void xe_mutex_free(xe_mutex_t* mutex) {
DeleteCriticalSection(&mutex->value);
xe_free(mutex);
}
int xe_mutex_lock(xe_mutex_t* mutex) {
EnterCriticalSection(&mutex->value);
return 0;
}
int xe_mutex_trylock(xe_mutex_t* mutex) {
if (TryEnterCriticalSection(&mutex->value) == TRUE) {
return 0;
} else {
return 1;
}
}
int xe_mutex_unlock(xe_mutex_t* mutex) {
LeaveCriticalSection(&mutex->value);
return 0;
}

View File

@@ -9,7 +9,6 @@
#include <xenia/core/run_loop.h>
#include <xenia/core/mutex.h>
#include <xenia/core/thread.h>

View File

@@ -4,7 +4,6 @@
'hash.cc',
'hash.h',
'mmap.h',
'mutex.h',
'pal.h',
'path.cc',
'path.h',
@@ -20,7 +19,6 @@
['OS == "mac" or OS == "linux"', {
'sources': [
'mmap_posix.cc',
'mutex_posix.cc',
'path_posix.cc',
'socket_posix.cc',
],
@@ -38,7 +36,6 @@
['OS == "win"', {
'sources': [
'mmap_win.cc',
'mutex_win.cc',
'pal_win.cc',
'path_win.cc',
'run_loop_win.cc',