summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2013-07-29 14:38:18 -0400
committerDan Pasette <dan@10gen.com>2013-08-01 20:39:49 -0400
commit6d738db1f45ec0f7447e2a14e0216af2410074c8 (patch)
tree6954f2e5a5067f50fc91b21e5e4440bdf2797e08
parent50dace31f840b8c0261420db9ce53480f36ef83d (diff)
downloadmongo-6d738db1f45ec0f7447e2a14e0216af2410074c8.tar.gz
SERVER-10362: add option to ClientCursor::staticYield to do a pthread_yield instead of sleepmicros
this is mostly because of some platforms (like xen) where sleepmicros is too inaccurate
-rw-r--r--src/mongo/db/clientcursor.cpp24
-rw-r--r--src/mongo/db/clientcursor.h5
2 files changed, 22 insertions, 7 deletions
diff --git a/src/mongo/db/clientcursor.cpp b/src/mongo/db/clientcursor.cpp
index a0693dd8c7d..aa5452ac4cb 100644
--- a/src/mongo/db/clientcursor.cpp
+++ b/src/mongo/db/clientcursor.cpp
@@ -564,7 +564,7 @@ namespace mongo {
// need to lock this else rec->touch won't be safe file could disappear
lk.reset( new LockMongoFilesShared() );
}
-
+
dbtempreleasecond unlock;
if ( unlock.unlocked() ) {
if ( haveReadLock ) {
@@ -574,16 +574,30 @@ namespace mongo {
#ifdef _WIN32
SwitchToThread();
#else
- sleepmicros(1);
+ if ( micros == 0 ) {
+ pthread_yield();
+ }
+ else {
+ sleepmicros(1);
+ }
#endif
}
else {
- if ( micros == -1 )
+ if ( micros == -1 ) {
micros = Client::recommendedYieldMicros();
- if ( micros > 0 )
+ }
+ else if ( micros == 0 ) {
+#ifdef _WIN32
+ SwitchToThread();
+#else
+ pthread_yield();
+#endif
+ }
+ else if ( micros > 0 ) {
sleepmicros( micros );
+ }
}
-
+
}
else if ( Listener::getTimeTracker() == 0 ) {
// we aren't running a server, so likely a repair, so don't complain
diff --git a/src/mongo/db/clientcursor.h b/src/mongo/db/clientcursor.h
index 7de161d6dd5..f2077282c66 100644
--- a/src/mongo/db/clientcursor.h
+++ b/src/mongo/db/clientcursor.h
@@ -178,7 +178,8 @@ namespace mongo {
/**
* @param microsToSleep -1 : ask client
- * >=0 : sleep for that amount
+ * 0 : pthread_yield or equivilant
+ * >0 : sleep for that amount
* @param recordToLoad after yielding lock, load this record with only mmutex
* do a dbtemprelease
* note: caller should check matcher.docMatcher().atomic() first and not yield if atomic -
@@ -188,7 +189,7 @@ namespace mongo {
* if false is returned, then this ClientCursor should be considered deleted -
* in fact, the whole database could be gone.
*/
- bool yield( int microsToSleep = -1 , Record * recordToLoad = 0 );
+ bool yield( int microsToSleep = -1, Record * recordToLoad = 0 );
enum RecordNeeds {
DontNeed = -1 , MaybeCovered = 0 , WillNeed = 100