From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 7CE963858D1E; Thu, 7 Sep 2023 16:32:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CE963858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694104360; bh=gOBtPTLgjEbMIDIGUT3FselhnqnVFnoVnGgqRy4uocg=; h=From:To:Subject:Date:From; b=vODWrWvSDIQcJ7CajXPhscX0V+IgbQas6ZqlCNyBj5aSvTZDOpluSLIGCA2XOhh2q Bq8bFZizLRh+C0zT7+Hv989A2EZg+K4i1I7AIlyr0trVSsCbSNZoVPQNdL3TJo980l BmNQv6hnhql7T+YJiyaxCvWuoI9AstSf6ViyEqzQ= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: dsp: Improve response time of select()/poll(). X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 2c06014f12b0231e40d4256ae5f0d16a4b21be48 X-Git-Newrev: 7ced682549ae718db29121013c84ce8057bc3509 Message-Id: <20230907163240.7CE963858D1E@sourceware.org> Date: Thu, 7 Sep 2023 16:32:40 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D7ced682549a= e718db29121013c84ce8057bc3509 commit 7ced682549ae718db29121013c84ce8057bc3509 Author: Takashi Yano Date: Thu Sep 7 17:35:25 2023 +0900 Cygwin: dsp: Improve response time of select()/poll(). =20 With this patch, the response time of select()/poll() has been improved by utilizing semaphore (select_sem) just like pipe and fifo. In addition, notification of exceptional conditions has been added. =20 Fixes: 2c06014f12b0 ("Cygwin: dsp: Implement select()/poll().") Signed-off-by: Takashi Yano Diff: --- winsup/cygwin/fhandler/dsp.cc | 11 ++++++++++- winsup/cygwin/local_includes/fhandler.h | 5 +++-- winsup/cygwin/select.cc | 16 ++++++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/winsup/cygwin/fhandler/dsp.cc b/winsup/cygwin/fhandler/dsp.cc index f1634f7a8..5f78821d4 100644 --- a/winsup/cygwin/fhandler/dsp.cc +++ b/winsup/cygwin/fhandler/dsp.cc @@ -536,6 +536,8 @@ inline void fhandler_dev_dsp::Audio_out::callback_sampledone (WAVEHDR *pHdr) { Qisr2app_->send (pHdr); + ReleaseSemaphore (fh->get_select_sem (), + get_obj_handle_count (fh->get_select_sem ()) - 1, NULL); } =20 bool @@ -994,6 +996,8 @@ inline void fhandler_dev_dsp::Audio_in::callback_blockfull (WAVEHDR *pHdr) { Qisr2app_->send (pHdr); + ReleaseSemaphore (fh->get_select_sem (), + get_obj_handle_count (fh->get_select_sem ()) - 1, NULL); } =20 static void CALLBACK @@ -1058,7 +1062,7 @@ fhandler_dev_dsp::fixup_after_exec () =20 =20 int -fhandler_dev_dsp::open (int flags, mode_t) +fhandler_dev_dsp::open (int flags, mode_t mode) { int ret =3D -1, err =3D 0; UINT num_in =3D 0, num_out =3D 0; @@ -1093,6 +1097,8 @@ fhandler_dev_dsp::open (int flags, mode_t) else ret =3D open_null (flags); =20 + select_sem =3D CreateSemaphore (sec_none_cloexec (mode), 0, INT32_MAX, N= ULL); + debug_printf ("ACCMODE=3D%y audio_in=3D%d audio_out=3D%d, err=3D%d, ret= =3D%d", flags & O_ACCMODE, num_in, num_out, err, ret); if (ret >=3D 0) @@ -1226,6 +1232,9 @@ fhandler_dev_dsp::close () being_closed =3D true; close_audio_in (); close_audio_out (); + ReleaseSemaphore (select_sem, get_obj_handle_count (select_sem) - 1, NUL= L); + CloseHandle (select_sem); + select_sem =3D NULL; return fhandler_base::close (); } =20 diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_= includes/fhandler.h index d7dc02e89..212c22344 100644 --- a/winsup/cygwin/local_includes/fhandler.h +++ b/winsup/cygwin/local_includes/fhandler.h @@ -2875,8 +2875,9 @@ class fhandler_dev_dsp: public fhandler_base select_record *select_write (select_stuff *); select_record *select_except (select_stuff *); =20 - bool read_ready(); - bool write_ready(); + bool read_ready (); + bool write_ready (); + bool is_closed () { return being_closed; }; }; =20 class fhandler_virtual : public fhandler_base diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index 3ad12c262..725aab90c 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -2268,6 +2268,9 @@ peek_dsp (select_record *s, bool from_select) if (s->write_selected) if (s->write_ready || fh->write_ready ()) gotone +=3D s->write_ready =3D true; + if (s->except_selected) + if (s->except_ready || fh->is_closed ()) + gotone +=3D s->except_ready =3D true; return gotone; } =20 @@ -2296,7 +2299,7 @@ thread_dsp (void *arg) } if (!looping) break; - cygwait (sleep_time >> 3); + cygwait (di->bye, sleep_time >> 3); if (sleep_time < 80) ++sleep_time; if (di->stop_thread) @@ -2313,6 +2316,13 @@ start_thread_dsp (select_record *me, select_stuff *s= tuff) me->h =3D *((select_dsp_info *) stuff->device_specific_dsp)->thread; else { + di->bye =3D me->fh->get_select_sem (); + if (di->bye) + DuplicateHandle (GetCurrentProcess (), di->bye, + GetCurrentProcess (), &di->bye, + 0, 0, DUPLICATE_SAME_ACCESS); + else + di->bye =3D CreateSemaphore (&sec_none_nih, 0, INT32_MAX, NULL); di->start =3D &stuff->start; di->stop_thread =3D false; di->thread =3D new cygthread (thread_dsp, di, "dspsel"); @@ -2324,7 +2334,7 @@ start_thread_dsp (select_record *me, select_stuff *st= uff) } =20 static void -dsp_cleanup (select_record *aaa, select_stuff *stuff) +dsp_cleanup (select_record *, select_stuff *stuff) { select_dsp_info *di =3D (select_dsp_info *) stuff->device_specific_dsp; if (!di) @@ -2332,7 +2342,9 @@ dsp_cleanup (select_record *aaa, select_stuff *stuff) if (di->thread) { di->stop_thread =3D true; + ReleaseSemaphore (di->bye, get_obj_handle_count (di->bye), NULL); di->thread->detach (); + CloseHandle (di->bye); } delete di; stuff->device_specific_dsp =3D NULL;