xref: /aoo41x/main/framework/inc/threadhelp/irwlock.h (revision 228b4580)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef __FRAMEWORK_THREADHELP_IRWLOCK_H_
25 #define __FRAMEWORK_THREADHELP_IRWLOCK_H_
26 
27 //_________________________________________________________________________________________________________________
28 //	includes
29 //_________________________________________________________________________________________________________________
30 
31 //_________________________________________________________________________________________________________________
32 //	namespace
33 //_________________________________________________________________________________________________________________
34 
35 namespace framework{
36 
37 //_________________________________________________________________________________________________________________
38 //	declarations
39 //_________________________________________________________________________________________________________________
40 
41 /*-************************************************************************************************************//**
42 	@descr			A guard (specialy a write guard) support different internal working states.
43 					His lock can set for reading or writing/reading! Or he was unlocked by user ...
44 *//*-*************************************************************************************************************/
45 enum ELockMode
46 {
47 	E_NOLOCK	,
48 	E_READLOCK	,
49 	E_WRITELOCK
50 };
51 
52 /*-************************************************************************************************************//**
53 	@descr			We implement two guards for using an rw-lock. But if you wish to implement
54 					different rw-locks to you will have problems by using with same guard implementation!
55 					Thats why we define this "pure virtual base class" ...
56 					All rw-locks must support this base interface for working and all guard must use this one too!
57 *//*-*************************************************************************************************************/
58 class IRWLock
59 {
60 	//-------------------------------------------------------------------------------------------------------------
61 	//	public methods
62 	//-------------------------------------------------------------------------------------------------------------
63 	public:
64 
65 		/*-****************************************************************************************************//**
66 			@descr		These functions must be supported by a derived class!
67 							acquireReadAccess()		-try to register thread as reader
68 							releaseReadAccess()		-unregister thread as reader
69 							acquireWriteAccess()	-try to register thread as writer
70 							releaseWriteAccess()	-unregister thread as writer
71 							downgradeWriteAccess()	-make writer to reader
72 		*//*-*****************************************************************************************************/
73         virtual void acquireReadAccess    () =0;
74         virtual void releaseReadAccess    () =0;
75         virtual void acquireWriteAccess   () =0;
76         virtual void releaseWriteAccess   () =0;
77         virtual void downgradeWriteAccess () =0;
78 
79 };		//	class IRWLock
80 
81 }		//	namespace framework
82 
83 #endif	//	#ifndef __FRAMEWORK_THREADHELP_IRWLOCK_H_
84