File tree 3 files changed +66
-1
lines changed
3 files changed +66
-1
lines changed Original file line number Diff line number Diff line change @@ -199,7 +199,7 @@ MODULE_ID="CORE"
199
199
MODULE_DEPENDS=()
200
200
ModuleLibIncs=(${SRS_OBJS_DIR} )
201
201
MODULE_FILES=(" srs_core" " srs_core_version5" " srs_core_autofree" " srs_core_performance"
202
- " srs_core_time" " srs_core_platform" )
202
+ " srs_core_time" " srs_core_platform" " srs_core_lock " )
203
203
CORE_INCS=" src/core" ; MODULE_DIR=${CORE_INCS} . auto/modules.sh
204
204
CORE_OBJS=" ${MODULE_OBJS[@]} "
205
205
#
Original file line number Diff line number Diff line change
1
+ //
2
+ // Copyright (c) 2013-2021 The SRS Authors
3
+ //
4
+ // SPDX-License-Identifier: MIT or MulanPSL-2.0
5
+ //
6
+
7
+ #include < srs_core_autofree.hpp>
8
+
Original file line number Diff line number Diff line change
1
+ //
2
+ // Copyright (c) 2013-2021 The SRS Authors
3
+ //
4
+ // SPDX-License-Identifier: MIT or MulanPSL-2.0
5
+ //
6
+
7
+ #ifndef SRS_CORE_LOCK_HPP
8
+ #define SRS_CORE_LOCK_HPP
9
+
10
+ #include < pthread.h>
11
+
12
+ #include < srs_core.hpp>
13
+
14
+ #include < stdlib.h>
15
+
16
+ class SrsScopeLock
17
+ {
18
+ private:
19
+ pthread_mutex_t * mutex_;
20
+ bool locked_;
21
+
22
+ public:
23
+ explicit SrsScopeLock (pthread_mutex_t * mutex)
24
+ {
25
+ mutex_ = mutex;
26
+ locked_ = false ;
27
+
28
+ lock ();
29
+ }
30
+
31
+ ~SrsScopeLock ()
32
+ {
33
+ unlock ();
34
+ }
35
+
36
+ void lock ()
37
+ {
38
+ if (locked_) {
39
+ return ;
40
+ }
41
+
42
+ locked_ = true ;
43
+ pthread_mutex_lock (mutex_);
44
+ }
45
+
46
+ void unlock ()
47
+ {
48
+ if (! locked_) {
49
+ return ;
50
+ }
51
+
52
+ locked_ = false ;
53
+ pthread_mutex_unlock (mutex_);
54
+ }
55
+ };
56
+
57
+ #endif
You can’t perform that action at this time.
0 commit comments