ddnet/src/engine/client/updater.h
bors[bot] 9dd46eb764
Merge #5260
5260: Pr thread safety negative r=heinrich5991 a=def-

WorkerThread is hard because `REQUIRES(!((CJobPool *)pUser)->m_Lock)` would require alias analysis or the function using that everywhere.

https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#negative

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Dennis Felsing <dennis@felsin9.de>
2022-06-01 11:17:30 +00:00

83 lines
1.8 KiB
C++

#ifndef ENGINE_CLIENT_UPDATER_H
#define ENGINE_CLIENT_UPDATER_H
#include <engine/updater.h>
#include <map>
#include <string>
#define CLIENT_EXEC "DDNet"
#define SERVER_EXEC "DDNet-Server"
#if defined(CONF_FAMILY_WINDOWS)
#define PLAT_EXT ".exe"
#define PLAT_NAME CONF_PLATFORM_STRING
#elif defined(CONF_FAMILY_UNIX)
#define PLAT_EXT ""
#if defined(CONF_ARCH_IA32)
#define PLAT_NAME CONF_PLATFORM_STRING "-x86"
#elif defined(CONF_ARCH_AMD64)
#define PLAT_NAME CONF_PLATFORM_STRING "-x86_64"
#else
#define PLAT_NAME CONF_PLATFORM_STRING "-unsupported"
#endif
#else
#define PLAT_EXT ""
#define PLAT_NAME "unsupported-unsupported"
#endif
#define PLAT_CLIENT_DOWN CLIENT_EXEC "-" PLAT_NAME PLAT_EXT
#define PLAT_SERVER_DOWN SERVER_EXEC "-" PLAT_NAME PLAT_EXT
#define PLAT_CLIENT_EXEC CLIENT_EXEC PLAT_EXT
#define PLAT_SERVER_EXEC SERVER_EXEC PLAT_EXT
class CUpdater : public IUpdater
{
friend class CUpdaterFetchTask;
class IClient *m_pClient;
class IStorage *m_pStorage;
class IEngine *m_pEngine;
LOCK m_Lock;
int m_State;
char m_aStatus[256] GUARDED_BY(m_Lock);
int m_Percent GUARDED_BY(m_Lock);
char m_aLastFile[256];
char m_aClientExecTmp[64];
char m_aServerExecTmp[64];
bool m_ClientUpdate;
bool m_ServerUpdate;
std::map<std::string, bool> m_FileJobs;
void AddFileJob(const char *pFile, bool Job);
void FetchFile(const char *pFile, const char *pDestPath = 0);
bool MoveFile(const char *pFile);
void ParseUpdate();
void PerformUpdate();
void CommitUpdate();
bool ReplaceClient();
bool ReplaceServer();
void SetCurrentState(int NewState) REQUIRES(!m_Lock);
public:
CUpdater();
~CUpdater();
int GetCurrentState() override REQUIRES(!m_Lock);
void GetCurrentFile(char *pBuf, int BufSize) override REQUIRES(!m_Lock);
int GetCurrentPercent() override REQUIRES(!m_Lock);
void InitiateUpdate() override;
void Init();
void Update() override;
};
#endif