summaryrefslogtreecommitdiff
path: root/cesar/maximus
diff options
context:
space:
mode:
authorThierry Carré2013-04-18 18:50:22 +0200
committerThierry Carré2013-05-16 14:48:21 +0200
commit921fa4adca872d1e860cccc7a589e2eb42908d9a (patch)
treeee0ff9a0e1339d1e6e9a71e06765b0f05c9c5cd1 /cesar/maximus
parentf4feb8ade549c3da7e92174e0ad8f8aff062a621 (diff)
cesar/maximus/{interface, sci}: build fd_set on sta list changes only, refs #3943
This commit will optimise a little bit the cpu taken. And simplify the 'process' function of SciServer class.
Diffstat (limited to 'cesar/maximus')
-rw-r--r--cesar/maximus/interface/src/Maximus.cpp3
-rw-r--r--cesar/maximus/sci/inc/SciServer.h9
-rw-r--r--cesar/maximus/sci/src/SciServer.cpp57
-rw-r--r--cesar/maximus/sci/utest/server/src/TestSciServer.cpp2
4 files changed, 47 insertions, 24 deletions
diff --git a/cesar/maximus/interface/src/Maximus.cpp b/cesar/maximus/interface/src/Maximus.cpp
index 84e4de457e..6dba773c95 100644
--- a/cesar/maximus/interface/src/Maximus.cpp
+++ b/cesar/maximus/interface/src/Maximus.cpp
@@ -493,6 +493,7 @@ Maximus::create_sta_2 (
seed);
sta_list.push_back (p_station);
+ p_sci_server->update_fd_set ();
if (mpChannel && get_phy ()->isChannelEnabled ())
{
@@ -515,6 +516,8 @@ Maximus::del_station (
logFunction ();
sta_list.remove (p_station);
+ p_sci_server->update_fd_set ();
+
p_scheduler->remove_sta_events (
p_station->getStationId ());
}
diff --git a/cesar/maximus/sci/inc/SciServer.h b/cesar/maximus/sci/inc/SciServer.h
index 7722c60f37..03ae902133 100644
--- a/cesar/maximus/sci/inc/SciServer.h
+++ b/cesar/maximus/sci/inc/SciServer.h
@@ -18,6 +18,7 @@
#include "maximus/sci/sci_msg.h"
#include "maximus/scheduler/scheduler.h"
#include <string>
+#include <sys/types.h>
class SciServer
{
@@ -31,12 +32,20 @@ private:
bool is_server_ready;
+ /* Current fd_set of Sta to Max pipe (or socket) to check. */
+ fd_set fds_sta2max;
+
+ /* Max value of fd for Sta to Max pipe (or socket) to check. */
+ int fd_sta2max_max;
+
public:
SciServer (stations_list_t &ref1);
virtual ~SciServer ();
+ void update_fd_set ();
+
inline void set_station_log (
const std::string &station_log)
{
diff --git a/cesar/maximus/sci/src/SciServer.cpp b/cesar/maximus/sci/src/SciServer.cpp
index 051956ab1f..7172927a7e 100644
--- a/cesar/maximus/sci/src/SciServer.cpp
+++ b/cesar/maximus/sci/src/SciServer.cpp
@@ -34,6 +34,8 @@ SciServer::SciServer (stations_list_t &ref1):
for (unsigned int i = 0; i < SCI_MSG_TYPE_NB; i ++)
processor_array[i] = NULL;
+
+ update_fd_set ();
}
SciServer::~SciServer ()
@@ -42,44 +44,51 @@ SciServer::~SciServer ()
}
void
-SciServer::process () const
+SciServer::update_fd_set ()
{
- logFunction ();
-
- /* polling mode. */
- struct timeval timeout;
- timeout.tv_sec = 0;
- timeout.tv_usec = 0;
-
- fd_set read_fds;
- FD_ZERO (&read_fds);
- int fd_max, fd_min, fd_index;
- bool first_fd = true;
stations_list_t::const_iterator it;
- assert (is_server_ready);
+ FD_ZERO (&fds_sta2max);
+ fd_sta2max_max = 0;
for (it = sta_list.begin () ;
it != sta_list.end ();
it ++)
{
- Station *station = *it;
+ int fd;
- FD_SET (station->getInputFileDescriptor (), &read_fds);
- if (first_fd || (fd_min > station->getInputFileDescriptor ()))
- fd_min = station->getInputFileDescriptor ();
+ fd = (*it)->getInputFileDescriptor ();
+ FD_SET (fd, &fds_sta2max);
+ if (fd > fd_sta2max_max)
+ fd_sta2max_max = fd;
+ }
+}
- if (first_fd || (fd_max < station->getInputFileDescriptor ()))
- fd_max = station->getInputFileDescriptor ();
+void
+SciServer::process () const
+{
+ logFunction ();
+ assert (is_server_ready);
- first_fd = false;
- }
+ struct timeval timeout;
- while (select (fd_max + 1, &read_fds, NULL, NULL, &timeout) > 0)
+ /* polling mode. */
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 0;
+ /* Copy is needed as function is const,
+ * because select request a not const. */
+ fd_set fds_copy = fds_sta2max;
+
+ while (select (fd_sta2max_max + 1, &fds_copy,
+ NULL, NULL, &timeout) > 0)
{
- for (fd_index = fd_min; fd_index <= fd_max; fd_index++)
+ stations_list_t::const_iterator it;
+
+ for (it = sta_list.begin () ; it != sta_list.end (); it ++)
{
- if (!FD_ISSET (fd_index, &read_fds))
+ int fd_index = (*it)->getInputFileDescriptor ();
+
+ if (!FD_ISSET (fd_index, &fds_copy))
continue;
const static int header_size = sizeof (struct Sci_Msg_Header);
diff --git a/cesar/maximus/sci/utest/server/src/TestSciServer.cpp b/cesar/maximus/sci/utest/server/src/TestSciServer.cpp
index d21223c728..74b9c40406 100644
--- a/cesar/maximus/sci/utest/server/src/TestSciServer.cpp
+++ b/cesar/maximus/sci/utest/server/src/TestSciServer.cpp
@@ -62,6 +62,7 @@ TestSciServer::test_pipe_bidir ()
Station *fake_sta = new Station (*max,
"pipe", 0, SCI_MSG_MAX_SIZE);
sta_list.push_back (fake_sta);
+ server->update_fd_set ();
PipoSciMsg *msg = NULL;
for (size_t i = 0; i < SCI_MSG_MAX_SIZE; i++)
@@ -92,6 +93,7 @@ TestSciServer::test_pipe_bidir ()
std::cout << "100%" << std::endl;
sta_list.clear ();
+ server->update_fd_set ();
delete fake_sta;
delete pipo_proc;
}