Decouple <cstdint>

This commit is contained in:
Martin Natano
2023-04-21 22:13:41 +02:00
parent bcea05dd67
commit aa87f85eef
167 changed files with 1533 additions and 1307 deletions
+8 -6
View File
@@ -1,6 +1,8 @@
#ifndef THREADS_H
#define THREADS_H
#include <cstdint>
/* This is the low-level implementation; you probably want RageThreads. */
class RageMutex;
class RageTimer;
@@ -16,7 +18,7 @@ public:
* implementation-defined, except that each thread has exactly one ID
* and each ID corresponds to one thread. (This means that Win32
* thread handles are not acceptable as ThreadIds.) */
virtual uint64_t GetThreadId() const = 0;
virtual std::uint64_t GetThreadId() const = 0;
virtual int Wait() = 0;
};
@@ -69,23 +71,23 @@ public:
};
// These functions must be implemented by the thread implementation.
ThreadImpl *MakeThread( int (*fn)(void *), void *data, uint64_t *piThreadID );
ThreadImpl *MakeThread( int (*fn)(void *), void *data, std::uint64_t *piThreadID );
ThreadImpl *MakeThisThread();
MutexImpl *MakeMutex( RageMutex *pParent );
EventImpl *MakeEvent( MutexImpl *pMutex );
SemaImpl *MakeSemaphore( int iInitialValue );
uint64_t GetThisThreadId();
std::uint64_t GetThisThreadId();
/* Since ThreadId is implementation-defined, we can't define a universal
* invalid value. Return the invalid value for this implementation. */
uint64_t GetInvalidThreadId();
std::uint64_t GetInvalidThreadId();
#endif
/*
* (c) 2001-2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -95,7 +97,7 @@ uint64_t GetInvalidThreadId();
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+6 -5
View File
@@ -5,8 +5,9 @@
#include "RageThreads.h"
#include "RageUtil.h"
#include <cerrno>
#include <cstddef>
#include <errno.h>
#include <cstdint>
#include <sys/time.h>
#if defined(UNIX)
@@ -37,7 +38,7 @@ void ThreadImpl_Pthreads::Resume()
ResumeThread( threadHandle );
}
uint64_t ThreadImpl_Pthreads::GetThreadId() const
std::uint64_t ThreadImpl_Pthreads::GetThreadId() const
{
return threadHandle;
}
@@ -78,7 +79,7 @@ static void *StartThread( void *pData )
return new int(iRet);
}
ThreadImpl *MakeThread( int (*pFunc)(void *pData), void *pData, uint64_t *piThreadID )
ThreadImpl *MakeThread( int (*pFunc)(void *pData), void *pData, std::uint64_t *piThreadID )
{
ThreadImpl_Pthreads *thread = new ThreadImpl_Pthreads;
thread->m_pFunc = pFunc;
@@ -226,12 +227,12 @@ void MutexImpl_Pthreads::Unlock()
pthread_mutex_unlock( &mutex );
}
uint64_t GetThisThreadId()
std::uint64_t GetThisThreadId()
{
return GetCurrentThreadId();
}
uint64_t GetInvalidThreadId()
std::uint64_t GetInvalidThreadId()
{
return 0;
}
+5 -3
View File
@@ -3,6 +3,8 @@
#include "Threads.h"
#include <cstdint>
#include <pthread.h>
#include <semaphore.h>
@@ -16,17 +18,17 @@ public:
* Keep a list of child PIDs, so we can send them SIGKILL. This has
* an added bonus: if this is corrupted, we'll just send signals and
* they'll fail; we won't blow up (unless we're root). */
uint64_t threadHandle;
std::uint64_t threadHandle;
// These are only used during initialization.
int (*m_pFunc)( void *pData );
void *m_pData;
uint64_t *m_piThreadID;
std::uint64_t *m_piThreadID;
SemaImpl *m_StartFinishedSem;
void Halt( bool Kill );
void Resume();
uint64_t GetThreadId() const;
std::uint64_t GetThreadId() const;
int Wait();
};
+16 -14
View File
@@ -5,6 +5,8 @@
#include "RageTimer.h"
#include "archutils/Win32/ErrorStrings.h"
#include <cstdint>
const int MAX_THREADS=128;
static MutexImpl_Win32 *g_pThreadIdMutex = nullptr;
@@ -15,10 +17,10 @@ static void InitThreadIdMutex()
g_pThreadIdMutex = new MutexImpl_Win32(nullptr);
}
static uint64_t g_ThreadIds[MAX_THREADS];
static std::uint64_t g_ThreadIds[MAX_THREADS];
static HANDLE g_ThreadHandles[MAX_THREADS];
HANDLE Win32ThreadIdToHandle( uint64_t iID )
HANDLE Win32ThreadIdToHandle( std::uint64_t iID )
{
for( int i = 0; i < MAX_THREADS; ++i )
{
@@ -42,9 +44,9 @@ void ThreadImpl_Win32::Resume()
ResumeThread( ThreadHandle );
}
uint64_t ThreadImpl_Win32::GetThreadId() const
std::uint64_t ThreadImpl_Win32::GetThreadId() const
{
return (uint64_t) ThreadId;
return (std::uint64_t) ThreadId;
}
int ThreadImpl_Win32::Wait()
@@ -109,7 +111,7 @@ static DWORD WINAPI StartThread( LPVOID pData )
return ret;
}
static int GetOpenSlot( uint64_t iID )
static int GetOpenSlot( std::uint64_t iID )
{
InitThreadIdMutex();
@@ -135,7 +137,7 @@ ThreadImpl *MakeThisThread()
SetThreadName( GetCurrentThreadId(), RageThread::GetCurrentThreadName() );
const HANDLE CurProc = GetCurrentProcess();
int ret = DuplicateHandle( CurProc, GetCurrentThread(), CurProc,
int ret = DuplicateHandle( CurProc, GetCurrentThread(), CurProc,
&thread->ThreadHandle, 0, false, DUPLICATE_SAME_ACCESS );
if( !ret )
@@ -154,14 +156,14 @@ ThreadImpl *MakeThisThread()
return thread;
}
ThreadImpl *MakeThread( int (*pFunc)(void *pData), void *pData, uint64_t *piThreadID )
ThreadImpl *MakeThread( int (*pFunc)(void *pData), void *pData, std::uint64_t *piThreadID )
{
ThreadImpl_Win32 *thread = new ThreadImpl_Win32;
thread->m_pFunc = pFunc;
thread->m_pData = pData;
thread->ThreadHandle = CreateThread( nullptr, 0, &StartThread, thread, CREATE_SUSPENDED, &thread->ThreadId );
*piThreadID = (uint64_t) thread->ThreadId;
*piThreadID = (std::uint64_t) thread->ThreadId;
ASSERT_M( thread->ThreadHandle != nullptr, ssprintf("%s", werr_ssprintf(GetLastError(), "CreateThread").c_str() ) );
int slot = GetOpenSlot( thread->ThreadId );
@@ -247,12 +249,12 @@ void MutexImpl_Win32::Unlock()
sm_crash( werr_ssprintf( GetLastError(), "ReleaseMutex failed" ) );
}
uint64_t GetThisThreadId()
std::uint64_t GetThisThreadId()
{
return GetCurrentThreadId();
}
uint64_t GetInvalidThreadId()
std::uint64_t GetInvalidThreadId()
{
return 0;
}
@@ -452,12 +454,12 @@ void SemaImpl_Win32::Post()
bool SemaImpl_Win32::Wait()
{
int len = 15000;
int len = 15000;
int tries = 5;
while( tries-- )
{
/* Wait for 15 seconds. If it takes longer than that, we're
/* Wait for 15 seconds. If it takes longer than that, we're
* probably deadlocked. */
if( SimpleWaitForSingleObject( sem, len ) )
{
@@ -491,7 +493,7 @@ SemaImpl *MakeSemaphore( int iInitialValue )
/*
* (c) 2001-2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -501,7 +503,7 @@ SemaImpl *MakeSemaphore( int iInitialValue )
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+6 -4
View File
@@ -1,6 +1,8 @@
#ifndef THREADS_WIN32_H
#define THREADS_WIN32_H
#include <cstdint>
#include "Threads.h"
#if defined(_WINDOWS)
# include <windows.h>
@@ -19,11 +21,11 @@ public:
void Halt( bool Kill );
void Resume();
uint64_t GetThreadId() const;
std::uint64_t GetThreadId() const;
int Wait();
};
HANDLE Win32ThreadIdToHandle( uint64_t iID );
HANDLE Win32ThreadIdToHandle( std::uint64_t iID );
class MutexImpl_Win32: public MutexImpl
{
@@ -82,7 +84,7 @@ private:
/*
* (c) 2001-2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -92,7 +94,7 @@ private:
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF