Skip to content

Commit

Permalink
Cygwin: pipes: remove unnecessary NULL checks for hdl_cnt_mtx
Browse files Browse the repository at this point in the history
In view of the previous changes to open_setup, we can always assume
that hdl_cnt_mtx is non-NULL.
  • Loading branch information
kbrow1i committed Sep 18, 2021
1 parent be08c5c commit 643db9e
Showing 1 changed file with 12 additions and 26 deletions.
38 changes: 12 additions & 26 deletions winsup/cygwin/fhandler_pipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,10 @@ fhandler_pipe::reader_closed ()
{
if (!query_hdl)
return false;
if (hdl_cnt_mtx)
WaitForSingleObject (hdl_cnt_mtx, INFINITE);
WaitForSingleObject (hdl_cnt_mtx, INFINITE);
int n_reader = get_obj_handle_count (query_hdl);
int n_writer = get_obj_handle_count (get_handle ());
if (hdl_cnt_mtx)
ReleaseMutex (hdl_cnt_mtx);
ReleaseMutex (hdl_cnt_mtx);
return n_reader == n_writer;
}

Expand Down Expand Up @@ -583,18 +581,14 @@ fhandler_pipe::set_close_on_exec (bool val)
set_no_inheritance (select_sem, val);
if (query_hdl)
set_no_inheritance (query_hdl, val);
if (hdl_cnt_mtx)
set_no_inheritance (hdl_cnt_mtx, val);
set_no_inheritance (hdl_cnt_mtx, val);
}

void
fhandler_pipe::fixup_after_fork (HANDLE parent)
{
if (hdl_cnt_mtx)
{
fork_fixup (parent, hdl_cnt_mtx, "hdl_cnt_mtx");
WaitForSingleObject (hdl_cnt_mtx, INFINITE);
}
fork_fixup (parent, hdl_cnt_mtx, "hdl_cnt_mtx");
WaitForSingleObject (hdl_cnt_mtx, INFINITE);
if (read_mtx)
fork_fixup (parent, read_mtx, "read_mtx");
if (select_sem)
Expand All @@ -603,8 +597,7 @@ fhandler_pipe::fixup_after_fork (HANDLE parent)
fork_fixup (parent, query_hdl, "query_hdl");

fhandler_base::fixup_after_fork (parent);
if (hdl_cnt_mtx)
ReleaseMutex (hdl_cnt_mtx);
ReleaseMutex (hdl_cnt_mtx);
}

int
Expand All @@ -614,8 +607,7 @@ fhandler_pipe::dup (fhandler_base *child, int flags)
ftp->set_popen_pid (0);

int res = 0;
if (hdl_cnt_mtx)
WaitForSingleObject (hdl_cnt_mtx, INFINITE);
WaitForSingleObject (hdl_cnt_mtx, INFINITE);
if (fhandler_base::dup (child, flags))
res = -1;
else if (read_mtx &&
Expand Down Expand Up @@ -645,17 +637,15 @@ fhandler_pipe::dup (fhandler_base *child, int flags)
ftp->close ();
res = -1;
}
else if (hdl_cnt_mtx &&
!DuplicateHandle (GetCurrentProcess (), hdl_cnt_mtx,
else if (!DuplicateHandle (GetCurrentProcess (), hdl_cnt_mtx,
GetCurrentProcess (), &ftp->hdl_cnt_mtx,
0, !(flags & O_CLOEXEC), DUPLICATE_SAME_ACCESS))
{
__seterrno ();
ftp->close ();
res = -1;
}
if (hdl_cnt_mtx)
ReleaseMutex (hdl_cnt_mtx);
ReleaseMutex (hdl_cnt_mtx);

debug_printf ("res %d", res);
return res;
Expand All @@ -671,16 +661,12 @@ fhandler_pipe::close ()
}
if (read_mtx)
CloseHandle (read_mtx);
if (hdl_cnt_mtx)
WaitForSingleObject (hdl_cnt_mtx, INFINITE);
WaitForSingleObject (hdl_cnt_mtx, INFINITE);
if (query_hdl)
CloseHandle (query_hdl);
int ret = fhandler_base::close ();
if (hdl_cnt_mtx)
{
ReleaseMutex (hdl_cnt_mtx);
CloseHandle (hdl_cnt_mtx);
}
ReleaseMutex (hdl_cnt_mtx);
CloseHandle (hdl_cnt_mtx);
return ret;
}

Expand Down

0 comments on commit 643db9e

Please sign in to comment.