Skip to content

Commit

Permalink
partial native implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex D committed Jul 28, 2017
1 parent b0fdafa commit aa50d90
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,27 @@ namespace CoreLib { namespace System {
// Method : string.this[int].get
char16_t String::get_Chars(int32_t index)
{
throw 3221274624U;
return ((char16_t*)&this->_firstChar)[index];
}

// Method : string.Length.get
int32_t String::get_Length()
{
throw 3221274624U;
return this->m_stringLength;
}

// Method : string.FastAllocateString(int)
string* String::FastAllocateString(int32_t length)
{
throw 3221274624U;
}
auto size = sizeof(string) + (length + 1) * sizeof(char16_t);
#ifdef NDEBUG
auto str = new ((size_t)size) string;
#else
auto str = new ((size_t)size, __FILE__, __LINE__) string;
#endif
str->m_stringLength = length;
return str;
}

// Method : string.IsFastSort()
bool String::IsFastSort()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,115 +5,195 @@ namespace CoreLib { namespace System { namespace Threading {
// Method : System.Threading.Interlocked.Exchange(ref int, int)
int32_t Interlocked::Exchange_Ref(int32_t& location1, int32_t value)
{
throw 3221274624U;
}
#ifdef _MSC_VER
return InterlockedExchange((LONG volatile*)&location1, value);
#else
__sync_synchronize();
return __sync_lock_test_and_set((int32_t volatile*)&location1, value);
#endif
}

// Method : System.Threading.Interlocked.Exchange(ref long, long)
int64_t Interlocked::Exchange_Ref(int64_t& location1, int64_t value)
{
throw 3221274624U;
}
#ifdef _MSC_VER
return InterlockedExchange64((int64_t volatile*)&location1, value);
#else
__sync_synchronize();
return __sync_lock_test_and_set((int64_t volatile*)&location1, value);
#endif
}

// Method : System.Threading.Interlocked.Exchange(ref float, float)
float Interlocked::Exchange_Ref(float& location1, float value)
{
throw 3221274624U;
}
#ifdef _MSC_VER
return InterlockedExchange((LONG volatile*)&location1, value);
#else
__sync_synchronize();
return __sync_lock_test_and_set((int32_t volatile*)&location1, value);
#endif
}

// Method : System.Threading.Interlocked.Exchange(ref double, double)
double Interlocked::Exchange_Ref(double& location1, double value)
{
throw 3221274624U;
}
#ifdef _MSC_VER
return InterlockedExchange64((int64_t volatile*)&location1, value);
#else
__sync_synchronize();
return __sync_lock_test_and_set((int64_t volatile*)&location1, value);
#endif
}

// Method : System.Threading.Interlocked.Exchange(ref object, object)
object* Interlocked::Exchange_Ref(object*& location1, object* value)
{
throw 3221274624U;
}
#ifdef _MSC_VER
return (object*)InterlockedExchangePointer((void* volatile*)&location1, value);
#else
__sync_synchronize();
return (object*)__sync_lock_test_and_set((void* volatile*)&location1, value);
#endif
}

// Method : System.Threading.Interlocked.Exchange(ref System.IntPtr, System.IntPtr)
::CoreLib::System::IntPtr Interlocked::Exchange_Ref(::CoreLib::System::IntPtr& location1, ::CoreLib::System::IntPtr value)
{
throw 3221274624U;
}
#ifdef _MSC_VER
return __init<::CoreLib::System::IntPtr>(InterlockedExchangePointer((void* volatile*)&location1->INTPTR_VALUE_FIELD, value->INTPTR_VALUE_FIELD));
#else
__sync_synchronize();
return __init<::CoreLib::System::IntPtr>(__sync_lock_test_and_set((void* volatile*)&location1->INTPTR_VALUE_FIELD, value->INTPTR_VALUE_FIELD));
#endif
}

// Method : System.Threading.Interlocked._Exchange(System.TypedReference, System.TypedReference)
void Interlocked::_Exchange(::CoreLib::System::TypedReference location1, ::CoreLib::System::TypedReference value)
{
throw 3221274624U;
}
#ifdef _MSC_VER
InterlockedExchangePointer((void* volatile*)&(location1.Value)->INTPTR_VALUE_FIELD, value.Value->INTPTR_VALUE_FIELD);
#else
__sync_synchronize();
__sync_lock_test_and_set((void* volatile*)&(location1.Value)->INTPTR_VALUE_FIELD, value.Value->INTPTR_VALUE_FIELD);
#endif
}

// Method : System.Threading.Interlocked.CompareExchange(ref int, int, int)
int32_t Interlocked::CompareExchange_Ref(int32_t& location1, int32_t value, int32_t comparand)
{
throw 3221274624U;
}
#ifdef _MSC_VER
return InterlockedCompareExchange((LONG volatile*)&location1, value, comparand);
#else
return __sync_val_compare_and_swap((int32_t volatile*)&location1, comparand, value);
#endif
}

// Method : System.Threading.Interlocked.CompareExchange(ref long, long, long)
int64_t Interlocked::CompareExchange_Ref(int64_t& location1, int64_t value, int64_t comparand)
{
throw 3221274624U;
}
#ifdef _MSC_VER
return InterlockedCompareExchange64((int64_t volatile*)&location1, value, comparand);
#else
return __sync_val_compare_and_swap((int64_t volatile*)&location1, comparand, value);
#endif
}

// Method : System.Threading.Interlocked.CompareExchange(ref float, float, float)
float Interlocked::CompareExchange_Ref(float& location1, float value, float comparand)
{
throw 3221274624U;
}
#ifdef _MSC_VER
return InterlockedCompareExchange((LONG volatile*)&location1, value, comparand);
#else
return __sync_val_compare_and_swap((int32_t volatile*)&location1, comparand, value);
#endif
}

// Method : System.Threading.Interlocked.CompareExchange(ref double, double, double)
double Interlocked::CompareExchange_Ref(double& location1, double value, double comparand)
{
throw 3221274624U;
}
#ifdef _MSC_VER
return InterlockedCompareExchange64((int64_t volatile*)&location1, value, comparand);
#else
return __sync_val_compare_and_swap((int64_t volatile*)&location1, comparand, value);
#endif
}

// Method : System.Threading.Interlocked.CompareExchange(ref object, object, object)
object* Interlocked::CompareExchange_Ref(object*& location1, object* value, object* comparand)
{
throw 3221274624U;
}
#ifdef _MSC_VER
return (object*)InterlockedCompareExchangePointer((void* volatile*)&location1, value, comparand);
#else
return (object*)__sync_val_compare_and_swap((void* volatile*)&location1, comparand, value);
#endif
}

// Method : System.Threading.Interlocked.CompareExchange(ref System.IntPtr, System.IntPtr, System.IntPtr)
::CoreLib::System::IntPtr Interlocked::CompareExchange_Ref(::CoreLib::System::IntPtr& location1, ::CoreLib::System::IntPtr value, ::CoreLib::System::IntPtr comparand)
{
throw 3221274624U;
}
#ifdef _MSC_VER
return __init<::CoreLib::System::IntPtr>(InterlockedCompareExchangePointer((void* volatile*)&location1->INTPTR_VALUE_FIELD, value->INTPTR_VALUE_FIELD, comparand->INTPTR_VALUE_FIELD));
#else
return __init<::CoreLib::System::IntPtr>(__sync_val_compare_and_swap((void* volatile*)&location1->INTPTR_VALUE_FIELD, comparand->INTPTR_VALUE_FIELD, value->INTPTR_VALUE_FIELD));
#endif
}

// Method : System.Threading.Interlocked._CompareExchange(System.TypedReference, System.TypedReference, object)
void Interlocked::_CompareExchange(::CoreLib::System::TypedReference location1, ::CoreLib::System::TypedReference value, object* comparand)
{
throw 3221274624U;
}
#ifdef _MSC_VER
InterlockedCompareExchangePointer((void* volatile*)&(location1.Value)->INTPTR_VALUE_FIELD, value.Value->INTPTR_VALUE_FIELD, comparand);
#else
__sync_val_compare_and_swap((void* volatile*)&(location1.Value)->INTPTR_VALUE_FIELD, comparand, value.Value->INTPTR_VALUE_FIELD);
#endif
}

// Method : System.Threading.Interlocked.CompareExchange(ref int, int, int, ref bool)
int32_t Interlocked::CompareExchange_Ref_Ref(int32_t& location1, int32_t value, int32_t comparand, bool& succeeded)
{
throw 3221274624U;
}
#ifdef _MSC_VER
int32_t val = *(int32_t*)location1;
int32_t val_after = InterlockedCompareExchange((LONG volatile*)&location1, value, comparand);
succeeded = val != val_after;
return val_after;
#else
auto val = *(int32_t*)location1;
succeeded = __sync_bool_compare_and_swap((int32_t volatile*)&location1, comparand, value);
return val;
#endif
}

// Method : System.Threading.Interlocked.ExchangeAdd(ref int, int)
int32_t Interlocked::ExchangeAdd_Ref(int32_t& location1, int32_t value)
{
throw 3221274624U;
}
#ifdef _MSC_VER
return InterlockedExchangeAdd((LONG volatile*)&location1, value);
#else
return __sync_fetch_and_add((int32_t volatile*)&location1, value);
#endif
}

// Method : System.Threading.Interlocked.ExchangeAdd(ref long, long)
int64_t Interlocked::ExchangeAdd_Ref(int64_t& location1, int64_t value)
{
throw 3221274624U;
}
#ifdef _MSC_VER
return InterlockedExchangeAdd64((int64_t volatile*)&location1, value);
#else
return __sync_fetch_and_add((int64_t volatile*)&location1, value);
#endif
}

// Method : System.Threading.Interlocked.MemoryBarrier()
void Interlocked::MemoryBarrier()
{
throw 3221274624U;
std::atomic_thread_fence(std::memory_order_relaxed);
}

// Method : System.Threading.Interlocked._MemoryBarrierProcessWide()
void Interlocked::_MemoryBarrierProcessWide()
{
throw 3221274624U;
std::atomic_thread_fence(std::memory_order_relaxed);
}

}}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,99 @@ namespace CoreLib { namespace System { namespace Threading {
// Method : System.Threading.Monitor.Enter(object)
void Monitor::Enter(object* obj)
{
throw 3221274624U;
}
auto object_extras = __object_extras_storage_instance->operator[](obj);
object_extras->monitor.lock();
}

// Method : System.Threading.Monitor.ReliableEnter(object, ref bool)
void Monitor::ReliableEnter_Ref(object* obj, bool& lockTaken)
{
throw 3221274624U;
}
if (obj == nullptr)
{
throw __new<::CoreLib::System::ArgumentNullException>();
}

auto object_extras = __object_extras_storage_instance->operator[](obj);
lockTaken = object_extras->monitor.try_lock_for(std::chrono::milliseconds::max());
}

// Method : System.Threading.Monitor.Exit(object)
void Monitor::Exit(object* obj)
{
throw 3221274624U;
}
if (obj == nullptr)
{
throw __new<::CoreLib::System::ArgumentNullException>();
}

auto object_extras = __object_extras_storage_instance->operator[](obj);
object_extras->monitor.unlock();
}

// Method : System.Threading.Monitor.ReliableEnterTimeout(object, int, ref bool)
void Monitor::ReliableEnterTimeout_Ref(object* obj, int32_t timeout, bool& lockTaken)
{
throw 3221274624U;
}
if (obj == nullptr)
{
throw __new<::CoreLib::System::ArgumentNullException>();
}

auto object_extras = __object_extras_storage_instance->operator[](obj);
lockTaken = object_extras->monitor.try_lock_for(std::chrono::milliseconds(timeout));
}

// Method : System.Threading.Monitor.IsEnteredNative(object)
bool Monitor::IsEnteredNative(object* obj)
{
throw 3221274624U;
}
if (obj == nullptr)
{
throw __new<::CoreLib::System::ArgumentNullException>();
}

auto object_extras = __object_extras_storage_instance->operator[](obj);
auto lockTaken = object_extras->monitor.try_lock_for(std::chrono::milliseconds(1));
if (lockTaken)
{
object_extras->monitor.unlock();
}

return !lockTaken;
}

// Method : System.Threading.Monitor.ObjWait(bool, int, object)
bool Monitor::ObjWait(bool exitContext, int32_t millisecondsTimeout, object* obj)
{
throw 3221274624U;
}
if (obj == nullptr)
{
throw __new<::CoreLib::System::ArgumentNullException>();
}

auto object_extras = __object_extras_storage_instance->operator[](obj);
return std::cv_status::no_timeout == object_extras->monitor.wait_for(millisecondsTimeout == -1 ? std::chrono::milliseconds::max() : std::chrono::milliseconds(millisecondsTimeout));
}

// Method : System.Threading.Monitor.ObjPulse(object)
void Monitor::ObjPulse(object* obj)
{
throw 3221274624U;
}
if (obj == nullptr)
{
throw __new<::CoreLib::System::ArgumentNullException>();
}

auto object_extras = __object_extras_storage_instance->operator[](obj);
object_extras->monitor.notify_one();
}

// Method : System.Threading.Monitor.ObjPulseAll(object)
void Monitor::ObjPulseAll(object* obj)
{
throw 3221274624U;
}
if (obj == nullptr)
{
throw __new<::CoreLib::System::ArgumentNullException>();
}

auto object_extras = __object_extras_storage_instance->operator[](obj);
object_extras->monitor.notify_all();
}

}}}

Expand Down
Binary file modified Il2Native.Logic/Resources/System_Private_CoreLibImpl.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion Il2Native/Il2Native.CmdLine.csproj.user
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartArguments>/release HelloWorld.cs /corelib:System.Private.CoreLib</StartArguments>
<StartArguments>/release HelloWorld.cs /ref:System.Console /corelib:System.Private.CoreLib</StartArguments>
<StartWorkingDirectory>C:\Temp\cs2cpp_tries\</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
Expand Down

0 comments on commit aa50d90

Please sign in to comment.