From patchwork Fri Dec 23 19:19:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seija Kijin X-Patchwork-Id: 13081079 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38615C3DA79 for ; Fri, 23 Dec 2022 19:19:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232160AbiLWTTn (ORCPT ); Fri, 23 Dec 2022 14:19:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231211AbiLWTTl (ORCPT ); Fri, 23 Dec 2022 14:19:41 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A65DC75F for ; Fri, 23 Dec 2022 11:19:40 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id m8-20020a05600c3b0800b003d96f801c48so1370844wms.0 for ; Fri, 23 Dec 2022 11:19:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=A6GP/eZ3XXrZHZXftNTRfIXvKeFBn1NYVoQFNtA6JMQ=; b=nQmRa4rO4jBM5P1Ra6F7RUxeVEkyKz9+/qS9EAbM6RqII+3sQFsho4/L2NKweH7OHu yPa957+FFjXeIacE8K4bZXFA05NQmdwuZ6V3ByAgk8F+3DBUvtWJEKtN5W7GFxAGFuBZ OVNXDflxYIbyO9/tyqA7BClgr6JxMP/Si4ie7p5/bN30kY6fTVnzKZWYTYlpbS911o92 W6cZ5tta4hznSgaxDiz2jRGaIZejzl7Fs5AO9nrUCTKECudGtoG/7J+x+UKroqKk/pBT SN+VDRZFkqfw34Ddi1JZtXxbopxP5zbTuUMVuk1+keY7Xy1unZeny0WsXGfiXQEEtPWT vtVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A6GP/eZ3XXrZHZXftNTRfIXvKeFBn1NYVoQFNtA6JMQ=; b=FN2jbvzBS/T2QmYW2M5L7CMqd5I8gMmxqxvN9+fA+OojkKV/Nar4sFOgnUxtD3FSvj PbpS8PyzJxG6AgzTJ5nxwsvkgqdQF+tif5svTI03giRX5/cd0/WzeFEWNFH1XIz5sAVQ gHFedF6FnNE3QZSusgfNd62GsBVAQAoWHTHIiz9cEcmZcPSZQJPe9aGAAUHRZvEUpKJj v8tUBEZuA3sM9oc0nOpPrd5kZ15Oj+sgGk3sZ8qRSoZt2pOxXYKRYlMo5jN0NkuiWDv7 PWV8ULsTlXdrKBrePyYhewTt0xNgyerpCsOBIEqwcYewBiLz5vaFq8+CxHggniePyjHD ZSOA== X-Gm-Message-State: AFqh2kp0zznTBigGKJd+zxv4pN32bwvHDrVa4v5i4zKcms1nD/yAEp4l X8VrR2EztCywcwpLfOA11cjeTFBR9EU= X-Google-Smtp-Source: AMrXdXt8tbaVDSvrydyU/RcEkP3Gcvd0gSkuWcB6XPVJXMC9OvC+sh3tiEXzgGnvk5ZIIrMC6NdBOw== X-Received: by 2002:a05:600c:3b82:b0:3cf:900c:de6b with SMTP id n2-20020a05600c3b8200b003cf900cde6bmr7959414wms.15.1671823178849; Fri, 23 Dec 2022 11:19:38 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r13-20020a05600c458d00b003d34f170487sm13092835wmo.0.2022.12.23.11.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Dec 2022 11:19:38 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 23 Dec 2022 19:19:36 +0000 Subject: [PATCH v11 1/2] win32-pthread: prepare pthread.c for change by formatting Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Johannes Sixt , Rose <83477269+AtariDreams@users.noreply.github.com>, Seija Kijin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Seija Kijin From: Seija Kijin File has been formatted to meet coding guidelines Signed-off-by: Seija Kijin --- compat/win32/pthread.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/compat/win32/pthread.c b/compat/win32/pthread.c index 2e7eead42cb..65e15a560d5 100644 --- a/compat/win32/pthread.c +++ b/compat/win32/pthread.c @@ -22,12 +22,12 @@ static unsigned __stdcall win32_start_routine(void *arg) } int pthread_create(pthread_t *thread, const void *unused, - void *(*start_routine)(void*), void *arg) + void *(*start_routine)(void *), void *arg) { thread->arg = arg; thread->start_routine = start_routine; - thread->handle = (HANDLE) - _beginthreadex(NULL, 0, win32_start_routine, thread, 0, NULL); + thread->handle = (HANDLE)_beginthreadex(NULL, 0, win32_start_routine, + thread, 0, NULL); if (!thread->handle) return errno; @@ -37,16 +37,15 @@ int pthread_create(pthread_t *thread, const void *unused, int win32_pthread_join(pthread_t *thread, void **value_ptr) { - DWORD result = WaitForSingleObject(thread->handle, INFINITE); - switch (result) { - case WAIT_OBJECT_0: - if (value_ptr) - *value_ptr = thread->arg; - return 0; - case WAIT_ABANDONED: - return EINVAL; - default: - return err_win_to_posix(GetLastError()); + switch (WaitForSingleObject(thread->handle, INFINITE)) { + case WAIT_OBJECT_0: + if (value_ptr) + *value_ptr = thread->arg; + return 0; + case WAIT_ABANDONED: + return EINVAL; + default: + return err_win_to_posix(GetLastError()); } } From patchwork Fri Dec 23 19:19:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seija Kijin X-Patchwork-Id: 13081080 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73F58C4332F for ; Fri, 23 Dec 2022 19:19:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231267AbiLWTTq (ORCPT ); Fri, 23 Dec 2022 14:19:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231970AbiLWTTn (ORCPT ); Fri, 23 Dec 2022 14:19:43 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07093D11C for ; Fri, 23 Dec 2022 11:19:41 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id i7so5326879wrv.8 for ; Fri, 23 Dec 2022 11:19:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=DY7PAnHRvdf7iBa0HiQUJ5J2M+tYPTu4mU/yDR/BtrI=; b=icR5J3gBgU5wMch5QYP6UKTmczyNYBmho2zJMDFwOnKvsjjSaKdkG/upI7e31c5alO ER+OLwtJcyNaiF4f3BkTtfevpLYPYOTvbBTacZZ8B8U2jT9rO/I4DpPuG/3K3GGHq9M6 8chUt+QJ5CZi+BFd6Rs1EkpV9ZfjKHRq/oPLuN8yHCk9EJmqKljs9ff91tlEAXrpJ8Ou WIPAVumPEveylyNgZi744WpWdpWtpEbc97MBwWFuqKZNWevOqy/T85yKXSJoqwc/9UPZ Sor16yKYeO/k18nM3nhZbavLZheYJxrQv97sd4hc9fbODkmOf7UO1hvz9tx5gXvACmEo kfgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DY7PAnHRvdf7iBa0HiQUJ5J2M+tYPTu4mU/yDR/BtrI=; b=mjOJBQPWQBd4wedImoOPVGBPI84QNcViFArK/JeuOslwfeRNvE/uRay9ffFvIHIBBK XYRGj8E/D7V2gkFsUKpXeJqPLlQV/zjbRWkeKXHJMWRAeTFbqfMsG/qRHFwVikjfY3/5 rcvt3FAgIOnI3g8IDR/zgp9MD9QBld0MXAvlAAMOil9cHwBgnJcIfJ0BHLI0olNt6Vug pnPZUAQwYb/fDneX+c+3u8Mhq0wUDFbZJ/2Jkn3K32ctqSiitwpEl2KOpeyTS/O4XJVv kd+OmO7cCbLSaBOHuqeK72BXfi8MbaNhIqq9P8JS8vToPZc3maJGRR6hh+3di51bB8ju gxGA== X-Gm-Message-State: AFqh2kqbbIfscgNeIw+olHEjv1p3rgJaUQGPYTgGF9FTiiHcqZZe88UO zFjiH0jEvdVKOeYhtzARk3Fkc4praI8= X-Google-Smtp-Source: AMrXdXvxoDFTSIphphQ3fan8w5NFp9PdMuP3GUJkBbEJpFPYMViAJZtrc0pvdeDNzn5j6o1VvXYWHA== X-Received: by 2002:a5d:4e83:0:b0:25d:9954:32c9 with SMTP id e3-20020a5d4e83000000b0025d995432c9mr6344370wru.10.1671823179479; Fri, 23 Dec 2022 11:19:39 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s18-20020adfdb12000000b00241fde8fe04sm3892799wri.7.2022.12.23.11.19.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Dec 2022 11:19:39 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 23 Dec 2022 19:19:37 +0000 Subject: [PATCH v11 2/2] win32: close handles of threads that have been joined Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Johannes Sixt , Rose <83477269+AtariDreams@users.noreply.github.com>, Seija Kijin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Seija Kijin From: Seija Kijin After the thread terminates, the handle to the original thread should be closed. This change makes win32_pthread_join POSIX compliant. Signed-off-by: Seija Kijin --- compat/win32/pthread.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compat/win32/pthread.c b/compat/win32/pthread.c index 65e15a560d5..f63f65c9dfe 100644 --- a/compat/win32/pthread.c +++ b/compat/win32/pthread.c @@ -41,11 +41,15 @@ int win32_pthread_join(pthread_t *thread, void **value_ptr) case WAIT_OBJECT_0: if (value_ptr) *value_ptr = thread->arg; + CloseHandle(thread->handle); return 0; case WAIT_ABANDONED: + CloseHandle(thread->handle); return EINVAL; default: - return err_win_to_posix(GetLastError()); + /* the wait failed, so do not detach */ + errno = err_win_to_posix(GetLastError()); + return errno; } }