blob: 26ee2e77951f9f097b88320965e3825f027f8cf8 [file] [log] [blame]
Benny Prijonodd859a62005-11-01 16:42:51 +00001/* $Header: /pjproject-0.3/pjlib/include/pj/lock.h 2 10/14/05 12:26a Bennylp $ */
2#ifndef __PJ_LOCK_H__
3#define __PJ_LOCK_H__
4
5/**
6 * @file lock.h
7 * @brief Higher abstraction for locking objects.
8 */
9#include <pj/types.h>
10
11PJ_BEGIN_DECL
12
13/**
14 * @defgroup PJ_LOCK Lock Objects
15 * @ingroup PJ_OS
16 * @{
17 *
18 * <b>Lock Objects</b> are higher abstraction for different lock mechanisms.
19 * It offers the same API for manipulating different lock types (e.g.
20 * @ref PJ_MUTEX "mutex", @ref PJ_SEM "semaphores", or null locks).
21 * Because Lock Objects have the same API for different types of lock
22 * implementation, it can be passed around in function arguments. As the
23 * result, it can be used to control locking policy for a particular
24 * feature.
25 */
26
27
28/**
29 * Create simple, non recursive mutex lock object.
30 *
31 * @param pool Memory pool.
32 * @param name Lock object's name.
33 * @param lock Pointer to store the returned handle.
34 *
35 * @return PJ_SUCCESS or the appropriate error code.
36 */
37PJ_DECL(pj_status_t) pj_lock_create_simple_mutex( pj_pool_t *pool,
38 const char *name,
39 pj_lock_t **lock );
40
41/**
42 * Create recursive mutex lock object.
43 *
44 * @param pool Memory pool.
45 * @param name Lock object's name.
46 * @param lock Pointer to store the returned handle.
47 *
48 * @return PJ_SUCCESS or the appropriate error code.
49 */
50PJ_DECL(pj_status_t) pj_lock_create_recursive_mutex( pj_pool_t *pool,
51 const char *name,
52 pj_lock_t **lock );
53
54
55/**
56 * Create NULL mutex. A NULL mutex doesn't actually have any synchronization
57 * object attached to it.
58 *
59 * @param pool Memory pool.
60 * @param name Lock object's name.
61 * @param lock Pointer to store the returned handle.
62 *
63 * @return PJ_SUCCESS or the appropriate error code.
64 */
65PJ_DECL(pj_status_t) pj_lock_create_null_mutex( pj_pool_t *pool,
66 const char *name,
67 pj_lock_t **lock );
68
69
70#if defined(PJ_HAS_SEMAPHORE) && PJ_HAS_SEMAPHORE != 0
71/**
72 * Create semaphore lock object.
73 *
74 * @param pool Memory pool.
75 * @param name Lock object's name.
76 * @param initial Initial value of the semaphore.
77 * @param max Maximum value of the semaphore.
78 * @param lock Pointer to store the returned handle.
79 *
80 * @return PJ_SUCCESS or the appropriate error code.
81 */
82PJ_DECL(pj_status_t) pj_lock_create_semaphore( pj_pool_t *pool,
83 const char *name,
84 unsigned initial,
85 unsigned max,
86 pj_lock_t **lock );
87
88#endif /* PJ_HAS_SEMAPHORE */
89
90/**
91 * Acquire lock on the specified lock object.
92 *
93 * @param lock The lock object.
94 *
95 * @return PJ_SUCCESS or the appropriate error code.
96 */
97PJ_DECL(pj_status_t) pj_lock_acquire( pj_lock_t *lock );
98
99
100/**
101 * Try to acquire lock on the specified lock object.
102 *
103 * @param lock The lock object.
104 *
105 * @return PJ_SUCCESS or the appropriate error code.
106 */
107PJ_DECL(pj_status_t) pj_lock_tryacquire( pj_lock_t *lock );
108
109
110/**
111 * Release lock on the specified lock object.
112 *
113 * @param lock The lock object.
114 *
115 * @return PJ_SUCCESS or the appropriate error code.
116 */
117PJ_DECL(pj_status_t) pj_lock_release( pj_lock_t *lock );
118
119
120/**
121 * Destroy the lock object.
122 *
123 * @param lock The lock object.
124 *
125 * @return PJ_SUCCESS or the appropriate error code.
126 */
127PJ_DECL(pj_status_t) pj_lock_destroy( pj_lock_t *lock );
128
129
130/** @} */
131
132PJ_END_DECL
133
134
135#endif /* __PJ_LOCK_H__ */
136