1
/* $Id: lock.hpp 2394 2008-12-23 17:27:53Z bennylp $ */
3
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJPP_LOCK_HPP__
21
#define __PJPP_LOCK_HPP__
23
#include <pj++/types.hpp>
25
#include <pj++/pool.hpp>
27
//////////////////////////////////////////////////////////////////////////////
30
class Pj_Lock : public Pj_Object
36
explicit Pj_Lock(pj_lock_t *lock)
47
pj_lock_destroy(lock_);
51
// Get pjlib compatible lock object.
53
pj_lock_t *pj_lock_t_()
63
return pj_lock_acquire(lock_);
71
return pj_lock_release(lock_);
79
//////////////////////////////////////////////////////////////////////////////
82
class Pj_Null_Lock : public Pj_Lock
86
// Default constructor.
88
explicit Pj_Null_Lock(Pj_Pool *pool, const char *name = NULL)
91
pj_lock_create_null_mutex(pool->pool_(), name, &lock_);
95
//////////////////////////////////////////////////////////////////////////////
96
// Simple mutex lock object.
98
class Pj_Simple_Mutex_Lock : public Pj_Lock
102
// Default constructor.
104
explicit Pj_Simple_Mutex_Lock(Pj_Pool *pool, const char *name = NULL)
107
pj_lock_create_simple_mutex(pool->pool_(), name, &lock_);
111
//////////////////////////////////////////////////////////////////////////////
112
// Recursive mutex lock object.
114
class Pj_Recursive_Mutex_Lock : public Pj_Lock
118
// Default constructor.
120
explicit Pj_Recursive_Mutex_Lock(Pj_Pool *pool, const char *name = NULL)
123
pj_lock_create_recursive_mutex(pool->pool_(), name, &lock_);
127
//////////////////////////////////////////////////////////////////////////////
128
// Semaphore lock object.
130
class Pj_Semaphore_Lock : public Pj_Lock
134
// Default constructor.
136
explicit Pj_Semaphore_Lock(Pj_Pool *pool,
137
unsigned max=PJ_MAXINT32,
139
const char *name=NULL)
142
pj_lock_create_semaphore(pool->pool_(), name, initial, max, &lock_);
148
#endif /* __PJPP_LOCK_HPP__ */