Revision: 6498
http://playerstage.svn.sourceforge.net/playerstage/?rev=6498&view=rev
Author: thjc
Date: 2008-06-09 18:12:22 -0700 (Mon, 09 Jun 2008)
Log Message:
-----------
Merged wait timout from 2-1 (6450)
Modified Paths:
--------------
code/player/trunk/libplayercore/CMakeLists.txt
code/player/trunk/libplayercore/driver.h
code/player/trunk/libplayercore/message.cc
code/player/trunk/libplayercore/message.h
code/player/trunk/server/drivers/position/nav200/CMakeLists.txt
Property Changed:
----------------
code/player/trunk/
Property changes on: code/player/trunk
___________________________________________________________________
Name: svn:ignore
- autom4te.cache
config.h
Makefile
Makefile.in
aclocal.m4
compile
config.guess
config.h.in
config.status
config.sub
configure
depcomp
install-sh
libtool
ltmain.sh
missing
stamp-h1
.project
build
+ autom4te.cache
config.h
Makefile
Makefile.in
aclocal.m4
compile
config.guess
config.h.in
config.status
config.sub
configure
depcomp
install-sh
libtool
ltmain.sh
missing
stamp-h1
.project
build
.cproject
Modified: code/player/trunk/libplayercore/CMakeLists.txt
===================================================================
--- code/player/trunk/libplayercore/CMakeLists.txt 2008-06-10 00:09:22 UTC
(rev 6497)
+++ code/player/trunk/libplayercore/CMakeLists.txt 2008-06-10 01:12:22 UTC
(rev 6498)
@@ -50,9 +50,9 @@
# from the fact that message cloning functions are auto-generated into
# playerxdr and used here. Those functions should go into a separate
# library.
-TARGET_LINK_LIBRARIES (playercore playerutils playererror playerxdr ltdl dl
pthread)
-PLAYER_ADD_LINK_LIB (ltdl dl pthread)
-PLAYER_MAKE_PKGCONFIG ("playercore" "Player core library - part of the Player
Project" "playererror" "" "" "-lltdl -lpthread")
+TARGET_LINK_LIBRARIES (playercore playerutils playererror playerxdr ltdl dl
pthread rt)
+PLAYER_ADD_LINK_LIB (ltdl dl pthread rt)
+PLAYER_MAKE_PKGCONFIG ("playercore" "Player core library - part of the Player
Project" "playererror" "" "" "-lltdl -lpthread -lrt")
SET (playererror_srcs error.c)
Modified: code/player/trunk/libplayercore/driver.h
===================================================================
--- code/player/trunk/libplayercore/driver.h 2008-06-10 00:09:22 UTC (rev
6497)
+++ code/player/trunk/libplayercore/driver.h 2008-06-10 01:12:22 UTC (rev
6498)
@@ -153,9 +153,13 @@
/** @brief Wait for new data to arrive on the driver's queue.
Call this method to block until a new message arrives on
- Driver::InQueue. This method will return immediately if at least
- one message is already waiting. */
- void Wait() { this->InQueue->Wait(); }
+ Driver::InQueue. This method will return true immediately if at least
+ one message is already waiting.
+
+ If TimeOut is set to a positive value this method will return false if the
+ timeout occurs before and update is recieved.
+ */
+ bool Wait(double TimeOut=0.0) { return this->InQueue->Wait(); }
public:
/** @brief The driver's thread.
Modified: code/player/trunk/libplayercore/message.cc
===================================================================
--- code/player/trunk/libplayercore/message.cc 2008-06-10 00:09:22 UTC (rev
6497)
+++ code/player/trunk/libplayercore/message.cc 2008-06-10 01:12:22 UTC (rev
6498)
@@ -47,6 +47,8 @@
#include <assert.h>
#include <string.h>
#include <stdio.h>
+#include <math.h>
+#include <time.h>
#include <libplayercore/message.h>
#include <libplayercore/player.h>
@@ -303,9 +305,10 @@
}
// Waits on the condition variable associated with this queue.
-void
-MessageQueue::Wait(void)
+bool
+MessageQueue::Wait(double TimeOut)
{
+ bool result = true;
MessageQueueElement* el;
// don't wait if there's data on the queue
@@ -319,7 +322,7 @@
}
this->Unlock();
if(el)
- return;
+ return result;
// need to push this cleanup function, cause if a thread is cancelled while
// in pthread_cond_wait(), it will immediately relock the mutex. thus we
@@ -327,9 +330,25 @@
pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock,
(void*)&this->condMutex);
pthread_mutex_lock(&this->condMutex);
- pthread_cond_wait(&this->cond,&this->condMutex);
+ if (TimeOut > 0)
+ {
+ struct timespec tp;
+ clock_gettime(CLOCK_REALTIME, &tp);
+ tp.tv_sec += static_cast<int> (floor(TimeOut));
+ tp.tv_nsec += static_cast<int> ((TimeOut - floor(TimeOut))*1e9);
+ int ret = pthread_cond_timedwait(&this->cond, &this->condMutex, &tp);
+ // if we got an error or timed out
+ if (ret != 0)
+ result = false;
+ }
+ else
+ {
+ pthread_cond_wait(&this->cond,&this->condMutex);
+ }
+
pthread_mutex_unlock(&this->condMutex);
pthread_cleanup_pop(0);
+ return result;
}
bool
Modified: code/player/trunk/libplayercore/message.h
===================================================================
--- code/player/trunk/libplayercore/message.h 2008-06-10 00:09:22 UTC (rev
6497)
+++ code/player/trunk/libplayercore/message.h 2008-06-10 01:12:22 UTC (rev
6498)
@@ -374,8 +374,12 @@
/// any existing message of the same signature, be ignored or accepted.
int CheckReplace(player_msghdr_t* hdr);
/** Wait on this queue. This method blocks until new data is available
- (as indicated by a call to DataAvailable()). */
- void Wait(void);
+ (as indicated by a call to DataAvailable()).
+
+ If TimeOut is set to a positive value this method will return false if the
+ timeout occurs before and update is recieved.
+ */
+ bool Wait(double TimeOut=0.0);
/** Signal that new data is available. Calling this method will
release any threads currently waiting on this queue. */
void DataAvailable(void);
Modified: code/player/trunk/server/drivers/position/nav200/CMakeLists.txt
===================================================================
--- code/player/trunk/server/drivers/position/nav200/CMakeLists.txt
2008-06-10 00:09:22 UTC (rev 6497)
+++ code/player/trunk/server/drivers/position/nav200/CMakeLists.txt
2008-06-10 01:12:22 UTC (rev 6498)
@@ -1,10 +1,3 @@
SET (sicknav200Srcs sicknav200.cc nav200.cc)
PLAYERDRIVER_OPTION (sicknav200 build_sicknav200 ON)
PLAYERDRIVER_ADD_DRIVER (sicknav200 build_sicknav200 SOURCES ${sicknav200Srcs})
-
-ADD_EXECUTABLE (test_program_init test_program_init.cpp ${sicknav200Srcs})
-TARGET_LINK_LIBRARIES (test_program_init playercore playererror playerutils
playerxdr ${PLAYER_EXTRA_LINK_LIBRARIES})
-ADD_EXECUTABLE (test_program test_program.cpp ${sicknav200Srcs})
-TARGET_LINK_LIBRARIES (test_program playercore playererror playerutils
playerxdr ${PLAYER_EXTRA_LINK_LIBRARIES})
-ADD_EXECUTABLE (test test.cpp ${sicknav200Srcs})
-TARGET_LINK_LIBRARIES (test playercore playererror playerutils playerxdr
${PLAYER_EXTRA_LINK_LIBRARIES})
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit