thread.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #ifndef __ZMQ_THREAD_HPP_INCLUDED__
4 #define __ZMQ_THREAD_HPP_INCLUDED__
5 
6 #if defined ZMQ_HAVE_VXWORKS
7 #include <vxWorks.h>
8 #include <taskLib.h>
9 #elif !defined ZMQ_HAVE_WINDOWS
10 #include <pthread.h>
11 #endif
12 #include <set>
13 #include <cstring>
14 
15 namespace zmq
16 {
17 typedef void (thread_fn) (void *);
18 
19 // Class encapsulating OS thread. Thread initiation/termination is done
20 // using special functions rather than in constructor/destructor so that
21 // thread isn't created during object construction by accident, causing
22 // newly created thread to access half-initialised object. Same applies
23 // to the destruction process: Thread should be terminated before object
24 // destruction begins, otherwise it can access half-destructed object.
25 
26 class thread_t
27 {
28  public:
29  thread_t () :
30  _tfn (NULL),
31  _arg (NULL),
32  _started (false),
35  {
36  memset (_name, 0, sizeof (_name));
37  }
38 
39 #ifdef ZMQ_HAVE_VXWORKS
40  ~thread_t ()
41  {
42  if (descriptor != NULL || descriptor > 0) {
43  taskDelete (descriptor);
44  }
45  }
46 #endif
47 
48  // Creates OS thread. 'tfn' is main thread function. It'll be passed
49  // 'arg' as an argument.
50  // Name is 16 characters max including terminating NUL. Thread naming is
51  // implemented only for pthread, and windows when a debugger is attached.
52  void start (thread_fn *tfn_, void *arg_, const char *name_);
53 
54  // Returns whether the thread was started, i.e. start was called.
55  bool get_started () const;
56 
57  // Returns whether the executing thread is the thread represented by the
58  // thread object.
59  bool is_current_thread () const;
60 
61  // Waits for thread termination.
62  void stop ();
63 
64  // Sets the thread scheduling parameters. Only implemented for
65  // pthread. Has no effect on other platforms.
66  void setSchedulingParameters (int priority_,
67  int scheduling_policy_,
68  const std::set<int> &affinity_cpus_);
69 
70  // These are internal members. They should be private, however then
71  // they would not be accessible from the main C routine of the thread.
73  void applyThreadName ();
75  void *_arg;
76  char _name[16];
77 
78  private:
79  bool _started;
80 
81 #ifdef ZMQ_HAVE_WINDOWS
83 #if defined _WIN32_WCE
84  DWORD _thread_id;
85 #else
86  unsigned int _thread_id;
87 #endif
88 #elif defined ZMQ_HAVE_VXWORKS
89  int _descriptor;
90  enum
91  {
92  DEFAULT_PRIORITY = 100,
93  DEFAULT_OPTIONS = 0,
94  DEFAULT_STACK_SIZE = 4000
95  };
96 #else
97  pthread_t _descriptor;
98 #endif
99 
100  // Thread scheduling parameters.
103  std::set<int> _thread_affinity_cpus;
104 
106 };
107 }
108 
109 #endif
zmq::thread_t::stop
void stop()
Definition: thread.cpp:245
NULL
NULL
Definition: test_security_zap.cpp:405
zmq::thread_t::_thread_affinity_cpus
std::set< int > _thread_affinity_cpus
Definition: thread.hpp:103
zmq::thread_fn
void() thread_fn(void *)
Definition: thread.hpp:17
zmq::thread_t::_arg
void * _arg
Definition: thread.hpp:75
zmq::thread_t::_tfn
thread_fn * _tfn
Definition: thread.hpp:74
descriptor
Descriptor * descriptor
Definition: php/ext/google/protobuf/protobuf.h:936
zmq::thread_t::start
void start(thread_fn *tfn_, void *arg_, const char *name_)
Definition: thread.cpp:234
zmq
Definition: zmq.hpp:229
ZMQ_THREAD_SCHED_POLICY_DFLT
#define ZMQ_THREAD_SCHED_POLICY_DFLT
Definition: zmq.h:196
zmq::thread_t::thread_t
thread_t()
Definition: thread.hpp:29
ZMQ_NON_COPYABLE_NOR_MOVABLE
#define ZMQ_NON_COPYABLE_NOR_MOVABLE(classname)
Definition: macros.hpp:58
zmq::thread_t
Definition: thread.hpp:26
name_
string name_
Definition: googletest.cc:182
zmq::thread_t::applyThreadName
void applyThreadName()
Definition: thread.cpp:350
zmq::thread_t::is_current_thread
bool is_current_thread() const
Definition: thread.cpp:253
void
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
zmq::thread_t::_started
bool _started
Definition: thread.hpp:79
zmq::thread_t::_thread_sched_policy
int _thread_sched_policy
Definition: thread.hpp:102
HANDLE
void * HANDLE
Definition: wepoll.c:70
zmq::thread_t::applySchedulingParameters
void applySchedulingParameters()
Definition: thread.cpp:267
false
#define false
Definition: cJSON.c:70
zmq::thread_t::get_started
bool get_started() const
Definition: thread.cpp:16
zmq::thread_t::_thread_priority
int _thread_priority
Definition: thread.hpp:101
zmq::thread_t::_name
char _name[16]
Definition: thread.hpp:76
ZMQ_THREAD_PRIORITY_DFLT
#define ZMQ_THREAD_PRIORITY_DFLT
Definition: zmq.h:195
zmq::thread_t::_descriptor
pthread_t _descriptor
Definition: thread.hpp:97
zmq::thread_t::setSchedulingParameters
void setSchedulingParameters(int priority_, int scheduling_policy_, const std::set< int > &affinity_cpus_)
Definition: thread.cpp:258


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:07:00