[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / Mutex.cpp
blob8adcb6f9c64512c54dc400e767f2cc4918d18ff0
1 // $Id: Mutex.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #include "ace/Mutex.h"
5 #if !defined (__ACE_INLINE__)
6 #include "ace/Mutex.inl"
7 #endif /* __ACE_INLINE__ */
9 #include "ace/Log_Msg.h"
10 #include "ace/OS_NS_string.h"
11 #include "ace/os_include/sys/os_mman.h"
14 ACE_RCSID (ace,
15 Mutex,
16 "$Id: Mutex.cpp 80826 2008-03-04 14:51:23Z wotte $")
18 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
20 ACE_ALLOC_HOOK_DEFINE(ACE_Mutex)
22 void
23 ACE_Mutex::dump (void) const
25 // ACE_TRACE ("ACE_Mutex::dump");
27 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
28 #if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
29 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("lockname_ = %s\n"), this->lockname_));
30 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("process_lock_ = %x\n"), this->process_lock_));
31 #endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
32 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));
33 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
36 ACE_Mutex::ACE_Mutex (int type, const ACE_TCHAR *name,
37 ACE_mutexattr_t *arg, mode_t mode)
39 #if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
40 process_lock_ (0),
41 lockname_ (0),
42 #endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
43 removed_ (false)
45 // ACE_TRACE ("ACE_Mutex::ACE_Mutex");
47 // These platforms need process-wide mutex to be in shared memory.
48 #if defined(ACE_HAS_PTHREADS) || defined (ACE_HAS_STHREADS)
49 if (type == USYNC_PROCESS)
51 // Let's see if the shared memory entity already exists.
52 ACE_HANDLE fd = ACE_OS::shm_open (name, O_RDWR | O_CREAT | O_EXCL, mode);
53 if (fd == ACE_INVALID_HANDLE)
55 if (errno == EEXIST)
56 fd = ACE_OS::shm_open (name, O_RDWR | O_CREAT, mode);
57 else
58 return;
60 else
62 // We own this shared memory object! Let's set its size.
63 if (ACE_OS::ftruncate (fd,
64 sizeof (ACE_mutex_t)) == -1)
66 ACE_OS::close (fd);
67 return;
69 this->lockname_ = ACE_OS::strdup (name);
70 if (this->lockname_ == 0)
72 ACE_OS::close (fd);
73 return;
77 this->process_lock_ =
78 (ACE_mutex_t *) ACE_OS::mmap (0,
79 sizeof (ACE_mutex_t),
80 PROT_RDWR,
81 MAP_SHARED,
82 fd,
83 0);
84 ACE_OS::close (fd);
85 if (this->process_lock_ == MAP_FAILED)
86 return;
88 if (this->lockname_
89 && ACE_OS::mutex_init (this->process_lock_,
90 type,
91 name,
92 arg) != 0)
94 ACE_ERROR ((LM_ERROR,
95 ACE_TEXT ("%p\n"),
96 ACE_TEXT ("ACE_Mutex::ACE_Mutex")));
97 return;
100 else
102 // local mutex init if USYNC_PROCESS flag is not enabled.
103 #else
104 ACE_UNUSED_ARG (mode);
105 #endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
107 if (ACE_OS::mutex_init (&this->lock_,
108 type,
109 name,
110 arg) != 0)
111 ACE_ERROR ((LM_ERROR,
112 ACE_TEXT ("%p\n"),
113 ACE_TEXT ("ACE_Mutex::ACE_Mutex")));
114 #if defined(ACE_HAS_PTHREADS) || defined (ACE_HAS_STHREADS)
116 #endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
119 ACE_Mutex::~ACE_Mutex (void)
121 // ACE_TRACE ("ACE_Mutex::~ACE_Mutex");
122 this->remove ();
125 ACE_END_VERSIONED_NAMESPACE_DECL