mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-03 08:00:50 +00:00
add mutex
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@691 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -17,6 +17,7 @@ our $cflags = "-fPIC -D_MILSKO";
|
|||||||
our $libdir = "";
|
our $libdir = "";
|
||||||
our $ldflags = "";
|
our $ldflags = "";
|
||||||
our $math = "-lm";
|
our $math = "-lm";
|
||||||
|
our $thread = "-lpthread";
|
||||||
our $shared = "-shared";
|
our $shared = "-shared";
|
||||||
our $backend = "";
|
our $backend = "";
|
||||||
|
|
||||||
@@ -142,7 +143,7 @@ print(OUT "INCDIR = ${incdir}\n");
|
|||||||
print(OUT "CFLAGS = ${cflags}\n");
|
print(OUT "CFLAGS = ${cflags}\n");
|
||||||
print(OUT "LIBDIR = ${libdir}\n");
|
print(OUT "LIBDIR = ${libdir}\n");
|
||||||
print(OUT "LDFLAGS = ${ldflags}\n");
|
print(OUT "LDFLAGS = ${ldflags}\n");
|
||||||
print(OUT "LIBS = ${math} ${libs}\n");
|
print(OUT "LIBS = ${math} ${thread} ${libs}\n");
|
||||||
print(OUT "MATH = ${math}\n");
|
print(OUT "MATH = ${math}\n");
|
||||||
print(OUT "SHARED = ${shared}\n");
|
print(OUT "SHARED = ${shared}\n");
|
||||||
print(OUT "\n");
|
print(OUT "\n");
|
||||||
|
|||||||
43
include/Mw/Abstract/Mutex.h
Normal file
43
include/Mw/Abstract/Mutex.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
/*!
|
||||||
|
* @file Mw/Abstract/Mutex.h
|
||||||
|
* @brief Mutex
|
||||||
|
*/
|
||||||
|
#ifndef __MW_ABSTRACT_MUTEX_H__
|
||||||
|
#define __MW_ABSTRACT_MUTEX_H__
|
||||||
|
|
||||||
|
#include <Mw/MachDep.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Creates a mutex
|
||||||
|
* @return Handle
|
||||||
|
*/
|
||||||
|
MWDECL void* MwMutexCreate(void);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Destroys a mutex
|
||||||
|
* @param handle Handle
|
||||||
|
*/
|
||||||
|
MWDECL void MwMutexDestroy(void* handle);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Locks a mutex
|
||||||
|
* @param handle Handle
|
||||||
|
*/
|
||||||
|
MWDECL void MwMutexLock(void* handle);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Unlocks a mutex
|
||||||
|
* @param handle Handle
|
||||||
|
*/
|
||||||
|
MWDECL void MwMutexUnlock(void* handle);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <Mw/Abstract/Dynamic.h>
|
#include <Mw/Abstract/Dynamic.h>
|
||||||
#include <Mw/Abstract/Directory.h>
|
#include <Mw/Abstract/Directory.h>
|
||||||
#include <Mw/Abstract/Time.h>
|
#include <Mw/Abstract/Time.h>
|
||||||
|
#include <Mw/Abstract/Mutex.h>
|
||||||
|
|
||||||
#include <Mw/Resource/Icon.h>
|
#include <Mw/Resource/Icon.h>
|
||||||
#include <Mw/Resource/Cursor.h>
|
#include <Mw/Resource/Cursor.h>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ $library_prefix = "";
|
|||||||
$library_suffix = ".dll";
|
$library_suffix = ".dll";
|
||||||
$executable_suffix = ".exe";
|
$executable_suffix = ".exe";
|
||||||
$math = "";
|
$math = "";
|
||||||
|
$thread = "";
|
||||||
add_ldflags("-Wl,--out-implib,src/libMw.a -static-libgcc");
|
add_ldflags("-Wl,--out-implib,src/libMw.a -static-libgcc");
|
||||||
use_backend("gdi");
|
use_backend("gdi");
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,28 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
void* MwDynamicOpen(const char* path) {
|
void* MwDynamicOpen(const char* path) {
|
||||||
#ifdef _WIN32
|
|
||||||
return LoadLibrary(path);
|
return LoadLibrary(path);
|
||||||
#else
|
|
||||||
return dlopen(path, RTLD_LAZY | RTLD_LOCAL);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void* MwDynamicSymbol(void* handle, const char* symbol) {
|
void* MwDynamicSymbol(void* handle, const char* symbol) {
|
||||||
#ifdef _WIN32
|
|
||||||
return GetProcAddress(handle, symbol);
|
return GetProcAddress(handle, symbol);
|
||||||
#else
|
|
||||||
return dlsym(handle, symbol);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwDynamicClose(void* handle) {
|
void MwDynamicClose(void* handle) {
|
||||||
#ifdef _WIN32
|
|
||||||
FreeLibrary(handle);
|
FreeLibrary(handle);
|
||||||
#else
|
|
||||||
dlclose(handle);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#elif defined(__unix__)
|
||||||
|
void* MwDynamicOpen(const char* path) {
|
||||||
|
return dlopen(path, RTLD_LOCAL | RTLD_LAZY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* MwDynamicSymbol(void* handle, const char* symbol) {
|
||||||
|
return dlsym(handle, symbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MwDynamicClose(void* handle) {
|
||||||
|
dlclose(handle);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
44
src/abstract/mutex.c
Normal file
44
src/abstract/mutex.c
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
void* MwMutexCreate(void) {
|
||||||
|
return CreateEvent(NULL, FALSE, TRUE, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MwMutexDestroy(void* handle) {
|
||||||
|
CloseHandle(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MwMutexLock(void* handle) {
|
||||||
|
WaitForSingleObject(handle, INFINITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MwMutexUnlock(void* handle) {
|
||||||
|
SetEvent(handle);
|
||||||
|
}
|
||||||
|
#elif defined(__unix__)
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
void* MwMutexCreate(void) {
|
||||||
|
pthread_mutex_t* m = malloc(sizeof(*m));
|
||||||
|
|
||||||
|
pthread_mutex_init(m, NULL);
|
||||||
|
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MwMutexDestroy(void* handle) {
|
||||||
|
pthread_mutex_destroy(handle);
|
||||||
|
|
||||||
|
free(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MwMutexLock(void* handle) {
|
||||||
|
pthread_mutex_lock(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MwMutexUnlock(void* handle) {
|
||||||
|
pthread_mutex_unlock(handle);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#if defined(_WIN32)
|
||||||
long MwTimeGetTick(void) {
|
long MwTimeGetTick(void) {
|
||||||
return GetTickCount();
|
return GetTickCount();
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ long MwTimeGetTick(void) {
|
|||||||
void MwTimeSleep(int ms) {
|
void MwTimeSleep(int ms) {
|
||||||
Sleep(ms);
|
Sleep(ms);
|
||||||
}
|
}
|
||||||
#else
|
#elif defined(__unix__)
|
||||||
long MwTimeGetTick(void) {
|
long MwTimeGetTick(void) {
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
long n = 0;
|
long n = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user