A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
system-thread.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2008 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Mathieu Lacage <mathieu.lacage.inria.fr>
19
*/
20
21
#include "
fatal-error.h
"
22
#include "
system-thread.h
"
23
#include "
log.h
"
24
#include <cstring>
25
26
NS_LOG_COMPONENT_DEFINE
(
"SystemThread"
);
27
28
namespace
ns3 {
29
30
#ifdef HAVE_PTHREAD_H
31
32
SystemThread::SystemThread
(Callback<void> callback)
33
: m_callback (callback)
34
{
35
NS_LOG_FUNCTION
(
this
<< &callback);
36
}
37
38
SystemThread::~SystemThread
()
39
{
40
NS_LOG_FUNCTION
(
this
);
41
}
42
43
void
44
SystemThread::Start
(
void
)
45
{
46
NS_LOG_FUNCTION
(
this
);
47
48
int
rc = pthread_create (&m_thread, NULL, &SystemThread::DoRun,
49
(
void
*)
this
);
50
51
if
(rc)
52
{
53
NS_FATAL_ERROR
(
"pthread_create failed: "
<< rc <<
"=\""
<<
54
strerror (rc) <<
"\"."
);
55
}
56
}
57
58
void
59
SystemThread::Join
(
void
)
60
{
61
NS_LOG_FUNCTION
(
this
);
62
63
void
*thread_return;
64
int
rc = pthread_join (m_thread, &thread_return);
65
if
(rc)
66
{
67
NS_FATAL_ERROR
(
"pthread_join failed: "
<< rc <<
"=\""
<<
68
strerror (rc) <<
"\"."
);
69
}
70
}
71
72
void
*
73
SystemThread::DoRun (
void
*arg)
74
{
75
NS_LOG_FUNCTION
(arg);
76
77
SystemThread
*
self
=
static_cast<
SystemThread
*
>
(arg);
78
self
->m_callback ();
79
80
return
0;
81
}
82
SystemThread::ThreadId
83
SystemThread::Self
(
void
)
84
{
85
NS_LOG_FUNCTION_NOARGS
();
86
return
pthread_self ();
87
}
88
89
bool
90
SystemThread::Equals
(SystemThread::ThreadId
id
)
91
{
92
NS_LOG_FUNCTION
(
id
);
93
return
(pthread_equal (pthread_self (),
id
) != 0);
94
}
95
96
#endif
/* HAVE_PTHREAD_H */
97
98
}
// namespace ns3
fatal-error.h
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:345
system-thread.h
ns3::SystemThread::Start
void Start(void)
Start a thread of execution, running the provided callback.
ns3::SystemThread::~SystemThread
~SystemThread()
Destroy a SystemThread object.
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition:
log.h:309
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition:
fatal-error.h:72
NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("SystemThread")
ns3::SystemThread::SystemThread
SystemThread(Callback< void > callback)
Create a SystemThread object.
ns3::SystemThread::Equals
static bool Equals(ThreadId id)
Compares an TharedId with the current ThreadId .
ns3::SystemThread::Join
void Join(void)
Suspend the caller until the thread of execution, running the provided callback, finishes.
log.h
ns3::SystemThread::Self
static ThreadId Self(void)
Returns the current thread Id.
src
core
model
system-thread.cc
Generated on Sat Apr 19 2014 14:06:52 for ns-3 by
1.8.6