icl_core_thread/ThreadImplPosix.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 #include "ThreadImplPosix.h"
24 
25 #include <assert.h>
26 #include <pthread.h>
27 
29 
30 #include "Thread.h"
31 
32 namespace icl_core {
33 namespace thread {
34 
36  icl_core::ThreadPriority priority)
37  : m_thread_id(0),
38  m_thread(thread),
39  m_priority(priority),
40  m_description(description)
41 { }
42 
44 { }
45 
47 {
48  pthread_cancel(m_thread_id);
49 }
50 
52 {
53  pthread_join(m_thread_id, NULL);
54 }
55 
57 {
58  struct sched_param param;
59  int policy;
60  int ret = pthread_getschedparam(m_thread_id, &policy, &param);
61 
62  if (ret == 0)
63  {
64  return icl_core::ThreadPriority(param.sched_priority);
65  }
66  else
67  {
68  return 0;
69  }
70 }
71 
73 {
74  // First get the current scheduling parameters.
75  struct sched_param param;
76  int policy;
77  int ret = pthread_getschedparam(m_thread_id, &policy, &param);
78 
79  if (ret != 0)
80  {
81  return false;
82  }
83 
84  // Change the thread priority and set it.
85  param.sched_priority = priority;
86  ret = pthread_setschedparam(m_thread_id, policy, &param);
87 
88  return (ret == 0);
89 }
90 
92 {
93  if (pthread_create(&m_thread_id, NULL, ThreadImplPosix::runThread, this))
94  {
95  m_thread_id = 0;
96  }
97 
98  return m_thread_id != 0;
99 }
100 
102 {
104 }
105 
106 void * ThreadImplPosix::runThread(void *arg)
107 {
108  ThreadImplPosix *self = static_cast<ThreadImplPosix*>(arg);
109  self->m_thread->runThread();
110 
111  return NULL;
112 }
113 
114 }
115 }
ICL_CORE_OS_IMPL_NS::ThreadId ThreadId
Definition: os_thread.h:49
virtual icl_core::ThreadPriority priority() const
Posix implementation of the global thread functions.
ThreadImplPosix(Thread *thread, const icl_core::String &description, icl_core::ThreadPriority priority)
virtual icl_core::ThreadId threadId() const
virtual bool setPriority(icl_core::ThreadPriority priority)
std::string String
Definition: BaseTypes.h:43
Contains icl_core::thread::ThreadImpl for posix systems.
Contains icl_core::thread::Thread.
int32_t ThreadPriority
Definition: os_thread.h:50


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58