mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-10-31 16:32:18 +01:00 
			
		
		
		
	thread creation: Simplify error handling
Instead of always returning non-NULL and finding out about errors via the GError*, return NULL from the backend in the event of an error.
This commit is contained in:
		| @@ -1111,8 +1111,9 @@ g_system_thread_new (GThreadFunc   thread_func, | |||||||
|   if (ret == EAGAIN) |   if (ret == EAGAIN) | ||||||
|     { |     { | ||||||
|       g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN,  |       g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN,  | ||||||
| 		   "Error creating thread: %s", g_strerror (ret)); |                    "Error creating thread: %s", g_strerror (ret)); | ||||||
|       return thread; |       g_slice_free (GRealThread, thread); | ||||||
|  |       return NULL; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   posix_check_err (ret, "pthread_create"); |   posix_check_err (ret, "pthread_create"); | ||||||
|   | |||||||
| @@ -518,7 +518,8 @@ g_system_thread_new (GThreadFunc   func, | |||||||
|                    "Error creating thread: %s", win_error); |                    "Error creating thread: %s", win_error); | ||||||
|       g_free (retval); |       g_free (retval); | ||||||
|       g_free (win_error); |       g_free (win_error); | ||||||
|       return thread; |       g_slice_free (GRealThread, thread); | ||||||
|  |       return NULL; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   *(GThreadData **) &(thread->system_thread) = retval; |   *(GThreadData **) &(thread->system_thread) = retval; | ||||||
|   | |||||||
| @@ -799,27 +799,22 @@ g_thread_new_internal (const gchar   *name, | |||||||
|                        gsize          stack_size, |                        gsize          stack_size, | ||||||
|                        GError       **error) |                        GError       **error) | ||||||
| { | { | ||||||
|   GRealThread *result; |   GRealThread *thread; | ||||||
|   GError *local_error = NULL; |  | ||||||
|  |  | ||||||
|   g_return_val_if_fail (func != NULL, NULL); |   g_return_val_if_fail (func != NULL, NULL); | ||||||
|  |  | ||||||
|   G_LOCK (g_thread_new); |   G_LOCK (g_thread_new); | ||||||
|   result = g_system_thread_new (proxy, stack_size, joinable, &local_error); |   thread = g_system_thread_new (proxy, stack_size, joinable, error); | ||||||
|   result->thread.joinable = joinable; |   if (thread) | ||||||
|   result->thread.func = func; |     { | ||||||
|   result->thread.data = data; |       thread->thread.joinable = joinable; | ||||||
|   result->name = name; |       thread->thread.func = func; | ||||||
|  |       thread->thread.data = data; | ||||||
|  |       thread->name = name; | ||||||
|  |     } | ||||||
|   G_UNLOCK (g_thread_new); |   G_UNLOCK (g_thread_new); | ||||||
|  |  | ||||||
|   if (local_error) |   return (GThread*) thread; | ||||||
|     { |  | ||||||
|       g_propagate_error (error, local_error); |  | ||||||
|       g_system_thread_free (result); |  | ||||||
|       return NULL; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|   return (GThread*) result; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user