Apache log4cxx  Version 0.11.0
synchronized.h
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _LOG4CXX_HELPERS_SYNCHRONIZED_H
19 #define _LOG4CXX_HELPERS_SYNCHRONIZED_H
20 #include <log4cxx/log4cxx.h>
21 
22 extern "C" {
23  typedef struct apr_thread_mutex_t apr_thread_mutex_t;
24 }
25 
26 namespace log4cxx
27 {
28 namespace helpers
29 {
30 class Mutex;
31 
33 class LOG4CXX_EXPORT synchronized
34 {
35  public:
36  synchronized(const Mutex& mutex);
37  synchronized(apr_thread_mutex_t* mutex);
38  ~synchronized();
39 
40 
41  private:
42  void* mutex;
43  // prevent use of copy and assignment
44  synchronized(const synchronized&);
45  synchronized& operator=(const synchronized&);
46 };
47 }
48 }
49 
50 #if defined(RW_MUTEX)
51 
52 namespace log4cxx
53 {
54 namespace helpers
55 {
56 class RWMutex;
57 
58 // utility class for objects multi-thread synchronization.
59 class LOG4CXX_EXPORT synchronized_read
60 {
61  public:
62  synchronized_read(const RWMutex& mutex);
63  ~synchronized_read();
64 
65 
66  private:
67  const RWMutex& mutex;
68  // prevent use of copy and assignment
69  synchronized_read(const synchronized_read&);
70  synchronized_read& operator=(const synchronized_read&);
71 };
72 }
73 }
74 
75 namespace log4cxx
76 {
77 namespace helpers
78 {
79 class RWMutex;
80 
81 // utility class for objects multi-thread synchronization.
82 class LOG4CXX_EXPORT synchronized_write
83 {
84  public:
85  synchronized_write(const RWMutex& mutex);
86  ~synchronized_write();
87 
88 
89  private:
90  const RWMutex& mutex;
91  // prevent use of copy and assignment
92  synchronized_write(const synchronized_write&);
93  synchronized_write& operator=(const synchronized_write&);
94 };
95 }
96 }
97 
98 #define LOCK_R synchronized_read
99 #define LOCK_W synchronized_write
100 
101 #else
102 
103 #define LOCK_R synchronized
104 #define LOCK_W synchronized
105 
106 #endif // RW_MUTEX
107 
108 #endif //_LOG4CXX_HELPERS_SYNCHRONIZED_H
Definition: mutex.h:41
utility class for objects multi-thread synchronization.
Definition: synchronized.h:33
Definition: appender.h:33