summaryrefslogtreecommitdiff
path: root/ACE/tests/TSS_Test_Errno.h
blob: ac4500b85aacd0aca9303f8cdc5522e54ea704f9 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* -*- C++ -*- */

//=============================================================================
/**
 *  @file    TSS_Test_Errno.h
 *
 *  This file contains the definition of Errno.  Some compilers need
 *  it in a .h file for template instantiation (such as AIX C Set
 *  ++).
 *
 *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
 */
//=============================================================================


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

/**
 * @class Errno
 *
 * @brief Define a simple Errno abstraction
 *
 * This class gets its own header file to work around AIX C++
 * compiler "features" related to template instantiation...  It is
 * only used by TSS_Test.cpp.
 */
class Errno
{
public:
  Errno()
  {
    ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_Mon, *Errno::lock_));
    created_ += 1;
  }
  ~Errno()
  {
    ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_Mon, *Errno::lock_));
    deleted_ += 1;
  }

  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_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_Mon, *Errno::lock_, -1));

    return Errno::flags_;
  }
  int flags (int f)
  {
    ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, *Errno::lock_, -1));

    Errno::flags_ = f;
    return 0;
  }

  static int created (void)
  {
    return created_;
  }

  static int deleted (void)
  {
    return deleted_;
  }

#if defined (ACE_HAS_THREADS)
  static
  ACE_Thread_Mutex *
  allocate_lock (void)
  {
    ACE_NEW_RETURN (Errno::lock_, ACE_Thread_Mutex, 0);
    return Errno::lock_;
  }

  static
  void
  deallocate_lock () { delete lock_; lock_ = 0; }
#endif /* ACE_HAS_THREADS */

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

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