niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » *nix » BSD » FreeBSD » mail-lists » Architecture
[RFC] Implement cv_wait_nolock(), for emulation of SGI's sv_wait()
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
Craig Rodrigues
*nix forums beginner


Joined: 13 Dec 2002
Posts: 27

PostPosted: Wed Dec 07, 2005 10:43 pm    Post subject: [RFC] Implement cv_wait_nolock(), for emulation of SGI's sv_wait() Reply with quote

Hi,

As part of the XFS for FreeBSD project, Alexander Kabaev
implemented a cv_wait_nolock() function for compatibility
with SGI's sv_wait() call:
http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0650&db=man&fname=/usr/share/catman/p_man/catD/SV_WAIT.z

sv_wait() waits on a synchronization variable, the lock must be held
before the call is entered, but the lock is not held when sv_wait() is
exited.

Is this patch OK to go into FreeBSD?
Comments?


Index: condvar.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/condvar.h,v
retrieving revision 1.12
diff -u -u -r1.12 condvar.h
--- condvar.h 5 May 2004 21:57:44 -0000 1.12
+++ condvar.h 7 Dec 2005 22:38:44 -0000
@@ -53,6 +53,7 @@
void cv_destroy(struct cv *cvp);

void cv_wait(struct cv *cvp, struct mtx *mp);
+void cv_wait_nolock(struct cv *cvp, struct mtx *mp);
int cv_wait_sig(struct cv *cvp, struct mtx *mp);
int cv_timedwait(struct cv *cvp, struct mtx *mp, int timo);
int cv_timedwait_sig(struct cv *cvp, struct mtx *mp, int timo);
Index: kern_condvar.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_condvar.c,v
retrieving revision 1.52
diff -u -u -r1.52 kern_condvar.c
--- kern_condvar.c 12 Oct 2004 18:36:19 -0000 1.52
+++ kern_condvar.c 7 Dec 2005 22:39:25 -0000
@@ -137,6 +137,46 @@
}

/*
+ * Wait on a condition variable. This function differs from cv_wait by
+ * not aquiring the mutex after condition variable was signaled.
+ */
+void
+cv_wait_nolock(struct cv *cvp, struct mtx *mp)
+{
+ struct thread *td;
+
+ td = curthread;
+#ifdef KTRACE
+ if (KTRPOINT(td, KTR_CSW))
+ ktrcsw(1, 0);
+#endif
+ CV_ASSERT(cvp, mp, td);
+ WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, &mp->mtx_object,
+ "Waiting on \"%s\"", cvp->cv_description);
+
+ if (cold || panicstr) {
+ /*
+ * During autoconfiguration, just give interrupts
+ * a chance, then just return. Don't run any other
+ * thread or panic below, in case this is the idle
+ * process and already asleep.
+ */
+ return;
+ }
+
+ sleepq_lock(cvp);
+
+ cvp->cv_waiters++;
+ DROP_GIANT();
+ mtx_unlock(mp);
+
+ sleepq_add(cvp, mp, cvp->cv_description, SLEEPQ_CONDVAR);
+ sleepq_wait(cvp);
+
+ PICKUP_GIANT();
+}
+
+/*
* Wait on a condition variable, allowing interruption by signals. Return 0 if
* the thread was resumed with cv_signal or cv_broadcast, EINTR or ERESTART if
* a signal was caught. If ERESTART is returned the system call should be



--
Craig Rodrigues
rodrigc@crodrigues.org
_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
Back to top
Christoph Hellwig
*nix forums beginner


Joined: 08 May 2002
Posts: 40

PostPosted: Thu Dec 08, 2005 9:22 am    Post subject: Re: [RFC] Implement cv_wait_nolock(), for emulation of SGI's sv_wait() Reply with quote

On Wed, Dec 07, 2005 at 05:43:59PM -0500, Craig Rodrigues wrote:
Quote:
Hi,

As part of the XFS for FreeBSD project, Alexander Kabaev
implemented a cv_wait_nolock() function for compatibility
with SGI's sv_wait() call:
http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0650&db=man&fname=/usr/share/catman/p_man/catD/SV_WAIT.z

sv_wait() waits on a synchronization variable, the lock must be held
before the call is entered, but the lock is not held when sv_wait() is
exited.

The name sounds odd. I'd rather all it cv_wait_unlock.

_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
Back to top
John Baldwin
*nix forums Guru Wannabe


Joined: 27 Mar 2002
Posts: 278

PostPosted: Thu Dec 08, 2005 2:56 pm    Post subject: Re: [RFC] Implement cv_wait_nolock(), for emulation of SGI's sv_wait() Reply with quote

On Wednesday 07 December 2005 05:43 pm, Craig Rodrigues wrote:
Quote:
Hi,

As part of the XFS for FreeBSD project, Alexander Kabaev
implemented a cv_wait_nolock() function for compatibility
with SGI's sv_wait() call:
http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0650&db=man&fna
me=/usr/share/catman/p_man/catD/SV_WAIT.z

sv_wait() waits on a synchronization variable, the lock must be held
before the call is entered, but the lock is not held when sv_wait() is
exited.

Is this patch OK to go into FreeBSD?
Comments?

As I said on IRC, I'm not a big fan of this or PDROP, but PDROP is in the
tree. Note that you could implement sv_wait() using the existing primitives
via:

sv_wait()
{
cv_wait()
mtx_unlock()
}

If you do stick with cv_wait_nolock(), _please_ don't duplicate a whole bunch
of code by implement cv_wait() like so:

cv_wait()
{
cv_wait_nolock()
mtx_lock()
}

Note that currently you have a bug in the cold || panicstr case in that the
function doesn't drop the lock.

--
John Baldwin <jhb@FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org
_______________________________________________
freebsd-arch@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Tue Jan 06, 2009 9:30 am | All times are GMT
navigation Forum index » *nix » BSD » FreeBSD » mail-lists » Architecture
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts emulation of DB corruption Konstantin Sorokin Berkeley DB 0 Fri Jul 21, 2006 8:09 am
No new posts emulation of DB corruption Konstantin Sorokin Berkeley DB 0 Fri Jul 21, 2006 6:15 am
No new posts how to implement a simple class forname? Manuel C++ 11 Wed Jul 19, 2006 5:29 pm
No new posts What functions in UNIX 6th implement search and sort algo... lovecreatesbeauty C 3 Thu Jul 13, 2006 3:20 pm
No new posts DLT / Tape Library Emulation Mirco Piccin Debian 1 Thu Jul 06, 2006 12:00 pm

Loans | Credit Card Debt Consolidation | Web Advertising | Adverse Credit Remortgage | Internet Advertising
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.3303s ][ Queries: 16 (0.2007s) ][ GZIP on - Debug on ]