Skip to content

Commit

Permalink
Optional IMPL_CRITSET for implementation of critical sections (incomp…
Browse files Browse the repository at this point in the history
…lete)
  • Loading branch information
matpow2 committed Nov 25, 2018
1 parent 9e5aefd commit 2b77984
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions terraingen/tgen2/src/import/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <cmath>
#include "mem.h"

// #define IMPL_CRITSEC

// import: free
void free_imp(void * data)
{
Expand Down Expand Up @@ -98,13 +100,26 @@ uint32_t WSAStartup_imp(uint32_t version, uint32_t data)
bool InitializeCriticalSectionAndSpinCount_imp(uint32_t crit_sec,
uint32_t spincount)
{
#ifdef IMPL_CRITSEC
void * crit = (void*)crit_sec;
std::recursive_mutex * mut = new std::recursive_mutex();
memcpy(crit, &mut, sizeof(mut));
crit += sizeof(mut);
memcpy(crit, &spincount, sizeof(spincount));
#endif
return 1;
}

// import: DeleteCriticalSection
// stdcall
void DeleteCriticalSection_imp(uint32_t critical_section)
{
#ifdef IMPL_CRITSEC
void * crit = (void*)critical_section;
std::recursive_mutex * mut;
memcpy(&mut, crit, sizeof(mut));
delete[] mut;
#endif
std::cout << "DeleteCriticalSection" << std::endl;
}

Expand Down

0 comments on commit 2b77984

Please sign in to comment.