This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: sem_trywait returns EAGAIN (rather than returning -1 and setting errno)


Andrew T. Schnable [mailto:schnable@enteract.com] wrote:
> I think all the sem_* functions are broken similarly. [ ... ]

I just came across this myself while working on enabling
Cygwin Python threads. You may find the following function
helpful:

static int
fix_status(int status)
{
	return (status == -1) ? errno : status;
}

I defined it as a routine rather than a macro so that you
can use it on a single line without mistakenly calling
the function twice. E.g.,
	status = fix_status(sem_wait(thelock));

This should work for any function that returns 0 for success
and -1 for failure (putting the error code in errno), since
0 is never a legal errno code. You may find it useful if you
are using pthreads and semaphore code at the same time and
want the return codes to work the same.

-Jerry

-O Gerald S. Williams, 22Y-103GA : mailto:gsw@agere.com O-
-O AGERE SYSTEMS, 555 UNION BLVD : office:610-712-8661  O-
-O ALLENTOWN, PA, USA 18109-3286 : mobile:908-672-7592  O-


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]