From 253b952f4db8768b0b123037cd1c1e050b8e66c0 Mon Sep 17 00:00:00 2001 From: MacDue Date: Thu, 19 May 2022 14:50:31 +0100 Subject: [PATCH 1/2] pthread: avoid heap alloc in pthread_cond_timedwait --- components/pthread/pthread_cond_var.c | 29 +++++++++------------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/components/pthread/pthread_cond_var.c b/components/pthread/pthread_cond_var.c index 03267a54c0..fc6f96e5aa 100644 --- a/components/pthread/pthread_cond_var.c +++ b/components/pthread/pthread_cond_var.c @@ -1,21 +1,8 @@ -// Copyright 2017 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// This is a simple implementation of pthread condition variables. In essence, -// the waiter creates its own semaphore to wait on and pushes it in the cond var -// specific list. Upon notify and broadcast, all the waiters for the given cond -// var are woken up. +/* + * SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include @@ -162,7 +149,11 @@ int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *mut, const struc } esp_pthread_cond_waiter_t w; - w.wait_sem = xSemaphoreCreateCounting(1, 0); /* First get will block */ + + // Around 80 bytes + StaticSemaphore_t sem_buffer; + // Create semaphore: first take will block + w.wait_sem = xSemaphoreCreateCountingStatic(1, 0, &sem_buffer); _lock_acquire_recursive(&cond->lock); TAILQ_INSERT_TAIL(&cond->waiter_list, &w, link); From 75066bde5a9fdf6cb8c010f52b0977429b5e5847 Mon Sep 17 00:00:00 2001 From: MacDue Date: Thu, 19 May 2022 15:58:44 +0100 Subject: [PATCH 2/2] ci: remove components/pthread/pthread_cond_var.c from ignore list --- tools/ci/check_copyright_ignore.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index fecc8763c2..b68f65abcf 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -778,7 +778,6 @@ components/nvs_flash/test_nvs_host/test_nvs_initialization.cpp components/nvs_flash/test_nvs_host/test_nvs_storage.cpp components/protocomm/include/transports/protocomm_console.h components/protocomm/include/transports/protocomm_httpd.h -components/pthread/pthread_cond_var.c components/pthread/test/test_cxx_cond_var.cpp components/pthread/test/test_cxx_std_future.cpp components/pthread/test/test_pthread.c