File: thread_specific.h

package info (click to toggle)
ace 6.0.3%2Bdfsg-0.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 49,368 kB
  • sloc: cpp: 341,826; perl: 30,850; ansic: 20,952; makefile: 10,144; sh: 4,744; python: 828; exp: 787; yacc: 511; xml: 330; lex: 158; lisp: 116; csh: 48; tcl: 5
file content (53 lines) | stat: -rw-r--r-- 1,383 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// $Id: thread_specific.h 80826 2008-03-04 14:51:23Z wotte $

#ifndef ACE_THREAD_SPECIFIC_H

#include "ace/Guard_T.h"
#include "ace/Thread_Mutex.h"

// Define a class that will be stored in thread-specific data.  Note
// that as far as this class is concerned it's just a regular C++
// class.  The ACE_TSS wrapper transparently ensures that objects of
// this class will be placed in thread-specific storage.  All calls on
// ACE_TSS::operator->() are delegated to the appropriate method in
// the Errno class.

class Errno
{
public:
  int error (void) { return this->errno_; }
  void error (int i) { this->errno_ = i; }

  int line (void) { return this->lineno_; }
  void line (int l) { this->lineno_ = l; }

  // Errno::flags_ is a static variable, so we've got to protect it
  // with a mutex since it isn't kept in thread-specific storage.
  int flags (void)
  {
    ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, Errno::lock_, -1);

    return Errno::flags_;
  }

  void flags (int f)
  {
    ACE_GUARD (ACE_Thread_Mutex, ace_mon, Errno::lock_);

    Errno::flags_ = f;
  }

private:
  // = errno_ and lineno_ will be thread-specific data so they don't
  // need a lock.
  int errno_;
  int lineno_;

  static int flags_;
#if defined (ACE_HAS_THREADS)
  // flags_ needs a lock.
  static ACE_Thread_Mutex lock_;
#endif /* ACE_HAS_THREADS */
};

#endif /* ACE_THREAD_SPECIFIC_H */