mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-08-02 11:42:25 +00:00
feat: nanosleep-based Sleep stub
This commit is contained in:
parent
065ffff071
commit
22b97a4dc0
|
|
@ -93,7 +93,8 @@ typedef RTL_CRITICAL_SECTION CRITICAL_SECTION;
|
||||||
typedef PRTL_CRITICAL_SECTION PCRITICAL_SECTION;
|
typedef PRTL_CRITICAL_SECTION PCRITICAL_SECTION;
|
||||||
typedef PRTL_CRITICAL_SECTION LPCRITICAL_SECTION;
|
typedef PRTL_CRITICAL_SECTION LPCRITICAL_SECTION;
|
||||||
|
|
||||||
void InitializeCriticalSection(PRTL_CRITICAL_SECTION CriticalSection) {
|
void InitializeCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
|
||||||
|
{
|
||||||
pthread_mutexattr_t attr;
|
pthread_mutexattr_t attr;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|
@ -103,24 +104,29 @@ void InitializeCriticalSection(PRTL_CRITICAL_SECTION CriticalSection) {
|
||||||
pthread_mutexattr_destroy(&attr);
|
pthread_mutexattr_destroy(&attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitializeCriticalSectionAndSpinCount(PRTL_CRITICAL_SECTION CriticalSection, ULONG SpinCount) {
|
void InitializeCriticalSectionAndSpinCount(PRTL_CRITICAL_SECTION CriticalSection, ULONG SpinCount)
|
||||||
|
{
|
||||||
// no spin count required because we use a recursive mutex
|
// no spin count required because we use a recursive mutex
|
||||||
InitializeCriticalSection(CriticalSection);
|
InitializeCriticalSection(CriticalSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeleteCriticalSection(PRTL_CRITICAL_SECTION CriticalSection) {
|
void DeleteCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
|
||||||
|
{
|
||||||
pthread_mutex_destroy(CriticalSection);
|
pthread_mutex_destroy(CriticalSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnterCriticalSection(PRTL_CRITICAL_SECTION CriticalSection) {
|
void EnterCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
|
||||||
|
{
|
||||||
pthread_mutex_lock(CriticalSection);
|
pthread_mutex_lock(CriticalSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LeaveCriticalSection(PRTL_CRITICAL_SECTION CriticalSection) {
|
void LeaveCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
|
||||||
|
{
|
||||||
pthread_mutex_unlock(CriticalSection);
|
pthread_mutex_unlock(CriticalSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
ULONG TryEnterCriticalSection(PRTL_CRITICAL_SECTION CriticalSection) {
|
ULONG TryEnterCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
|
||||||
|
{
|
||||||
return pthread_mutex_trylock(CriticalSection) == 0;
|
return pthread_mutex_trylock(CriticalSection) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,6 +172,18 @@ DWORD GetLastError(VOID)
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VOID Sleep(DWORD dwMilliseconds)
|
||||||
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
ts.tv_nsec = (dwMilliseconds * 1000000) % 1000000000;
|
||||||
|
ts.tv_sec = dwMilliseconds / 1000;
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
do {
|
||||||
|
ret = nanosleep(&ts, &ts);
|
||||||
|
} while (ret == -1 && errno == EINTR);
|
||||||
|
}
|
||||||
|
|
||||||
LONG64 InterlockedCompareExchangeRelease64(
|
LONG64 InterlockedCompareExchangeRelease64(
|
||||||
LONG64 volatile *Destination,
|
LONG64 volatile *Destination,
|
||||||
LONG64 Exchange,
|
LONG64 Exchange,
|
||||||
|
|
@ -176,6 +194,4 @@ LONG64 InterlockedCompareExchangeRelease64(
|
||||||
return expected;
|
return expected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // WLINUX_H
|
#endif // WLINUX_H
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue