From patchwork Mon Sep 2 01:27:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rosen Penev X-Patchwork-Id: 11125813 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C628414DE for ; Mon, 2 Sep 2019 01:28:07 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5073521874 for ; Mon, 2 Sep 2019 01:28:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="Vez0QjbQ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DjT1ZYCS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5073521874 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 1897A167B; Mon, 2 Sep 2019 03:27:15 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1897A167B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567387685; bh=UCUHERGEc4MlRiQobqortniD4YqCSDQ6vaIeN7hUyQk=; h=From:To:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=Vez0QjbQU9mguet6Gxkc2xtEvh3Cizcw/SIGlHT7AhOszBiyF/f4ywYSTkH2GzYRd g2ReVyWSNyHWfE/RmbixseqFUs2sCpyy914XGrCXBoVZWWXwaDh9WTriiC7Y0JqrXO goIkXi2XnAstEATYHRI9jJ1Te4uDbWNtDo7xOVmU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 872A4F80306; Mon, 2 Sep 2019 03:27:14 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 2F6F8F8045F; Mon, 2 Sep 2019 03:27:13 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 43223F80306 for ; Mon, 2 Sep 2019 03:27:09 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 43223F80306 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DjT1ZYCS" Received: by mail-pg1-x543.google.com with SMTP id n9so6547979pgc.1 for ; Sun, 01 Sep 2019 18:27:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=fpuKjcvQL2FC1BkEAV7/GouC1zaHg3TIj3cjQPPsPps=; b=DjT1ZYCSQs3lZeB9H0O48+NKT9MNnw+wBgjx0zej7pEwKcE/EtA7ZWc39u18RWymRQ VMQXF58wZDqLH5ymYMN85RzuUKhd5nHsqHmHSYVx1EaxpZPvyRlW5t5vDTZmwFizbWZT svbJ60aSX76VeLaLn7yBvNyzgqpix3qOyI4fSV22/Itussx0xO92eGhuZh5QuC2lfODw 3e3+4ssn6VOGsNye8BGHqbxZY9SjRN7IRHE1TQfS/z1oNaNVOiYLMMA7kcxS/6OCJgxt 8KvedLm6sTqYd8GRrWhoMDuQgZSDksIfsVVjqEpRg2soWNU2MvI+iXHyFX0LSvGK3xQL Fu6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=fpuKjcvQL2FC1BkEAV7/GouC1zaHg3TIj3cjQPPsPps=; b=K+ajaMhWocC8Rlv6DiauQEZmMjUkiJt2p5OCMqzqBEGoXkvNiw8RL4TM/dno8tv5L2 1FnreSlibh57zsxLxl0hQA37MvnovQzjmkcrEQpJKlAZXKu9Yizto/FklVD9A+VcUeHP U0Jk5IUOh1JnUDrAUX/a8Tfrv83oDwqyj0xGTakw+uaTG/MzZNBTJMv1FZPxRdr5X3bO udBjntjTYT6LzybOq8lQJqNrgxxt+N1s8zz7iir+AlUE1ffIN7/hSPTyi4YvDWuFkZEU tiuuSTxzHN0avD4i2qfttmvVQUajarKSt78323C5UrlmFDjn4NdaiBn59KPnUzHHMj+s u9Qg== X-Gm-Message-State: APjAAAWBkaYeTZSnE0JdMr9UWFC5PjyMInYsGZbZ5zgwxFvwHZHBpajg POO1KEPFs0HhJgFVpqR+MTzJ+dU4Va8= X-Google-Smtp-Source: APXvYqx5hqnU1i95c6TSWpScoJkabWsEMaFixL6QdZSGCs7a0DHNkisf1nWBzEVszf3xIjvkV+yEVQ== X-Received: by 2002:a17:90b:14a:: with SMTP id em10mr10103777pjb.26.1567387628024; Sun, 01 Sep 2019 18:27:08 -0700 (PDT) Received: from localhost.localdomain (76-14-106-55.rk.wavecable.com. [76.14.106.55]) by smtp.gmail.com with ESMTPSA id t11sm11947919pgb.33.2019.09.01.18.27.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Sep 2019 18:27:07 -0700 (PDT) From: Rosen Penev To: alsa-devel@alsa-project.org Date: Sun, 1 Sep 2019 18:27:05 -0700 Message-Id: <20190902012705.16062-1-rosenp@gmail.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Subject: [alsa-devel] [PATCH] alsa-utils: Remove usleep usage X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" usleep was deprecated in POSIX 2008 and is not available without deprecated APIs enabled in uClibc-ng. Signed-off-by: Rosen Penev --- alsactl/daemon.c | 3 ++- alsaloop/pcmjob.c | 3 ++- amidi/amidi.c | 6 ++++-- bat/bat.c | 5 +++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/alsactl/daemon.c b/alsactl/daemon.c index 1d98caa..3b84cf6 100644 --- a/alsactl/daemon.c +++ b/alsactl/daemon.c @@ -348,7 +348,8 @@ static int check_another_instance(const char *pidfile) if (pid >= 0) { /* invoke new card rescan */ if (kill(pid, SIGUSR1) >= 0) { - usleep(1000); + struct timespec req = { 0, 1 * 1000 * 1000 }; + nanosleep(&req, NULL); pid = read_pid_file(pidfile); if (pid >= 0) return 1; diff --git a/alsaloop/pcmjob.c b/alsaloop/pcmjob.c index 29d1aba..d0347dc 100644 --- a/alsaloop/pcmjob.c +++ b/alsaloop/pcmjob.c @@ -662,10 +662,11 @@ static int xrun(struct loopback_handle *lhandle) static int suspend(struct loopback_handle *lhandle) { + struct timespec req = { 0, 1000}; int err; while ((err = snd_pcm_resume(lhandle->handle)) == -EAGAIN) - usleep(1); + nanosleep(&req, NULL); if (err < 0) return xrun(lhandle); return 0; diff --git a/amidi/amidi.c b/amidi/amidi.c index b6e05e1..3b2953d 100644 --- a/amidi/amidi.c +++ b/amidi/amidi.c @@ -254,10 +254,12 @@ static int send_midi_interleaved(void) snd_rawmidi_status(output, st); do { /* 320 µs per byte as noted in Page 1 of MIDI spec */ - usleep((buffer_size - snd_rawmidi_status_get_avail(st)) * 320); + struct timespec req = { 0, (buffer_size - snd_rawmidi_status_get_avail(st)) * 320 * 1000}; + nanosleep(&req, NULL); snd_rawmidi_status(output, st); } while(snd_rawmidi_status_get_avail(st) < buffer_size); - usleep(sysex_interval * 1000); + struct timespec sysex = { 0, sysex_interval * 1000 * 1000}; + nanosleep(&sysex, NULL); } /* find end of SysEx */ diff --git a/bat/bat.c b/bat/bat.c index 8645770..27e7a34 100644 --- a/bat/bat.c +++ b/bat/bat.c @@ -176,6 +176,7 @@ static void test_loopback(struct bat *bat) pthread_t capture_id, playback_id; int err; int *thread_result_capture, *thread_result_playback; + struct timespec capture_delay = { 0, CAPTURE_DELAY * 1000 * 1000 }; /* start playback */ err = pthread_create(&playback_id, NULL, @@ -188,7 +189,7 @@ static void test_loopback(struct bat *bat) /* TODO: use a pipe to signal stream start etc - i.e. to sync threads */ /* Let some time for playing something before capturing */ - usleep(CAPTURE_DELAY * 1000); + nanosleep(&capture_delay, NULL); /* start capture */ err = pthread_create(&capture_id, NULL, (void *) bat->capture.fct, bat); @@ -691,7 +692,7 @@ int main(int argc, char *argv[]) } /* Waiting 500ms and start the next round */ - usleep(CAPTURE_DELAY * 1000); + nanosleep(&capture_delay, NULL); } goto out; }