+ /* No need to lock here */
+ if (this->culture_info) {
+ domain = mono_domain_get ();
+ for (i = 0; i < NUM_CACHED_CULTURES; ++i) {
+ res = this->culture_info [i];
+ if (res && res->vtable->domain == domain)
+ return res;
+ }
+ }
+
+ return NULL;
+}
+
+MonoArray*
+ves_icall_System_Threading_Thread_GetSerializedCurrentCulture (MonoThread *this)
+{
+ MonoArray *res;
+
+ mono_monitor_enter (this->synch_lock);
+ if (this->serialized_culture_info) {
+ res = mono_array_new (mono_domain_get (), mono_defaults.byte_class, this->serialized_culture_info_len);
+ memcpy (mono_array_addr (res, guint8, 0), this->serialized_culture_info, this->serialized_culture_info_len);
+ }
+ else
+ res = NULL;
+ mono_monitor_exit (this->synch_lock);
+
+ return res;
+}
+
+void
+ves_icall_System_Threading_Thread_SetCachedCurrentCulture (MonoThread *this, MonoObject *culture)
+{
+ int i;
+ MonoDomain *domain = mono_domain_get ();
+
+ mono_monitor_enter (this->synch_lock);
+ if (!this->culture_info) {
+ this->culture_info = mono_gc_alloc_fixed (sizeof (MonoObject*) * NUM_CACHED_CULTURES, NULL);
+ }
+
+ for (i = 0; i < NUM_CACHED_CULTURES; ++i) {
+ if (this->culture_info [i]) {
+ if (this->culture_info [i]->vtable->domain == domain)
+ /* Replace */
+ break;
+ }
+ else
+ /* Free entry */
+ break;
+ }
+ if (i < NUM_CACHED_CULTURES)
+ this->culture_info [i] = culture;
+ mono_monitor_exit (this->synch_lock);
+}
+
+void
+ves_icall_System_Threading_Thread_SetSerializedCurrentCulture (MonoThread *this, MonoArray *arr)
+{
+ mono_monitor_enter (this->synch_lock);
+ if (this->serialized_culture_info)
+ g_free (this->serialized_culture_info);
+ this->serialized_culture_info = g_new0 (guint8, mono_array_length (arr));
+ this->serialized_culture_info_len = mono_array_length (arr);
+ memcpy (this->serialized_culture_info, mono_array_addr (arr, guint8, 0), mono_array_length (arr));
+ mono_monitor_exit (this->synch_lock);
+}
+
+
+MonoObject*
+ves_icall_System_Threading_Thread_GetCachedCurrentUICulture (MonoThread *this)
+{
+ MonoObject *res;
+ MonoDomain *domain;
+ int i;
+
+ /* No need to lock here */
+ if (this->ui_culture_info) {
+ domain = mono_domain_get ();
+ for (i = 0; i < NUM_CACHED_CULTURES; ++i) {
+ res = this->ui_culture_info [i];
+ if (res && res->vtable->domain == domain)
+ return res;
+ }
+ }
+
+ return NULL;
+}
+
+MonoArray*
+ves_icall_System_Threading_Thread_GetSerializedCurrentUICulture (MonoThread *this)
+{
+ MonoArray *res;
+
+ mono_monitor_enter (this->synch_lock);
+ if (this->serialized_ui_culture_info) {
+ res = mono_array_new (mono_domain_get (), mono_defaults.byte_class, this->serialized_ui_culture_info_len);
+ memcpy (mono_array_addr (res, guint8, 0), this->serialized_ui_culture_info, this->serialized_ui_culture_info_len);
+ }
+ else
+ res = NULL;
+ mono_monitor_exit (this->synch_lock);
+
+ return res;
+}
+
+void
+ves_icall_System_Threading_Thread_SetCachedCurrentUICulture (MonoThread *this, MonoObject *culture)
+{
+ int i;
+ MonoDomain *domain = mono_domain_get ();
+
+ mono_monitor_enter (this->synch_lock);
+ if (!this->ui_culture_info) {
+ this->ui_culture_info = mono_gc_alloc_fixed (sizeof (MonoObject*) * NUM_CACHED_CULTURES, NULL);
+ }
+
+ for (i = 0; i < NUM_CACHED_CULTURES; ++i) {
+ if (this->ui_culture_info [i]) {
+ if (this->ui_culture_info [i]->vtable->domain == domain)
+ /* Replace */
+ break;
+ }
+ else
+ /* Free entry */
+ break;
+ }
+ if (i < NUM_CACHED_CULTURES)
+ this->ui_culture_info [i] = culture;
+ mono_monitor_exit (this->synch_lock);
+}
+
+void
+ves_icall_System_Threading_Thread_SetSerializedCurrentUICulture (MonoThread *this, MonoArray *arr)
+{
+ mono_monitor_enter (this->synch_lock);
+ if (this->serialized_ui_culture_info)
+ g_free (this->serialized_ui_culture_info);
+ this->serialized_ui_culture_info = g_new0 (guint8, mono_array_length (arr));
+ this->serialized_ui_culture_info_len = mono_array_length (arr);
+ memcpy (this->serialized_ui_culture_info, mono_array_addr (arr, guint8, 0), mono_array_length (arr));
+ mono_monitor_exit (this->synch_lock);
+}