[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / src / zthread / PrioritySemaphore.cxx
blob15138b5f426141f65df3796317b7ea25549d0e6e
1 /*
2 * Copyright (c) 2005, Eric Crahen
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is furnished
9 * to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #include "Debug.h"
24 #include "zthread/PrioritySemaphore.h"
25 #include "SemaphoreImpl.h"
27 namespace ZThread {
29 class PrioritySemaphoreImpl : public SemaphoreImpl<priority_list> {
30 public:
32 PrioritySemaphoreImpl(int count, unsigned int maxCount)
33 : SemaphoreImpl<priority_list>(count, maxCount, true) { }
37 /**
38 * Create a new semaphore of a given size with a given count
40 * @param initialCount initial count to assign this semaphore
41 * @param maxCount maximum size of the semaphore count
43 PrioritySemaphore::PrioritySemaphore(int count, unsigned int maxCount) {
45 _impl = new PrioritySemaphoreImpl(count, maxCount);
49 PrioritySemaphore::~PrioritySemaphore() {
51 if(_impl != 0)
52 delete _impl;
56 void PrioritySemaphore::wait() {
58 _impl->acquire();
63 bool PrioritySemaphore::tryWait(unsigned long ms) {
65 return _impl->tryAcquire(ms);
69 void PrioritySemaphore::post() {
71 _impl->release();
75 int PrioritySemaphore::count() {
77 return _impl->count();
81 ///////////////////////////////////////////////////////////////////////////////
82 // Locakable compatibility
85 void PrioritySemaphore::acquire() {
87 _impl->acquire();
91 bool PrioritySemaphore::tryAcquire(unsigned long ms) {
93 return _impl->tryAcquire(ms);
98 void PrioritySemaphore::release() {
100 _impl->release();
104 } // namespace ZThread