aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/threads
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2005-11-26 15:44:40 +0000
committerMartin Willi <martin@strongswan.org>2005-11-26 15:44:40 +0000
commitc1eb15373373f103e4f69dc3f6d001aa3f69cbc6 (patch)
tree4fdb0bc01003a358ad273e03a398a6bf8c1dc28a /Source/charon/threads
parentf1c91cf037689979049f4904fd3d76f85cd98981 (diff)
downloadstrongswan-c1eb15373373f103e4f69dc3f6d001aa3f69cbc6.tar.bz2
strongswan-c1eb15373373f103e4f69dc3f6d001aa3f69cbc6.tar.xz
- threads are new identified by pid
Diffstat (limited to 'Source/charon/threads')
-rw-r--r--Source/charon/threads/receiver.c5
-rw-r--r--Source/charon/threads/scheduler.c6
-rw-r--r--Source/charon/threads/sender.c3
-rw-r--r--Source/charon/threads/thread_pool.c16
-rw-r--r--Source/charon/threads/thread_pool.h2
5 files changed, 23 insertions, 9 deletions
diff --git a/Source/charon/threads/receiver.c b/Source/charon/threads/receiver.c
index b46949bf2..b78ebcf09 100644
--- a/Source/charon/threads/receiver.c
+++ b/Source/charon/threads/receiver.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <pthread.h>
+#include <unistd.h>
#include "receiver.h"
@@ -71,8 +72,12 @@ static void receive_packets(private_receiver_t * this)
{
packet_t * current_packet;
job_t *current_job;
+
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
+
+ this->logger->log(this->logger, CONTROL, "receiver thread running, pid %d", getpid());
+
while (1)
{
while (global_socket->receive(global_socket,&current_packet) == SUCCESS)
diff --git a/Source/charon/threads/scheduler.c b/Source/charon/threads/scheduler.c
index 8349d3611..774bd3a7c 100644
--- a/Source/charon/threads/scheduler.c
+++ b/Source/charon/threads/scheduler.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <pthread.h>
+#include <unistd.h>
#include "scheduler.h"
@@ -69,9 +70,12 @@ struct private_scheduler_t {
*/
static void get_events(private_scheduler_t * this)
{
+ job_t *current_job;
+
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
- job_t *current_job;
+
+ this->logger->log(this->logger, CONTROL, "scheduler thread running, pid %d", getpid());
for (;;)
{
diff --git a/Source/charon/threads/sender.c b/Source/charon/threads/sender.c
index 5ad00e00f..2b33c0d22 100644
--- a/Source/charon/threads/sender.c
+++ b/Source/charon/threads/sender.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <pthread.h>
+#include <unistd.h>
#include "sender.h"
@@ -73,6 +74,8 @@ static void send_packets(private_sender_t * this)
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
+ this->logger->log(this->logger, CONTROL, "sender thread running, pid %d", getpid());
+
while (1)
{
while (global_send_queue->get(global_send_queue,&current_packet) == SUCCESS)
diff --git a/Source/charon/threads/thread_pool.c b/Source/charon/threads/thread_pool.c
index ee8d50bc7..c22f5fe05 100644
--- a/Source/charon/threads/thread_pool.c
+++ b/Source/charon/threads/thread_pool.c
@@ -24,6 +24,7 @@
#include <pthread.h>
#include <string.h>
#include <errno.h>
+#include <unistd.h>
#include "thread_pool.h"
@@ -104,7 +105,8 @@ static void process_jobs(private_thread_pool_t *this)
{
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
- this->worker_logger->log(this->worker_logger, CONTROL, "started working");
+
+ this->worker_logger->log(this->worker_logger, CONTROL, "worker thread running, pid: %d", getpid());
for (;;) {
job_t *job;
@@ -318,14 +320,14 @@ static status_t destroy(private_thread_pool_t *this)
int current;
/* flag thread for termination */
for (current = 0; current < this->pool_size; current++) {
- this->pool_logger->log(this->pool_logger, CONTROL, "cancelling thread %u", this->threads[current]);
+ this->pool_logger->log(this->pool_logger, CONTROL, "cancelling worker a thread #%d", current+1);
pthread_cancel(this->threads[current]);
}
/* wait for all threads */
for (current = 0; current < this->pool_size; current++) {
pthread_join(this->threads[current], NULL);
- this->pool_logger->log(this->pool_logger, CONTROL, "thread %u terminated", this->threads[current]);
+ this->pool_logger->log(this->pool_logger, CONTROL, "worker thread #%d terminated", current+1);
}
/* free mem */
@@ -384,14 +386,14 @@ thread_pool_t *thread_pool_create(size_t pool_size)
{
if (pthread_create(&(this->threads[current]), NULL, (void*(*)(void*))this->process_jobs, this) == 0)
{
- this->pool_logger->log(this->pool_logger, CONTROL, "thread %u created", this->threads[current]);
+ this->pool_logger->log(this->pool_logger, CONTROL, "created worker thread #%d", current+1);
}
- else
+ else
{
/* creation failed, is it the first one? */
if (current == 0)
{
- this->pool_logger->log(this->pool_logger, ERROR, "could not create any thread: %s\n", strerror(errno));
+ this->pool_logger->log(this->pool_logger, ERROR, "could not create any thread");
global_logger_manager->destroy_logger(global_logger_manager, this->pool_logger);
global_logger_manager->destroy_logger(global_logger_manager, this->worker_logger);
allocator_free(this->threads);
@@ -399,7 +401,7 @@ thread_pool_t *thread_pool_create(size_t pool_size)
return NULL;
}
/* not all threads could be created, but at least one :-/ */
- this->pool_logger->log(this->pool_logger, CONTROL, "could only create %d from requested %d threads: %s\n", current, pool_size, strerror(errno));
+ this->pool_logger->log(this->pool_logger, ERROR, "could only create %d from requested %d threads!", current, pool_size);
this->pool_size = current;
return (thread_pool_t*)this;
diff --git a/Source/charon/threads/thread_pool.h b/Source/charon/threads/thread_pool.h
index aac803ab2..46166bf52 100644
--- a/Source/charon/threads/thread_pool.h
+++ b/Source/charon/threads/thread_pool.h
@@ -1,7 +1,7 @@
/**
* @file thread_pool.h
*
- * @brief Interface for thread_pool_t.
+ * @brief Interface of thread_pool_t.
*
*/