Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: MinGW fixes for master #43

Open
wants to merge 1 commit into
base: ldc
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 11 additions & 63 deletions std/stdio.d
Original file line number Diff line number Diff line change
Expand Up @@ -215,54 +215,10 @@ else version (MINGW_IO)
extern (C)
{
int setmode(int, int);
int fgetwc(FILE*);
int fputwc(wchar_t, FILE*);
}

import core.sync.mutex;

__gshared Mutex lockMutex;
__gshared Mutex[uint] fileLocks;

void flockfile(FILE* fp)
{
Mutex mutex;

if (lockMutex is null)
lockMutex = new Mutex;

lockMutex.lock();

if (fp._file in fileLocks)
{
mutex = fileLocks[fp._file];
}
else
{
mutex = new Mutex();
fileLocks[fp._file] = mutex;
}
mutex.lock();

lockMutex.unlock();
}

void funlockfile(FILE* fp)
{
Mutex mutex;

if (lockMutex is null)
lockMutex = new Mutex;
lockMutex.lock();

if (fp._file in fileLocks)
{
mutex = fileLocks[fp._file];
mutex.unlock();
} else
{ /* Should this be an error */ }
lockMutex.unlock();
}


int fputc_unlocked(int c, _iobuf* fp) { return fputc(c, cast(shared) fp); }
int fputwc_unlocked(int c, _iobuf* fp)
{
Expand All @@ -271,24 +227,16 @@ else version (MINGW_IO)
int fgetc_unlocked(_iobuf* fp) { return fgetc(cast(shared) fp); }
int fgetwc_unlocked(_iobuf* fp) { return fgetwc(cast(shared) fp); }

extern (C)
{
nothrow:
@nogc:
FILE* _fdopen(int, const (char)*);
}

alias fputc_unlocked FPUTC;
alias fputwc_unlocked FPUTWC;
alias fgetc_unlocked FGETC;
alias fgetwc_unlocked FGETWC;
alias FPUTC = fputc_unlocked;
alias FPUTWC = fputwc_unlocked;
alias FGETC = fgetc_unlocked;
alias FGETWC = fgetwc_unlocked;

alias flockfile FLOCK;
alias funlockfile FUNLOCK;
alias FLOCK = _lock_file;
alias FUNLOCK = _unlock_file;

alias setmode _setmode;
int _fileno(FILE* f) { return f._file; }
alias _fileno fileno;
alias _setmode = setmode;
alias _fileno = fileno;

enum
{
Expand Down Expand Up @@ -5100,7 +5048,7 @@ private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator, File.Orie
encode(buf, c);
}
}
if (ferror(fp))
if (ferror(fps))
StdioException();
return buf.length;
}
Expand Down