mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 22:50:38 +03:00
add shared
This commit is contained in:
parent
7508b06d3d
commit
cf644a325a
22 changed files with 108 additions and 84 deletions
2
crc32.d
2
crc32.d
|
@ -14,7 +14,7 @@
|
|||
// CRC-32 calculation
|
||||
module crc32;
|
||||
|
||||
private uint[256] crc32_table =
|
||||
private immutable uint[256] crc32_table =
|
||||
[
|
||||
0x00000000,0x77073096,0xee0e612c,0x990951ba,0x076dc419,0x706af48f,0xe963a535,
|
||||
0x9e6495a3,0x0edb8832,0x79dcb8a4,0xe0d5e91e,0x97d2d988,0x09b64c2b,0x7eb17cbd,
|
||||
|
|
|
@ -61,7 +61,7 @@ class Base64CharException: Base64Exception
|
|||
}
|
||||
|
||||
|
||||
auto array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
immutable array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -559,8 +559,8 @@ struct BitArray
|
|||
{
|
||||
debug(bitarray) printf("BitArray.sort.unittest\n");
|
||||
|
||||
static uint x = 0b1100011000;
|
||||
static BitArray ba = { 10, &x };
|
||||
__gshared uint x = 0b1100011000;
|
||||
__gshared BitArray ba = { 10, &x };
|
||||
ba.sort;
|
||||
for (size_t i = 0; i < 6; i++)
|
||||
assert(ba[i] == false);
|
||||
|
|
|
@ -8,9 +8,22 @@
|
|||
|
||||
module std.c.linux.linux;
|
||||
|
||||
public import std.c.linux.linuxextern;
|
||||
public import std.c.linux.pthread;
|
||||
|
||||
extern (C)
|
||||
{
|
||||
extern __gshared
|
||||
{
|
||||
void* __libc_stack_end;
|
||||
int __data_start;
|
||||
int _end;
|
||||
int timezone;
|
||||
|
||||
void *_deh_beg;
|
||||
void *_deh_end;
|
||||
}
|
||||
}
|
||||
|
||||
struct struct_stat64 // distinguish it from the stat() function
|
||||
{
|
||||
ulong st_dev; /// device
|
||||
|
|
|
@ -12,14 +12,4 @@
|
|||
|
||||
module std.c.linux.linuxextern;
|
||||
|
||||
extern (C)
|
||||
{
|
||||
extern void* __libc_stack_end;
|
||||
extern int __data_start;
|
||||
extern int _end;
|
||||
extern int timezone;
|
||||
|
||||
extern void *_deh_beg;
|
||||
extern void *_deh_end;
|
||||
}
|
||||
|
||||
// No longer needed since "extern" storage class
|
||||
|
|
|
@ -17,9 +17,7 @@ extern (C):
|
|||
|
||||
version (Win32)
|
||||
{
|
||||
extern FILE _iob[_NFILE];
|
||||
extern void function() _fcloseallp;
|
||||
extern ubyte __fhnd_info[_NFILE];
|
||||
extern shared ubyte[_NFILE] __fhnd_info;
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
|
@ -208,6 +208,8 @@ private:
|
|||
AMD
|
||||
}
|
||||
|
||||
__gshared
|
||||
{
|
||||
uint flags, misc, exflags, apic, signature;
|
||||
uint _stepping, _model, _family;
|
||||
|
||||
|
@ -217,6 +219,7 @@ private:
|
|||
uint maxThreads=1;
|
||||
uint maxCores=1;
|
||||
uint manufac=OTHER;
|
||||
}
|
||||
|
||||
/* **
|
||||
* fetches the cpu vendor string
|
||||
|
|
|
@ -210,17 +210,17 @@ class CFile : Stream {
|
|||
/**
|
||||
* CFile wrapper of std.c.stdio.stdin (not seekable).
|
||||
*/
|
||||
CFile din;
|
||||
__gshared CFile din;
|
||||
|
||||
/**
|
||||
* CFile wrapper of std.c.stdio.stdout (not seekable).
|
||||
*/
|
||||
CFile dout;
|
||||
__gshared CFile dout;
|
||||
|
||||
/**
|
||||
* CFile wrapper of std.c.stdio.stderr (not seekable).
|
||||
*/
|
||||
CFile derr;
|
||||
__gshared CFile derr;
|
||||
|
||||
static this() {
|
||||
// open standard I/O devices
|
||||
|
|
|
@ -123,7 +123,7 @@ enum
|
|||
_ALP = _UC|_LC,
|
||||
}
|
||||
|
||||
ubyte _ctype[128] =
|
||||
immutable ubyte _ctype[128] =
|
||||
[
|
||||
_CTL,_CTL,_CTL,_CTL,_CTL,_CTL,_CTL,_CTL,
|
||||
_CTL,_CTL|_SPC,_CTL|_SPC,_CTL|_SPC,_CTL|_SPC,_CTL|_SPC,_CTL,_CTL,
|
||||
|
|
|
@ -88,7 +88,7 @@ unittest
|
|||
assert(ticksPerSecond == TicksPerSecond);
|
||||
}
|
||||
|
||||
d_time localTZA = 0;
|
||||
__gshared d_time localTZA = 0;
|
||||
|
||||
private immutable char[] daystr = "SunMonTueWedThuFriSat";
|
||||
private immutable char[] monstr = "JanFebMarAprMayJunJulAugSepOctNovDec";
|
||||
|
|
|
@ -252,7 +252,7 @@ private:
|
|||
short value;
|
||||
}
|
||||
|
||||
static DateID dateidtab[] =
|
||||
static immutable DateID dateidtab[] =
|
||||
[
|
||||
{ "january", DP.month, 1},
|
||||
{ "february", DP.month, 2},
|
||||
|
|
|
@ -2394,7 +2394,7 @@ abstract class EncodingScheme
|
|||
return t.length - s.length;
|
||||
}
|
||||
|
||||
static string[string] supported;
|
||||
__gshared string[string] supported;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,7 @@ version (Win32)
|
|||
* (Thanks to yaneurao for this)
|
||||
*/
|
||||
version(Windows) alias std.windows.charset.toMBSz toMBSz;
|
||||
bool useWfuncs = true; // initialized in std.__fileinit
|
||||
shared bool useWfuncs = true; // initialized in std.__fileinit
|
||||
}
|
||||
version (Posix)
|
||||
{
|
||||
|
|
|
@ -42,7 +42,7 @@ version (DigitalMarsC)
|
|||
// This is DMC's internal floating point formatting function
|
||||
extern (C)
|
||||
{
|
||||
extern char* function(int c, int flags, int precision,
|
||||
extern shared char* function(int c, int flags, int precision,
|
||||
in real* pdval,
|
||||
char* buf, size_t* psl, int width) __pfloatfmt;
|
||||
}
|
||||
|
@ -120,7 +120,8 @@ enum Mangle : char
|
|||
// routine could go away.
|
||||
private TypeInfo primitiveTypeInfo(Mangle m)
|
||||
{
|
||||
static TypeInfo[Mangle] dic;
|
||||
// BUG: should fix this in static this() to avoid double checked locking bug
|
||||
__gshared TypeInfo[Mangle] dic;
|
||||
if (!dic.length) {
|
||||
dic = [
|
||||
Mangle.Tvoid : typeid(void),
|
||||
|
|
10
std/loader.d
10
std/loader.d
|
@ -161,8 +161,8 @@ public string ExeModule_Error()
|
|||
|
||||
version(Windows)
|
||||
{
|
||||
private int s_init;
|
||||
private int s_lastError; // This is NOT thread-specific
|
||||
private __gshared int s_init;
|
||||
private __gshared int s_lastError; // This is NOT thread-specific
|
||||
|
||||
private void record_error_()
|
||||
{
|
||||
|
@ -274,9 +274,9 @@ else version(Posix)
|
|||
}
|
||||
};
|
||||
|
||||
private int s_init;
|
||||
private ExeModuleInfo [string] s_modules;
|
||||
private string s_lastError; // This is NOT thread-specific
|
||||
private __gshared int s_init;
|
||||
private __gshared ExeModuleInfo [string] s_modules;
|
||||
private __gshared string s_lastError; // This is NOT thread-specific
|
||||
|
||||
private void record_error_()
|
||||
{
|
||||
|
|
|
@ -831,7 +831,7 @@ unittest
|
|||
//__EOF__
|
||||
/* ===================== Random ========================= */
|
||||
|
||||
// BUG: not multithreaded
|
||||
// seed and index are deliberately thread local
|
||||
|
||||
private uint seed; // starting seed
|
||||
private uint index; // ith random number
|
||||
|
@ -926,7 +926,7 @@ static this()
|
|||
s = cast(ulong)((cast(long)tv.tv_sec << 32) + tv.tv_usec);
|
||||
}
|
||||
}
|
||||
rand_seed(cast(uint) s, cast(uint)(s >> 32));
|
||||
//rand_seed(cast(uint) s, cast(uint)(s >> 32));
|
||||
}
|
||||
|
||||
|
||||
|
|
97
std/stdio.d
97
std/stdio.d
|
@ -56,12 +56,14 @@ version (DIGITAL_MARS_STDIO)
|
|||
extern (C)
|
||||
{
|
||||
/* **
|
||||
* Digital Mars under-the-hood C I/O functions
|
||||
* Digital Mars under-the-hood C I/O functions.
|
||||
* Use _iobuf* for the unshared version of FILE*,
|
||||
* usable when the FILE is locked.
|
||||
*/
|
||||
int _fputc_nlock(int, FILE*);
|
||||
int _fputwc_nlock(int, FILE*);
|
||||
int _fgetc_nlock(FILE*);
|
||||
int _fgetwc_nlock(FILE*);
|
||||
int _fputc_nlock(int, _iobuf*);
|
||||
int _fputwc_nlock(int, _iobuf*);
|
||||
int _fgetc_nlock(_iobuf*);
|
||||
int _fgetwc_nlock(_iobuf*);
|
||||
int __fp_lock(FILE*);
|
||||
void __fp_unlock(FILE*);
|
||||
}
|
||||
|
@ -83,17 +85,17 @@ else version (GCC_IO)
|
|||
private import core.sys.posix.stdio;
|
||||
extern (C)
|
||||
{
|
||||
int fputc_unlocked(int, FILE*);
|
||||
int fputwc_unlocked(wchar_t, FILE*);
|
||||
int fgetc_unlocked(FILE*);
|
||||
int fgetwc_unlocked(FILE*);
|
||||
int fputc_unlocked(int, _iobuf*);
|
||||
int fputwc_unlocked(wchar_t, _iobuf*);
|
||||
int fgetc_unlocked(_iobuf*);
|
||||
int fgetwc_unlocked(_iobuf*);
|
||||
void flockfile(FILE*);
|
||||
void funlockfile(FILE*);
|
||||
ssize_t getline(char**, size_t*, FILE*);
|
||||
ssize_t getdelim (char**, size_t*, int, FILE*);
|
||||
|
||||
private size_t fwrite_unlocked(const(void)* ptr,
|
||||
size_t size, size_t n, FILE *stream);
|
||||
size_t size, size_t n, _iobuf *stream);
|
||||
}
|
||||
|
||||
version (linux)
|
||||
|
@ -787,20 +789,23 @@ $(D Range) that locks the file and allows fast writing to it.
|
|||
struct LockingTextWriter {
|
||||
//@@@ Hacky implementation due to bugs, see the correct
|
||||
//implementation at the end of this struct
|
||||
FILE * handle;
|
||||
FILE* fps; // the shared file handle
|
||||
_iobuf* handle; // the unshared version of fps
|
||||
int orientation;
|
||||
|
||||
this(ref File f)
|
||||
{
|
||||
enforce(f.p && f.p.handle);
|
||||
handle = f.p.handle;
|
||||
orientation = fwide(handle, 0);
|
||||
FLOCK(handle);
|
||||
fps = f.p.handle;
|
||||
orientation = fwide(fps, 0);
|
||||
FLOCK(fps);
|
||||
handle = cast(_iobuf*)fps;
|
||||
}
|
||||
|
||||
~this()
|
||||
{
|
||||
FUNLOCK(handle);
|
||||
FUNLOCK(fps);
|
||||
fps = null;
|
||||
handle = null;
|
||||
}
|
||||
|
||||
|
@ -816,7 +821,7 @@ $(D Range) that locks the file and allows fast writing to it.
|
|||
//file.write(writeme); causes infinite recursion!!!
|
||||
//file.rawWrite(writeme);
|
||||
auto result =
|
||||
.fwrite(writeme.ptr, C.sizeof, writeme.length, handle);
|
||||
.fwrite(writeme.ptr, C.sizeof, writeme.length, fps);
|
||||
//if (result == result.max) result = 0;
|
||||
if (result != writeme.length) errnoEnforce(0);
|
||||
}
|
||||
|
@ -955,15 +960,17 @@ $(D Range) that locks the file and allows fast writing to it.
|
|||
}
|
||||
|
||||
private
|
||||
void writefx(FILE* fp, TypeInfo[] arguments, void* argptr, int newline=false)
|
||||
void writefx(FILE* fps, TypeInfo[] arguments, void* argptr, int newline=false)
|
||||
{
|
||||
int orientation = fwide(fp, 0);
|
||||
int orientation = fwide(fps, 0); // move this inside the lock?
|
||||
|
||||
/* Do the file stream locking at the outermost level
|
||||
* rather than character by character.
|
||||
*/
|
||||
FLOCK(fp);
|
||||
scope(exit) FUNLOCK(fp);
|
||||
FLOCK(fps);
|
||||
scope(exit) FUNLOCK(fps);
|
||||
|
||||
auto fp = cast(_iobuf*)fps; // fp is locked version
|
||||
|
||||
if (orientation <= 0) // byte orientation or no orientation
|
||||
{
|
||||
|
@ -1413,7 +1420,7 @@ struct lines
|
|||
ubyte[] buffer;
|
||||
static if (Parms.length == 2)
|
||||
Parms[0] line = 0;
|
||||
while ((c = FGETC(f.p.handle)) != -1)
|
||||
while ((c = FGETC(cast(_iobuf*)f.p.handle)) != -1)
|
||||
{
|
||||
buffer ~= to!(ubyte)(c);
|
||||
if (c == terminator)
|
||||
|
@ -1709,24 +1716,29 @@ Initialize with a message and an error code. */
|
|||
|
||||
extern(C) void std_stdio_static_this()
|
||||
{
|
||||
//printf("std_stdio_static_this()\n");
|
||||
|
||||
//Bind stdin, stdout, stderr
|
||||
static File.Impl stdinImpl = { null, uint.max / 2, null };
|
||||
__gshared File.Impl stdinImpl = { null, uint.max / 2, null };
|
||||
stdinImpl.handle = core.stdc.stdio.stdin;
|
||||
.stdin.p = &stdinImpl;
|
||||
// stdout
|
||||
static File.Impl stdoutImpl = { null, uint.max / 2, null };
|
||||
__gshared File.Impl stdoutImpl = { null, uint.max / 2, null };
|
||||
stdoutImpl.handle = core.stdc.stdio.stdout;
|
||||
.stdout.p = &stdoutImpl;
|
||||
// stderr
|
||||
static File.Impl stderrImpl = { null, uint.max / 2, null };
|
||||
__gshared File.Impl stderrImpl = { null, uint.max / 2, null };
|
||||
stderrImpl.handle = core.stdc.stdio.stderr;
|
||||
.stderr.p = &stderrImpl;
|
||||
}
|
||||
|
||||
//---------
|
||||
File stdin;
|
||||
File stdout;
|
||||
File stderr;
|
||||
__gshared
|
||||
{
|
||||
File stdin;
|
||||
File stdout;
|
||||
File stderr;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
struct ByRecord(Fields...)
|
||||
|
@ -1821,12 +1833,17 @@ unittest
|
|||
}
|
||||
|
||||
// Private implementation of readln
|
||||
private size_t readlnImpl(FILE* fp, ref char[] buf, dchar terminator = '\n')
|
||||
private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator = '\n')
|
||||
{
|
||||
version (DIGITAL_MARS_STDIO)
|
||||
{
|
||||
FLOCK(fp);
|
||||
scope(exit) FUNLOCK(fp);
|
||||
FLOCK(fps);
|
||||
scope(exit) FUNLOCK(fps);
|
||||
|
||||
/* Since fps is now locked, we can create an "unshared" version
|
||||
* of fp.
|
||||
*/
|
||||
auto fp = cast(_iobuf*)fps;
|
||||
|
||||
if (__fhnd_info[fp._file] & FHND_WCHAR)
|
||||
{ /* Stream is in wide characters.
|
||||
|
@ -1856,7 +1873,7 @@ private size_t readlnImpl(FILE* fp, ref char[] buf, dchar terminator = '\n')
|
|||
std.utf.encode(buf, c);
|
||||
}
|
||||
}
|
||||
if (ferror(fp))
|
||||
if (ferror(fps))
|
||||
StdioException();
|
||||
return buf.length;
|
||||
}
|
||||
|
@ -1894,7 +1911,8 @@ private size_t readlnImpl(FILE* fp, ref char[] buf, dchar terminator = '\n')
|
|||
buf = p[0 .. i];
|
||||
{
|
||||
char[] buf2;
|
||||
readlnImpl(fp, buf2, terminator);
|
||||
// This recursively does an unnecessary lock
|
||||
readlnImpl(fps, buf2, terminator);
|
||||
buf ~= buf2;
|
||||
}
|
||||
return buf.length;
|
||||
|
@ -1905,7 +1923,7 @@ private size_t readlnImpl(FILE* fp, ref char[] buf, dchar terminator = '\n')
|
|||
return i + 1;
|
||||
}
|
||||
}
|
||||
if (ferror(fp))
|
||||
if (ferror(fps))
|
||||
StdioException();
|
||||
buf = p[0 .. i];
|
||||
return i;
|
||||
|
@ -1975,12 +1993,13 @@ private size_t readlnImpl(FILE* fp, ref char[] buf, dchar terminator = '\n')
|
|||
}
|
||||
else version (GCC_IO)
|
||||
{
|
||||
if (fwide(fp, 0) > 0)
|
||||
if (fwide(fps, 0) > 0)
|
||||
{ /* Stream is in wide characters.
|
||||
* Read them and convert to chars.
|
||||
*/
|
||||
FLOCK(fp);
|
||||
scope(exit) FUNLOCK(fp);
|
||||
FLOCK(fps);
|
||||
scope(exit) FUNLOCK(fps);
|
||||
auto fp = cast(_iobuf*)fps;
|
||||
version (Windows)
|
||||
{
|
||||
buf.length = 0;
|
||||
|
@ -2022,7 +2041,7 @@ private size_t readlnImpl(FILE* fp, ref char[] buf, dchar terminator = '\n')
|
|||
if (c == terminator)
|
||||
break;
|
||||
}
|
||||
if (ferror(fp))
|
||||
if (ferror(fps))
|
||||
StdioException();
|
||||
return buf.length;
|
||||
}
|
||||
|
@ -2034,11 +2053,11 @@ private size_t readlnImpl(FILE* fp, ref char[] buf, dchar terminator = '\n')
|
|||
|
||||
char *lineptr = null;
|
||||
size_t n = 0;
|
||||
auto s = getdelim(&lineptr, &n, terminator, fp);
|
||||
auto s = getdelim(&lineptr, &n, terminator, fps);
|
||||
scope(exit) free(lineptr);
|
||||
if (s < 0)
|
||||
{
|
||||
if (ferror(fp))
|
||||
if (ferror(fps))
|
||||
StdioException();
|
||||
buf.length = 0; // end of file
|
||||
return 0;
|
||||
|
|
|
@ -2186,13 +2186,13 @@ enum BOM {
|
|||
}
|
||||
|
||||
private const int NBOMS = 5;
|
||||
Endian[NBOMS] BOMEndian =
|
||||
immutable Endian[NBOMS] BOMEndian =
|
||||
[ std.system.endian,
|
||||
Endian.LittleEndian, Endian.BigEndian,
|
||||
Endian.LittleEndian, Endian.BigEndian
|
||||
];
|
||||
|
||||
ubyte[][NBOMS] ByteOrderMarks =
|
||||
immutable ubyte[][NBOMS] ByteOrderMarks =
|
||||
[ [0xEF, 0xBB, 0xBF],
|
||||
[0xFF, 0xFE],
|
||||
[0xFE, 0xFF],
|
||||
|
@ -2244,7 +2244,7 @@ class EndianStream : FilterStream {
|
|||
int result = -1; // the last match or -1
|
||||
for (int i=0; i < NBOMS; ++i) {
|
||||
int j;
|
||||
ubyte[] bom = ByteOrderMarks[i];
|
||||
immutable ubyte[] bom = ByteOrderMarks[i];
|
||||
for (j=0; j < bom.length; ++j) {
|
||||
if (n <= j) { // have to read more
|
||||
if (eof())
|
||||
|
@ -2380,7 +2380,7 @@ class EndianStream : FilterStream {
|
|||
|
||||
/// Write the specified BOM b to the source stream.
|
||||
void writeBOM(BOM b) {
|
||||
ubyte[] bom = ByteOrderMarks[b];
|
||||
immutable ubyte[] bom = ByteOrderMarks[b];
|
||||
writeBlock(bom.ptr, bom.length);
|
||||
}
|
||||
|
||||
|
|
|
@ -3693,7 +3693,7 @@ out (result)
|
|||
}
|
||||
body
|
||||
{
|
||||
static dex =
|
||||
static immutable dex =
|
||||
// ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
"01230120022455012623010202";
|
||||
|
||||
|
|
|
@ -187,7 +187,7 @@ dchar toUniUpper(dchar c)
|
|||
|
||||
int isUniAlpha(dchar u)
|
||||
{
|
||||
static dchar table[][2] =
|
||||
static immutable dchar table[][2] =
|
||||
[
|
||||
[ 'A', 'Z' ],
|
||||
[ 'a', 'z' ],
|
||||
|
|
|
@ -67,9 +67,9 @@ enum
|
|||
URI_Hash = 0x10, // '#'
|
||||
}
|
||||
|
||||
invariant char[16] hex2ascii = "0123456789ABCDEF";
|
||||
immutable char[16] hex2ascii = "0123456789ABCDEF";
|
||||
|
||||
ubyte[128] uri_flags; // indexed by character
|
||||
__gshared ubyte[128] uri_flags; // indexed by character
|
||||
|
||||
static this()
|
||||
{
|
||||
|
|
|
@ -228,7 +228,7 @@ SRC_STD_WIN= std\windows\registry.d \
|
|||
SRC_STD_C_WIN= std\c\windows\windows.d std\c\windows\com.d \
|
||||
std\c\windows\winsock.d std\c\windows\stat.d
|
||||
|
||||
SRC_STD_C_LINUX= std\c\linux\linux.d std\c\linux\linuxextern.d \
|
||||
SRC_STD_C_LINUX= std\c\linux\linux.d \
|
||||
std\c\linux\socket.d std\c\linux\pthread.d std\c\linux\termios.d \
|
||||
std\c\linux\tipc.d
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue