21 #include "ns3/assert.h"
33 #ifdef HAVE_VALGRIND_H
34 # include "valgrind/valgrind.h"
35 # include "valgrind/memcheck.h"
37 # define VALGRIND_STACK_REGISTER(start,end) (0)
38 # define VALGRIND_STACK_DEREGISTER(id)
39 # define VALGRIND_MAKE_MEM_DEFINED(start,sz)
64 unsigned long v = (
unsigned long) address;
70 int size = getpagesize ();
76 int size = getpagesize ();
123 status = pthread_mutex_lock (&
g_mutex);
125 NS_ASSERT_MSG (status == 0,
"lock failed");
130 newstack.ss_size = SIGSTKSZ;
131 newstack.ss_flags = 0;
133 status = sigaltstack (&newstack, &oldstack);
134 NS_ASSERT_MSG (status == 0,
"first sigaltstack failed stack=" << m_stack <<
135 " stacksize=" << SIGSTKSZ);
136 struct sigaction newact;
137 struct sigaction oldact;
139 newact.sa_flags = SA_ONSTACK | SA_RESETHAND;
140 sigemptyset (&newact.sa_mask);
141 status = sigaction (SIGUSR1, &newact, &oldact);
142 NS_ASSERT_MSG (status == 0,
"first sigaction failed");
143 status =
raise (SIGUSR1);
144 NS_ASSERT_MSG (status == 0,
"raise failed");
145 status = sigaltstack (&oldstack, 0);
146 NS_ASSERT_MSG (status == 0,
"second sigaltstack failed");
148 status = pthread_mutex_unlock (&
g_mutex);
149 NS_ASSERT_MSG (status == 0,
"unlock failed");
159 NS_LOG_FUNCTION (
this << thread);
166 if (previous != next)
184 if (setjmp (self->m_buf) == 0)
189 DoWork (self->m_jumpTarget);
193 NS_LOG_DEBUG (
"alternate trampoline stack");
196 if (previous != next)
243 NS_LOG_FUNCTION (
this);
248 NS_LOG_FUNCTION (
this);
255 NS_LOG_FUNCTION (
this << fib);
282 memcpy (dst, src, sz);
292 NS_LOG_DEBUG (
"created clone " << clone);
298 NS_LOG_DEBUG (
"returning from clone " << clone);
306 return __builtin_frame_address (0);
314 error = pthread_attr_init (&attr);
315 NS_ASSERT_MSG (error == 0,
"error=" << strerror (error));
316 error = pthread_attr_setstacksize (&attr, std::max (fiber->
thread->
stack_size,
317 (
size_t)PTHREAD_STACK_MIN));
318 NS_ASSERT_MSG (error == 0,
"error=" << strerror (error));
321 NS_ASSERT_MSG (error == 0,
"error=" << strerror (error));
322 error = pthread_attr_destroy (&attr);
323 NS_ASSERT_MSG (error == 0,
"error=" << strerror (error));
330 NS_LOG_FUNCTION (
this << fiber);
356 NS_LOG_FUNCTION (
this << fiber);
379 NS_LOG_DEBUG (
"Yield after setjmp before wait");
383 NS_LOG_DEBUG (
"Yield after wait");
387 NS_LOG_DEBUG (
"Yield after setjmp");
399 pthread_mutex_lock (&thread->
mutex);
404 pthread_cond_signal (&thread->
condvar);
405 pthread_mutex_unlock (&thread->
mutex);
406 pthread_detach (thread->
thread);
439 pthread_mutex_init (&thread->
mutex, NULL);
440 pthread_cond_init (&thread->
condvar, NULL);
469 int status = pthread_mutex_destroy (&fiber->
thread->
mutex);
470 NS_ASSERT (status == 0);
472 NS_ASSERT (status == 0);
487 const struct Fiber *toFiber)