From 0e8ba3a1940bf2e55364a3066cc56a90c541afe4 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 4 Sep 2006 12:23:44 +0200 Subject: [PATCH] remove unused system files --- SConstruct | 17 +- src/core/exec-commands.h | 58 -- src/core/system-mutex.h | 42 -- src/core/system-semaphore.h | 44 -- src/core/system-thread.h | 41 -- ...wall-clock-ms.h => system-wall-clock-ms.h} | 0 src/core/unix-exec-commands.cc | 516 ------------------ src/core/unix-system-mutex.cc | 82 --- src/core/unix-system-semaphore.cc | 114 ---- src/core/unix-system-thread.cc | 69 --- ...ock-ms.cc => unix-system-wall-clock-ms.cc} | 0 src/core/win32-system-mutex.cc | 78 --- src/core/win32-system-semaphore.cc | 103 ---- src/core/win32-system-thread.cc | 66 --- ...ck-ms.cc => win32-system-wall-clock-ms.cc} | 0 15 files changed, 3 insertions(+), 1227 deletions(-) delete mode 100644 src/core/exec-commands.h delete mode 100644 src/core/system-mutex.h delete mode 100644 src/core/system-semaphore.h delete mode 100644 src/core/system-thread.h rename src/core/{wall-clock-ms.h => system-wall-clock-ms.h} (100%) delete mode 100644 src/core/unix-exec-commands.cc delete mode 100644 src/core/unix-system-mutex.cc delete mode 100644 src/core/unix-system-semaphore.cc delete mode 100644 src/core/unix-system-thread.cc rename src/core/{unix-wall-clock-ms.cc => unix-system-wall-clock-ms.cc} (100%) delete mode 100644 src/core/win32-system-mutex.cc delete mode 100644 src/core/win32-system-semaphore.cc delete mode 100644 src/core/win32-system-thread.cc rename src/core/{win32-wall-clock-ms.cc => win32-system-wall-clock-ms.cc} (100%) diff --git a/SConstruct b/SConstruct index ce14e2fc9..96dad531d 100644 --- a/SConstruct +++ b/SConstruct @@ -476,28 +476,17 @@ env = Environment () if env['PLATFORM'] == 'posix' or env['PLATFORM'] == 'darwin': core.add_external_dep ('pthread') core.add_sources ([ - 'unix-system-semaphore.cc', - 'unix-system-thread.cc', - 'unix-system-mutex.cc', - 'unix-exec-commands.cc', - 'unix-wall-clock-ms.cc', + 'unix-system-wall-clock-ms.cc', 'unix-system-file.cc' ]) elif env['PLATFORM'] == 'win32': core.add_sources ([ - 'win32-system-semaphore.cc', - 'win32-system-thread.cc', - 'win32-system-mutex.cc', - 'win32-wall-clock-ms.cc', + 'win32-system-wall-clock-ms.cc', 'win32-system-file.cc' ]) core.add_inst_headers ([ - 'system-semaphore.h', - 'system-thread.h', - 'system-mutex.h', 'system-file.h', - 'exec-commands.h', - 'wall-clock-ms.h', + 'system-wall-clock-ms.h', 'reference-list.h', 'callback.h', 'test.h' diff --git a/src/core/exec-commands.h b/src/core/exec-commands.h deleted file mode 100644 index 2947889af..000000000 --- a/src/core/exec-commands.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ -/* - * Copyright (c) 2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ -#ifndef EXEC_COMMANDS_H -#define EXEC_COMMANDS_H - -#include -#include -#include -#include "callback.h" - -namespace ns3 { - -class ExecCommandsPrivate; - -class Command { -public: - void reset (void); - void append (std::string arg); - uint32_t get_n (void); - char const *get (uint32_t i); -private: - typedef std::vector Args; - Args m_args; -}; - -class ExecCommands { -public: - typedef Callback CommandCallback; - ExecCommands (uint32_t pool_size); - void enable_log (char const *main_log); - void add (Command command, char const *id); - void start (void); - uint32_t get_size (void); -private: - ExecCommandsPrivate *m_priv; -}; - -}; - -#endif /* EXEC_COMMANDS_H */ diff --git a/src/core/system-mutex.h b/src/core/system-mutex.h deleted file mode 100644 index 64db342a0..000000000 --- a/src/core/system-mutex.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ -/* - * Copyright (c) 2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ -#ifndef SYSTEM_MUTEX_H -#define SYSTEM_MUTEX_H - -#include - -namespace ns3 { - -class SystemMutexPrivate; - -class SystemMutex { -public: - SystemMutex (); - ~SystemMutex (); - void lock (void); - void unlock (void); - private: - SystemMutexPrivate *m_priv; -}; - -}; // namespace ns3 - -#endif /* SYSTEM_MUTEX_H */ diff --git a/src/core/system-semaphore.h b/src/core/system-semaphore.h deleted file mode 100644 index eb114f160..000000000 --- a/src/core/system-semaphore.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ -/* - * Copyright (c) 2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ -#ifndef SYSTEM_SEMAPHORE_H -#define SYSTEM_SEMAPHORE_H - -#include - -namespace ns3 { - -class SystemSemaphorePrivate; - -class SystemSemaphore { -public: - SystemSemaphore (uint32_t init); - ~SystemSemaphore (); - void post (void); - void post (uint32_t n); - void wait (void); - void wait (uint32_t n); -private: - SystemSemaphorePrivate *m_priv; -}; - -}; // namespace ns3 - -#endif /* SYSTEM_SEMAPHORE_H */ diff --git a/src/core/system-thread.h b/src/core/system-thread.h deleted file mode 100644 index a6fbb526f..000000000 --- a/src/core/system-thread.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ -/* - * Copyright (c) 2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ -#ifndef SYSTEM_THREAD_H -#define SYSTEM_THREAD_H - -namespace ns3 { - -class SystemThreadPrivate; - -class SystemThread { -public: - SystemThread (); - virtual ~SystemThread (); -private: - friend class SystemThreadPrivate; - SystemThreadPrivate *m_priv; - virtual void real_run (void) = 0; -}; - -}; // namespace ns3 - - -#endif /* SYSTEM_THREAD_H */ diff --git a/src/core/wall-clock-ms.h b/src/core/system-wall-clock-ms.h similarity index 100% rename from src/core/wall-clock-ms.h rename to src/core/system-wall-clock-ms.h diff --git a/src/core/unix-exec-commands.cc b/src/core/unix-exec-commands.cc deleted file mode 100644 index 641c2ff73..000000000 --- a/src/core/unix-exec-commands.cc +++ /dev/null @@ -1,516 +0,0 @@ -/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ -/* - * Copyright (c) 2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ -#include "exec-commands.h" -#include "system-thread.h" -#include "system-semaphore.h" -#include "system-mutex.h" -#include "callback.h" -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - - -#define noTRACE_COMMAND 1 - -#ifdef TRACE_COMMAND -#include -# define TRACE(x) \ -std::cout << "COMMAND TRACE " << x << std::endl; -#else /* TRACE_COMMAND */ -# define TRACE(format,...) -#endif /* TRACE_COMMAND */ - - -namespace ns3 { - -class LogThread : public SystemThread { -public: - LogThread (int main_log); - virtual ~LogThread (); - void add (int in, int out); -private: - virtual void real_run (void); - void write_to (int fd, char *buffer, int size); - typedef std::vector Fds; - typedef std::vector::iterator FdsI; - - int m_main_log; - Fds m_input_fds; - Fds m_output_fds; - SystemMutex m_fds_mutex; -}; - -LogThread::LogThread (int main_log) - : m_main_log (main_log) -{} - -LogThread::~LogThread () -{} - -void -LogThread::add (int in, int out) -{ - m_fds_mutex.lock (); - m_input_fds.push_back (in); - m_output_fds.push_back (out); - m_fds_mutex.unlock (); -} -void -LogThread::write_to (int fd, char *buffer, int to_write) -{ - while (to_write > 0) { - int written = write (fd, buffer, to_write); - to_write -= written; - buffer += written; - assert (written >= 0); - } -} - -void -LogThread::real_run (void) -{ - char buffer[1024]; - while (true) { - fd_set in; - struct timeval tv; - int retval; - - TRACE ("prepare fd set"); - m_fds_mutex.lock (); - assert (m_input_fds.size () == m_output_fds.size ()); - FD_ZERO (&in); - int max_fd = 0; - for (uint32_t i = 0; i < m_input_fds.size (); i++) { - if (m_input_fds[i] > max_fd) { - max_fd = m_input_fds[i]; - } - FD_SET (m_input_fds[i], &in); - } - m_fds_mutex.unlock (); - TRACE ("fd set prepared"); - - tv.tv_sec = 1; - tv.tv_usec = 0; - - retval = select (max_fd+1, &in, NULL, NULL, &tv); - TRACE ("selected"); - for (uint32_t i = 0; i < m_input_fds.size (); i++) { - if (FD_ISSET (m_input_fds[i], &in)) { - retval = read (m_input_fds[i], buffer, 1024); - if (retval == 0) { - close (m_output_fds[i]); - TRACE ("closed input"); - m_fds_mutex.lock (); - FdsI cur = m_input_fds.begin (); - cur += i; - m_input_fds.erase (cur); - cur = m_output_fds.begin (); - cur += i; - m_output_fds.erase (cur); - m_fds_mutex.unlock (); - continue; - } - assert (retval > 0); - write_to (m_output_fds[i], buffer, retval); - write_to (m_main_log, buffer, retval); - } - } - TRACE ("written"); - } -} - - -class CommandSystemThread : public SystemThread { -public: - typedef Callback DoneLogCallback; - typedef Callback DoneNoLogCallback; - CommandSystemThread (); - void start_log (Command command, std::string id, DoneLogCallback callback); - void start_no_log (Command command, DoneNoLogCallback callback); - void stop (void); -private: - virtual void real_run (void); - void run_exec (void); - SystemSemaphore m_sem; - bool m_stop; - Command m_command; - std::string m_id; - DoneLogCallback m_done_log; - DoneNoLogCallback m_done_no_log; - bool m_no_log; -}; - -CommandSystemThread::CommandSystemThread () - : m_sem (0), - m_stop (false) -{} - -void -CommandSystemThread::start_no_log (Command command, DoneNoLogCallback done) -{ - m_no_log = true; - m_command = command; - m_done_no_log = done; - m_sem.post (); -} - -void -CommandSystemThread::start_log (Command command, std::string id, DoneLogCallback done) -{ - m_no_log = false; - m_command = command; - m_id = id; - m_done_log = done; - m_sem.post (); -} - -void -CommandSystemThread::stop (void) -{ - m_stop = true; - m_sem.post (); -} - -void -CommandSystemThread::run_exec (void) -{ - char ** args = (char **)malloc (sizeof (char *) * (m_command.get_n ()+1)); - char const *file = m_command.get (0); - args[0] = strdup (m_command.get (0)); - for (uint32_t i = 1; i < m_command.get_n (); i++) { - args[i] = strdup (m_command.get (i)); - //std::cout << "arg " << args[i-1] << std::endl; - } - args[m_command.get_n ()] = (char *)NULL; - int retval = execvp (file, args); - if (retval != 0) { - std::cout << strerror (errno) << std::endl; - exit (1); - } - // NOTREACHED - assert (false); -} - -void -CommandSystemThread::real_run (void) -{ - while (true) { - m_sem.wait (); - if (m_stop) { - break; - } - int retval; - int filedes[2]; - if (m_no_log) { - pid_t pid = fork (); - if (pid == -1) { - assert (false); - // error in parent fork. - } else if (pid == 0) { - retval = open ("/dev/null", O_WRONLY); - dup2 (retval, 1); - close (retval); - // success, child. - run_exec (); - } else { - // success, parent. - m_done_no_log (this); - } - } else { - retval = pipe (filedes); - assert (retval == 0); - pid_t pid = fork (); - if (pid == -1) { - assert (false); - // error in parent fork. - } else if (pid == 0) { - // success, child. - TRACE ("child"); - close (1); - close (filedes[0]); - dup2 (filedes[1], 1); - run_exec (); - } else { - TRACE ("parent"); - // success, parent. - close (filedes[1]); - m_done_log (this, filedes[0], m_id); - } - } - } -} - -class ExecCommandsPrivate { -public: - ExecCommandsPrivate (uint32_t pool_size); - ~ExecCommandsPrivate (); - void enable_log (char const *main_log); - void add (Command command, std::string id); - void start (void); - uint32_t get_size (void); -private: - struct CommandRequest { - Command m_command; - std::string m_id; - }; - typedef std::vector Threads; - typedef std::vector::iterator ThreadsI; - typedef std::vector Requests; - typedef std::vector::iterator RequestsI; - void command_done_log (CommandSystemThread *thread, int fd, std::string id); - void command_done_no_log (CommandSystemThread *thread); - - Requests m_requests; - SystemSemaphore m_n_threads; - uint32_t m_pool_size; - Threads m_threads; - SystemMutex m_threads_mutex; - int m_main_log; - LogThread *m_log; -}; - - -ExecCommandsPrivate::ExecCommandsPrivate (uint32_t pool_size) - : m_n_threads (0), - m_pool_size (pool_size), - m_main_log (0), - m_log (0) -{ - m_threads_mutex.lock (); - for (uint32_t i = 0; i < pool_size; i++) { - m_threads.push_back (new CommandSystemThread ()); - } - m_threads_mutex.unlock (); - m_n_threads.post (m_pool_size); -} - -ExecCommandsPrivate::~ExecCommandsPrivate () -{ - m_threads_mutex.lock (); - for (ThreadsI i = m_threads.begin (); i != m_threads.end (); i++) { - (*i)->stop (); - delete *i; - } - m_threads.erase (m_threads.begin (), m_threads.end ()); - m_threads_mutex.unlock (); - delete m_log; -} - -void -ExecCommandsPrivate::enable_log (char const *main_log) -{ - m_main_log = open (main_log, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); - m_log = new LogThread (m_main_log); - assert (m_main_log != -1); -} - - -void -ExecCommandsPrivate::add (Command command, std::string id) -{ - struct CommandRequest request; - request.m_command = command; - request.m_id = id; - m_requests.push_back (request); -} -void -ExecCommandsPrivate::start (void) -{ - for (RequestsI i = m_requests.begin (); i != m_requests.end (); i++) { - TRACE ("wait for thread"); - m_n_threads.wait (); - m_threads_mutex.lock (); - CommandSystemThread *thread = m_threads.back (); - m_threads.pop_back (); - m_threads_mutex.unlock (); - TRACE ("start command"); - if (m_main_log != 0) { - thread->start_log (i->m_command, i->m_id, - make_callback (&ExecCommandsPrivate::command_done_log, this)); - } else { - thread->start_no_log (i->m_command, - make_callback (&ExecCommandsPrivate::command_done_no_log, this)); - } - } -} -void -ExecCommandsPrivate::command_done_log (CommandSystemThread *thread, int in, std::string id) -{ - TRACE ("command done"); - m_threads_mutex.lock (); - m_threads.push_back (thread); - m_threads_mutex.unlock (); - m_n_threads.post (); - - std::string out_filename = id; - out_filename.append (".log"); - int out_fd = open (out_filename.c_str (), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); - assert (out_fd != -1); - m_log->add (in, out_fd); - TRACE ("notify command done"); -} - -void -ExecCommandsPrivate::command_done_no_log (CommandSystemThread *thread) -{ - TRACE ("command done"); - m_threads_mutex.lock (); - m_threads.push_back (thread); - m_threads_mutex.unlock (); - m_n_threads.post (); - TRACE ("notify command done"); -} - -uint32_t -ExecCommandsPrivate::get_size (void) -{ - return m_requests.size (); -} - -void -Command::reset (void) -{ - m_args.erase (m_args.begin (), m_args.end ()); -} - -void -Command::append (std::string arg) -{ - m_args.push_back (arg); -} - - -uint32_t -Command::get_n (void) -{ - return m_args.size (); -} -char const* -Command::get (uint32_t i) -{ - return m_args[i].c_str (); -} - - - -ExecCommands::ExecCommands (uint32_t pool_size) - : m_priv (new ExecCommandsPrivate (pool_size)) -{ - assert (pool_size != 0); -} -void -ExecCommands::enable_log (char const *main_log) -{ - m_priv->enable_log (main_log); -} -void -ExecCommands::add (Command command, char const *id) -{ - m_priv->add (command, id); -} -void -ExecCommands::start (void) -{ - m_priv->start (); -} - -uint32_t -ExecCommands::get_size (void) -{ - return m_priv->get_size (); -} - -}; // namespace ns3 - -#ifdef RUN_SELF_TESTS - -#include "test.h" -#include -#include - -namespace ns3 { - -class ExecCommandsTest: public Test { -public: - ExecCommandsTest (); - virtual ~ExecCommandsTest (); - virtual bool run_tests (void); -private: - void command_output (char const *data, uint32_t size); -}; - -ExecCommandsTest::ExecCommandsTest () - : Test ("ExecCommands") -{} -ExecCommandsTest::~ExecCommandsTest () -{} -void -ExecCommandsTest::command_output (char const *data, uint32_t size) -{ - for (uint32_t i = 0; i < size; i++) { - std::cout << data[i]; - }; -} -bool -ExecCommandsTest::run_tests (void) -{ - bool ok = true; -#if 0 - ExecCommands commands = ExecCommands (2); - Command command; - command.append ("ls"); - command.append ("-l"); - commands.add (command, "ls"); - - command.reset (); - command.append ("ls"); - command.append ("-l"); - command.append ("src"); - commands.add (command, "ls-src"); - - command.reset (); - command.append ("ls"); - command.append ("-l"); - command.append ("/usr/bin"); - commands.add (command, "ls-usr-bin"); - - commands.enable_log ("main.log"); - commands.start (); - sleep (5); -#endif - return ok; -} - -static ExecCommandsTest g_exec_commands_test; - -}; // namespace ns3 - -#endif /* RUN_SELF_TESTS */ - - diff --git a/src/core/unix-system-mutex.cc b/src/core/unix-system-mutex.cc deleted file mode 100644 index 6035f0d10..000000000 --- a/src/core/unix-system-mutex.cc +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ -/* - * Copyright (c) 2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#include "system-mutex.h" - -#include -#include - -namespace ns3 { - -class SystemMutexPrivate { -public: - SystemMutexPrivate (); - ~SystemMutexPrivate (); - void lock (void); - void unlock (void); -private: - pthread_mutex_t m_mutex; -}; - -SystemMutexPrivate::SystemMutexPrivate () -{ - int retval; - retval = pthread_mutex_init (&m_mutex, NULL); - assert (retval == 0); -} -SystemMutexPrivate::~SystemMutexPrivate () -{ - int retval; - retval = pthread_mutex_destroy (&m_mutex); - assert (retval == 0); -} -void -SystemMutexPrivate::lock (void) -{ - pthread_mutex_lock (&m_mutex); -} -void -SystemMutexPrivate::unlock (void) -{ - pthread_mutex_unlock (&m_mutex); -} - -SystemMutex::SystemMutex () - : m_priv (new SystemMutexPrivate ()) -{} -SystemMutex::~SystemMutex () -{ - delete m_priv; -} -void -SystemMutex::lock (void) -{ - m_priv->lock (); -} -void -SystemMutex::unlock (void) -{ - m_priv->unlock (); -} - - - -}; // namespace ns3 diff --git a/src/core/unix-system-semaphore.cc b/src/core/unix-system-semaphore.cc deleted file mode 100644 index d36ccd8db..000000000 --- a/src/core/unix-system-semaphore.cc +++ /dev/null @@ -1,114 +0,0 @@ -/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ -/* - * Copyright (c) 2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#include "system-semaphore.h" - -#include -#include -#include -#include "errno.h" -#include "string.h" - -namespace ns3 { - -class SystemSemaphorePrivate { -public: - SystemSemaphorePrivate (uint32_t init); - void post (void); - void post (uint32_t n); - void wait (void); - void wait (uint32_t n); -private: - sem_t m_sem; -}; - -SystemSemaphorePrivate::SystemSemaphorePrivate (uint32_t init) -{ - int retval = sem_init (&m_sem, 0, init); - if (retval == -1) { - std::cout << "sem init " << this << " " << strerror (errno) << std::endl; - } -} -void -SystemSemaphorePrivate::post (void) -{ - int retval = sem_post (&m_sem); - if (retval == -1) { - std::cout << "sem post " << this << " " << strerror (errno) << std::endl; - } -} -void -SystemSemaphorePrivate::wait (void) -{ - int retval; - do { - retval = sem_wait (&m_sem); - } while (retval == -1 && errno == EINTR); - if (retval == -1) { - std::cout << "sem wait " << this << " " << strerror (errno) << std::endl; - } -} -void -SystemSemaphorePrivate::post (uint32_t n) -{ - for (uint32_t i = 0; i < n; i++) { - post (); - } -} -void -SystemSemaphorePrivate::wait (uint32_t n) -{ - for (uint32_t i = 0; i < n; i++) { - wait (); - } -} - -SystemSemaphore::SystemSemaphore (uint32_t init) - : m_priv (new SystemSemaphorePrivate (init)) -{} -SystemSemaphore::~SystemSemaphore () -{ - delete m_priv; -} -void -SystemSemaphore::post (void) -{ - m_priv->post (); -} -void -SystemSemaphore::post (uint32_t n) -{ - m_priv->post (n); -} -void -SystemSemaphore::wait (void) -{ - m_priv->wait (); -} -void -SystemSemaphore::wait (uint32_t n) -{ - m_priv->wait (n); -} - - - -}; // namespace ns3 diff --git a/src/core/unix-system-thread.cc b/src/core/unix-system-thread.cc deleted file mode 100644 index 8e495ef22..000000000 --- a/src/core/unix-system-thread.cc +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ -/* - * Copyright (c) 2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#include "system-thread.h" - -#include -#include - -namespace ns3 { - -class SystemThreadPrivate { -public: - SystemThreadPrivate (SystemThread *thread); - ~SystemThreadPrivate (); -private: - static void *pthread_run (void *thread); - pthread_t m_system_thread; - SystemThread *m_thread; -}; - -SystemThreadPrivate::SystemThreadPrivate (SystemThread *thread) - : m_thread (thread) -{ - int retval; - retval = pthread_create (&m_system_thread, - NULL, - SystemThreadPrivate::pthread_run, - this); - assert (retval == 0); -} -SystemThreadPrivate::~SystemThreadPrivate () -{} -void * -SystemThreadPrivate::pthread_run (void *thread) -{ - SystemThreadPrivate *self = reinterpret_cast (thread); - self->m_thread->real_run (); - return thread; -} - -SystemThread::SystemThread () - : m_priv (new SystemThreadPrivate (this)) -{} - -SystemThread::~SystemThread () -{ - delete m_priv; -} - -}; // namespace ns3 - diff --git a/src/core/unix-wall-clock-ms.cc b/src/core/unix-system-wall-clock-ms.cc similarity index 100% rename from src/core/unix-wall-clock-ms.cc rename to src/core/unix-system-wall-clock-ms.cc diff --git a/src/core/win32-system-mutex.cc b/src/core/win32-system-mutex.cc deleted file mode 100644 index e17c51891..000000000 --- a/src/core/win32-system-mutex.cc +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ -/* - * Copyright (c) 2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#include "system-mutex.h" - -#include -#include - -namespace ns3 { - -class SystemMutexPrivate { -public: - SystemMutexPrivate (); - ~SystemMutexPrivate (); - void lock (void); - void unlock (void); -private: - HANDLE m_mutex; -}; - -SystemMutexPrivate::SystemMutexPrivate () -{ - m_mutex = CreateMutex(NULL, FALSE, "mutex"); -} -SystemMutexPrivate::~SystemMutexPrivate () -{ - CloseHandle (m_mutex); -} -void -SystemMutexPrivate::lock (void) -{ - WaitForSingleObject (m_mutex,INFINITE); -} -void -SystemMutexPrivate::unlock (void) -{ - ReleaseMutex (m_mutex); -} - -SystemMutex::SystemMutex () - : m_priv (new SystemMutexPrivate ()) -{} -SystemMutex::~SystemMutex () -{ - delete m_priv; -} -void -SystemMutex::lock (void) -{ - m_priv->lock (); -} -void -SystemMutex::unlock (void) -{ - m_priv->unlock (); -} - - - -}; // namespace ns3 diff --git a/src/core/win32-system-semaphore.cc b/src/core/win32-system-semaphore.cc deleted file mode 100644 index b752f1f89..000000000 --- a/src/core/win32-system-semaphore.cc +++ /dev/null @@ -1,103 +0,0 @@ -/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ -/* - * Copyright (c) 2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#include "system-semaphore.h" - -#include -#include -#include - -namespace ns3 { - -class SystemSemaphorePrivate { -public: - SystemSemaphorePrivate (uint32_t init); - ~SystemSemaphorePrivate (); - void post (void); - void post (uint32_t n); - void wait (void); - void wait (uint32_t n); -private: - HANDLE m_sem; -}; - -SystemSemaphorePrivate::SystemSemaphorePrivate (uint32_t init) -{ - m_sem = CreateSemaphore(NULL, init, 0, "semaphore"); -} -SystemSemaphorePrivate::~SystemSemaphorePrivate () -{ - CloseHandle (m_sem); -} -void -SystemSemaphorePrivate::post (void) -{ - ReleaseSemaphore(m_sem,1,NULL); -} -void -SystemSemaphorePrivate::wait (void) -{ - WaitForSingleObject (m_sem, INFINITE); -} -void -SystemSemaphorePrivate::post (uint32_t n) -{ - ReleaseSemaphore(m_sem,n,NULL); -} -void -SystemSemaphorePrivate::wait (uint32_t n) -{ - for (uint32_t i = 0; i < n; i++) { - wait (); - } -} - -SystemSemaphore::SystemSemaphore (uint32_t init) - : m_priv (new SystemSemaphorePrivate (init)) -{} -SystemSemaphore::~SystemSemaphore () -{ - delete m_priv; -} -void -SystemSemaphore::post (void) -{ - m_priv->post (); -} -void -SystemSemaphore::post (uint32_t n) -{ - m_priv->post (n); -} -void -SystemSemaphore::wait (void) -{ - m_priv->wait (); -} -void -SystemSemaphore::wait (uint32_t n) -{ - m_priv->wait (n); -} - - - -}; // namespace ns3 diff --git a/src/core/win32-system-thread.cc b/src/core/win32-system-thread.cc deleted file mode 100644 index fa4a79585..000000000 --- a/src/core/win32-system-thread.cc +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ -/* - * Copyright (c) 2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#include "system-thread.h" -#include -#include - -namespace ns3 { - -class SystemThreadPrivate { -public: - SystemThreadPrivate (SystemThread *thread); - ~SystemThreadPrivate (); -private: - static void *thread_run (void *thread); - SystemThread *m_thread; - HANDLE m_system_thread; -}; - -SystemThreadPrivate::SystemThreadPrivate (SystemThread *thread) - : m_thread (thread) -{ - m_system_thread = CreateThread(NULL, 0, - (LPTHREAD_START_ROUTINE)SystemThreadPrivate::thread_run, - this, 0, 0); - assert (m_system_thread != NULL); -} -SystemThreadPrivate::~SystemThreadPrivate () -{} -void * -SystemThreadPrivate::thread_run (void *thread) -{ - SystemThreadPrivate *self = reinterpret_cast (thread); - self->m_thread->real_run (); - return thread; -} - -SystemThread::SystemThread () - : m_priv (new SystemThreadPrivate (this)) -{} - -SystemThread::~SystemThread () -{ - delete m_priv; -} - -}; // namespace ns3 - diff --git a/src/core/win32-wall-clock-ms.cc b/src/core/win32-system-wall-clock-ms.cc similarity index 100% rename from src/core/win32-wall-clock-ms.cc rename to src/core/win32-system-wall-clock-ms.cc