Ported debug file locking mechanism to win32

This commit is contained in:
Mark Vejvoda
2010-04-13 17:09:49 +00:00
parent feb61e0598
commit 0657004da2
4 changed files with 13 additions and 8 deletions

Binary file not shown.

View File

@@ -136,7 +136,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="wxbase28.lib wxbase28_net.lib wxbase28_xml.lib wxexpat.lib wxjpeg.lib wxmsw28_adv.lib wxmsw28_aui.lib wxmsw28_core.lib wxmsw28_gl.lib wxmsw28_html.lib wxmsw28_media.lib wxmsw28_qa.lib wxmsw28_richtext.lib wxmsw28_xrc.lib wxpng.lib wxregex.lib wxtiff.lib wxzlib.lib winmm.lib rpcrt4.lib kernel32.lib user32.lib gdi32.lib ole32.lib oleaut32.lib comctl32.lib comdlg32.lib uuid.lib advapi32.lib shell32.lib libglest.lib xerces-c_3.lib" AdditionalDependencies="wxbase28.lib wxbase28_net.lib wxbase28_xml.lib wxexpat.lib wxjpeg.lib wxmsw28_adv.lib wxmsw28_aui.lib wxmsw28_core.lib wxmsw28_gl.lib wxmsw28_html.lib wxmsw28_media.lib wxmsw28_qa.lib wxmsw28_richtext.lib wxmsw28_xrc.lib wxpng.lib wxregex.lib wxtiff.lib wxzlib.lib winmm.lib rpcrt4.lib kernel32.lib user32.lib gdi32.lib ole32.lib oleaut32.lib comctl32.lib comdlg32.lib uuid.lib advapi32.lib shell32.lib libglest.lib xerces-c_3.lib sdl.lib sdlmain.lib dsound.lib dxguid.lib Dbghelp.lib"
OutputFile="$(OutDir)\$(ProjectName).exe" OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="2" LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../build/$(ConfigurationName)/libglest&quot;;../../source/win32_deps/lib" AdditionalLibraryDirectories="&quot;../../build/$(ConfigurationName)/libglest&quot;;../../source/win32_deps/lib"

View File

@@ -137,7 +137,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="wxbase28.lib wxbase28_net.lib wxbase28_xml.lib wxexpat.lib wxjpeg.lib wxmsw28_adv.lib wxmsw28_aui.lib wxmsw28_core.lib wxmsw28_gl.lib wxmsw28_html.lib wxmsw28_media.lib wxmsw28_qa.lib wxmsw28_richtext.lib wxmsw28_xrc.lib wxpng.lib wxregex.lib wxtiff.lib wxzlib.lib winmm.lib rpcrt4.lib kernel32.lib user32.lib gdi32.lib ole32.lib oleaut32.lib comctl32.lib comdlg32.lib uuid.lib advapi32.lib shell32.lib libglest.lib" AdditionalDependencies="wxbase28.lib wxbase28_net.lib wxbase28_xml.lib wxexpat.lib wxjpeg.lib wxmsw28_adv.lib wxmsw28_aui.lib wxmsw28_core.lib wxmsw28_gl.lib wxmsw28_html.lib wxmsw28_media.lib wxmsw28_qa.lib wxmsw28_richtext.lib wxmsw28_xrc.lib wxpng.lib wxregex.lib wxtiff.lib wxzlib.lib winmm.lib rpcrt4.lib kernel32.lib user32.lib gdi32.lib ole32.lib oleaut32.lib comctl32.lib comdlg32.lib uuid.lib advapi32.lib shell32.lib libglest.lib sdl.lib sdlmain.lib dsound.lib dxguid.lib Dbghelp.lib"
OutputFile="$(OutDir)\$(ProjectName).exe" OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="2" LinkIncremental="2"
AdditionalLibraryDirectories="../../source/win32_deps/lib;&quot;../../build/$(ConfigurationName)/libglest&quot;" AdditionalLibraryDirectories="../../source/win32_deps/lib;&quot;../../build/$(ConfigurationName)/libglest&quot;"

View File

@@ -18,11 +18,11 @@
#include <cstdio> #include <cstdio>
#include <stdarg.h> #include <stdarg.h>
#include <time.h> #include <time.h>
#include <fcntl.h> // for open()
#ifndef WIN32 #ifdef WIN32
#include <fcntl.h> // for open()
#else
#include <io.h> // for open() #include <io.h> // for open()
#include <sys/stat.h> // for open()
#endif #endif
#include "platform_util.h" #include "platform_util.h"
@@ -44,12 +44,17 @@ string SystemFlags::lockfilename = "";
inline bool acquire_file_lock(int hnd) inline bool acquire_file_lock(int hnd)
{ {
#ifndef WIN32
struct ::flock lock; struct ::flock lock;
lock.l_type = F_WRLCK; lock.l_type = F_WRLCK;
lock.l_whence = SEEK_SET; lock.l_whence = SEEK_SET;
lock.l_start = 0; lock.l_start = 0;
lock.l_len = 0; lock.l_len = 0;
return -1 != ::fcntl(hnd, F_SETLK, &lock); return -1 != ::fcntl(hnd, F_SETLK, &lock);
#else
HANDLE hFile = (HANDLE)_get_osfhandle(hnd);
return true == ::LockFile(hFile, 0, 0, 0, -0x10000);
#endif
} }
SystemFlags::SystemFlags() { SystemFlags::SystemFlags() {
@@ -66,7 +71,7 @@ void SystemFlags::Close() {
SystemFlags::fileStream.close(); SystemFlags::fileStream.close();
} }
if(SystemFlags::lockfilename != "") { if(SystemFlags::lockfilename != "") {
close(SystemFlags::lockFile); _close(SystemFlags::lockFile);
remove(SystemFlags::lockfilename.c_str()); remove(SystemFlags::lockfilename.c_str());
SystemFlags::lockfilename = ""; SystemFlags::lockfilename = "";
} }
@@ -104,14 +109,14 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
//SystemFlags::lockFile = open(lockfile.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR|S_IWUSR); //SystemFlags::lockFile = open(lockfile.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR|S_IWUSR);
SystemFlags::lockFile = open(lockfile.c_str(), O_WRONLY | O_CREAT, S_IRUSR|S_IWUSR); SystemFlags::lockFile = _open(lockfile.c_str(), O_WRONLY | O_CREAT, S_IREAD | S_IWRITE);
if (SystemFlags::lockFile < 0 || acquire_file_lock(SystemFlags::lockFile) == false) { if (SystemFlags::lockFile < 0 || acquire_file_lock(SystemFlags::lockFile) == false) {
string newlockfile = lockfile; string newlockfile = lockfile;
int idx = 1; int idx = 1;
for(idx = 1; idx <= 100; ++idx) { for(idx = 1; idx <= 100; ++idx) {
newlockfile = lockfile + intToStr(idx); newlockfile = lockfile + intToStr(idx);
//SystemFlags::lockFile = open(newlockfile.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR|S_IWUSR); //SystemFlags::lockFile = open(newlockfile.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR|S_IWUSR);
SystemFlags::lockFile = open(newlockfile.c_str(), O_WRONLY | O_CREAT, S_IRUSR|S_IWUSR); SystemFlags::lockFile = _open(newlockfile.c_str(), O_WRONLY | O_CREAT, S_IREAD | S_IWRITE);
if(SystemFlags::lockFile >= 0 && acquire_file_lock(SystemFlags::lockFile) == true) { if(SystemFlags::lockFile >= 0 && acquire_file_lock(SystemFlags::lockFile) == true) {
break; break;
} }