1
/* $Id: lock.h 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 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
25
* @brief Higher abstraction for locking objects.
32
* @defgroup PJ_LOCK Lock Objects
36
* <b>Lock Objects</b> are higher abstraction for different lock mechanisms.
37
* It offers the same API for manipulating different lock types (e.g.
38
* @ref PJ_MUTEX "mutex", @ref PJ_SEM "semaphores", or null locks).
39
* Because Lock Objects have the same API for different types of lock
40
* implementation, it can be passed around in function arguments. As the
41
* result, it can be used to control locking policy for a particular
47
* Create simple, non recursive mutex lock object.
49
* @param pool Memory pool.
50
* @param name Lock object's name.
51
* @param lock Pointer to store the returned handle.
53
* @return PJ_SUCCESS or the appropriate error code.
55
PJ_DECL(pj_status_t) pj_lock_create_simple_mutex( pj_pool_t *pool,
60
* Create recursive mutex lock object.
62
* @param pool Memory pool.
63
* @param name Lock object's name.
64
* @param lock Pointer to store the returned handle.
66
* @return PJ_SUCCESS or the appropriate error code.
68
PJ_DECL(pj_status_t) pj_lock_create_recursive_mutex( pj_pool_t *pool,
74
* Create NULL mutex. A NULL mutex doesn't actually have any synchronization
75
* object attached to it.
77
* @param pool Memory pool.
78
* @param name Lock object's name.
79
* @param lock Pointer to store the returned handle.
81
* @return PJ_SUCCESS or the appropriate error code.
83
PJ_DECL(pj_status_t) pj_lock_create_null_mutex( pj_pool_t *pool,
88
#if defined(PJ_HAS_SEMAPHORE) && PJ_HAS_SEMAPHORE != 0
90
* Create semaphore lock object.
92
* @param pool Memory pool.
93
* @param name Lock object's name.
94
* @param initial Initial value of the semaphore.
95
* @param max Maximum value of the semaphore.
96
* @param lock Pointer to store the returned handle.
98
* @return PJ_SUCCESS or the appropriate error code.
100
PJ_DECL(pj_status_t) pj_lock_create_semaphore( pj_pool_t *pool,
106
#endif /* PJ_HAS_SEMAPHORE */
109
* Acquire lock on the specified lock object.
111
* @param lock The lock object.
113
* @return PJ_SUCCESS or the appropriate error code.
115
PJ_DECL(pj_status_t) pj_lock_acquire( pj_lock_t *lock );
119
* Try to acquire lock on the specified lock object.
121
* @param lock The lock object.
123
* @return PJ_SUCCESS or the appropriate error code.
125
PJ_DECL(pj_status_t) pj_lock_tryacquire( pj_lock_t *lock );
129
* Release lock on the specified lock object.
131
* @param lock The lock object.
133
* @return PJ_SUCCESS or the appropriate error code.
135
PJ_DECL(pj_status_t) pj_lock_release( pj_lock_t *lock );
139
* Destroy the lock object.
141
* @param lock The lock object.
143
* @return PJ_SUCCESS or the appropriate error code.
145
PJ_DECL(pj_status_t) pj_lock_destroy( pj_lock_t *lock );
153
#endif /* __PJ_LOCK_H__ */