YSTest: pseudo_mutex.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

pseudo_mutex.h
浏览该文件的文档.
1 /*
2 © 2014-2016 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YB_INC_ystdex_pseudo_mutex_h_
29 #define YB_INC_ystdex_pseudo_mutex_h_ 1
30
31 #include "ref.hpp" // for lref, std::declval;
32 #include "base.h" // for noncopyable, nonmovable;
33 #include <chrono> // for std::chrono::duration, std::chrono::time_point;
34 #include "exception.h" // for std::addressof, throw_error, std::errc;
35
36 namespace ystdex
37 {
38
43 namespace threading
44 {
45
51 yconstexpr const struct defer_lock_t
52 {} defer_lock{};
53
54 yconstexpr const struct try_to_lock_t
55 {} try_to_lock{};
56
57 yconstexpr const struct adopt_lock_t
58 {} adopt_lock{};
60
67 template<class _type, typename _tReference = lref<_type>>
69 class lockable_adaptor
70 {
71 public:
73 using holder_type = _type;
74 using reference = _tReference;
75
76 private:
77 reference ref;
78
79 public:
81
82 lockable_adaptor(holder_type& m) ynothrow
83 : ref(m)
84 {}
85
86 explicit
87 operator holder_type&() ynothrow
88 {
89 return ref;
90 }
91 explicit
92 operator const holder_type&() const ynothrow
93 {
94 return ref;
95 }
96
97 void
98 lock()
99 {
100 ref.get().lock();
101 }
102
104 bool
105 try_lock()
106 {
107 return ref.get().try_lock();
108 }
109
111
112 template<typename _tRep, typename _tPeriod>
113 bool
114 try_lock_for(const std::chrono::duration<_tRep, _tPeriod>& rel_time)
115 {
116 return ref.get().try_lock_for(rel_time);
117 }
118
119 template<typename _tClock, typename _tDuration>
120 bool
121 try_lock_until(const std::chrono::time_point<_tClock, _tDuration>& abs_time)
122 {
123 return ref.get().try_lock_until(abs_time);
124 }
126
127 void
128 unlock() ynothrowv
129 {
130 ref.get().unlock();
131 }
133 };
134
135
137 template<class _type, typename _tReference = lref<_type>>
138 class shared_lockable_adaptor
139 {
140 public:
142 using holder_type = _type;
143 using reference = _tReference;
144
145 private:
146 reference ref;
147
148 public:
149 shared_lockable_adaptor(holder_type& m) ynothrow
150 : ref(m)
151 {}
152
153 explicit
154 operator holder_type&() ynothrow
155 {
156 return ref;
157 }
158 explicit
159 operator const holder_type&() const ynothrow
160 {
161 return ref;
162 }
163
165
166 void
167 lock()
168 {
169 ref.get().lock_shared();
170 }
171
173 bool
174 try_lock()
175 {
176 return ref.get().try_lock_shared();
177 }
178
180
181 template<typename _tRep, typename _tPeriod>
182 bool
183 try_lock_for(const std::chrono::duration<_tRep, _tPeriod>& rel_time)
184 {
185 return ref.get().try_lock_shared_for(rel_time);
186 }
187
188 template<typename _tClock, typename _tDuration>
189 bool
190 try_lock_until(const std::chrono::time_point<_tClock, _tDuration>& abs_time)
191 {
192 return ref.get().try_lock_shared_until(abs_time);
193 }
195
196 void
197 unlock() ynothrow
198 {
199 ref.get().unlock_shared();
200 }
202 };
204
205
207
208
221 template<class _tMutex, bool = true, typename _tReference = _tMutex&>
222 class lock_guard : private yimpl(noncopyable), private yimpl(nonmovable)
223 {
224 ynoexcept_assert("Invalid type found.",
225 _tReference(std::declval<_tMutex&>()));
226
227 public:
228 using mutex_type = _tMutex;
229 using reference = _tReference;
230
231 private:
232 mutex_type& owned;
233
234 public:
239 explicit
240 lock_guard(mutex_type& m)
241 : owned(m)
242 {
243 reference(owned).lock();
244 }
249 lock_guard(mutex_type& m, adopt_lock_t) yimpl(ynothrow)
250 : owned(m)
251 {}
252 ~lock_guard()
253 {
254 reference(owned).unlock();
255 }
256 };
257
258 template<class _tMutex, typename _tReference>
259 class lock_guard<_tMutex, false, _tReference>
260 : private yimpl(noncopyable), private yimpl(nonmovable)
261 {
262 public:
263 using mutex_type = _tMutex;
264
265 explicit
266 lock_guard(mutex_type&) yimpl(ynothrow)
267 {}
268 lock_guard(mutex_type&, adopt_lock_t) yimpl(ynothrow)
269 {}
270 };
271
272
274
275 template<class _tMutex, bool _bEnableCheck = true, class _tReference = _tMutex&>
276 class lock_base : private noncopyable
277 {
278 ynoexcept_assert("Invalid type found.",
279 _tReference(std::declval<_tMutex&>()));
280
281 public:
282 using mutex_type = _tMutex;
283 using reference = _tReference;
284
285 private:
286 mutex_type* pm;
287 bool owns;
288
289 public:
290 lock_base() ynothrow
291 : pm(), owns()
292 {}
293
295
296 explicit
297 lock_base(mutex_type& m)
298 : lock_base(m, defer_lock)
299 {
300 lock();
301 owns = true;
302 }
303 lock_base(mutex_type& m, defer_lock_t) ynothrow
304 : pm(std::addressof(m)), owns()
305 {}
310 lock_base(mutex_type& m, try_to_lock_t)
311 : pm(std::addressof(m)), owns(get_ref().try_lock())
312 {}
314 lock_base(mutex_type& m, adopt_lock_t) yimpl(ynothrow)
315 : pm(std::addressof(m)), owns(true)
316 {}
322 template<typename _tClock, typename _tDuration>
323 lock_base(mutex_type& m, const std::chrono::time_point<_tClock,
324 _tDuration>& abs_time)
325 : pm(std::addressof(m)), owns(get_ref().try_lock_until(abs_time))
326 {}
327 template<typename _tRep, typename _tPeriod>
328 lock_base(mutex_type& m,
329 const std::chrono::duration<_tRep, _tPeriod>& rel_time)
330 : pm(std::addressof(m)), owns(get_ref().try_lock_for(rel_time))
331 {}
333
334
338 lock_base(lock_base&& u) ynothrow
339 : pm(u.pm), owns(u.owns)
340 {
341 yunseq(u.pm = {}, u.owns = {});
342 }
343 ~lock_base()
344 {
345 if(owns)
346 unlock();
347 }
348
354 lock_base&
355 operator=(lock_base&& u) yimpl(ynothrow)
356 {
357 if(owns)
358 unlock();
359 swap(u, *this);
360 u.clear_members();
361 return *this;
362 }
363
364 explicit
365 operator bool() const ynothrow
366 {
367 return owns;
368 }
369
370 private:
371 void
372 check_lock()
373 {
374 using namespace std;
375
376 if(!pm)
377 throw_error(errc::operation_not_permitted);
378 if(owns)
379 throw_error(errc::resource_deadlock_would_occur);
380 }
381
382 void
383 clear_members() yimpl(ynothrow)
384 {
385 yunseq(pm = {}, owns = {});
386 }
387
388 reference
389 get_ref() ynothrow
390 {
391 yassume(pm);
392 return reference(*pm);
393 }
394
395 public:
396 void
397 lock()
398 {
399 check_lock();
400 get_ref().lock();
401 owns = true;
402 }
403
405 bool
406 try_lock()
407 {
408 check_lock();
409 return owns = get_ref().try_lock();
410 }
411
413
414 template<typename _tRep, typename _tPeriod>
415 bool
416 try_lock_for(const std::chrono::duration<_tRep, _tPeriod>& rel_time)
417 {
418 check_lock();
419 return owns = get_ref().try_lock_for(rel_time);
420 }
421
422 template<typename _tClock, typename _tDuration>
423 bool
424 try_lock_until(const std::chrono::time_point<_tClock, _tDuration>& abs_time)
425 {
426 check_lock();
427 return owns = get_ref().try_lock_until(abs_time);
428 }
430
431 void
432 unlock()
433 {
434 if(!owns)
435 throw_error(std::errc::operation_not_permitted);
436 if(pm)
437 {
438 get_ref().unlock();
439 owns = {};
440 }
441 }
442
443 friend void
444 swap(lock_base& x, lock_base& y) ynothrow
445 {
446 std::swap(x.pm, y.pm),
447 std::swap(x.owns, y.owns);
448 }
449
450 mutex_type*
451 release() ynothrow
452 {
453 const auto res(pm);
454
455 clear_members();
456 return res;
457 }
458
459 bool
460 owns_lock() const ynothrow
461 {
462 return owns;
463 }
464
465 mutex_type*
466 mutex() const ynothrow
467 {
468 return pm;
469 }
470 };
471
472 template<class _tMutex, class _tReference>
473 class lock_base<_tMutex, false, _tReference>
474 {
475 public:
476 using mutex_type = _tMutex;
477
478 lock_base() ynothrow yimpl(= default);
479 explicit
480 lock_base(mutex_type&) yimpl(ynothrow)
481 {}
482 lock_base(mutex_type&, defer_lock_t) ynothrow
483 {}
484 lock_base(mutex_type&, try_to_lock_t) yimpl(ynothrow)
485 {}
486 lock_base(mutex_type&, adopt_lock_t) yimpl(ynothrow)
487 {}
488 template<typename _tClock, typename _tDuration>
489 lock_base(mutex_type&,
490 const std::chrono::time_point<_tClock, _tDuration>&) yimpl(ynothrow)
491 {}
492 template<typename _tRep, typename _tPeriod>
493 lock_base(mutex_type&, const std::chrono::duration<_tRep, _tPeriod>&)
494 yimpl(ynothrow)
495 {}
496 lock_base(lock_base&&) yimpl(= default);
497
499 lock_base&
500 operator=(lock_base&&) = yimpl(default);
501
502 explicit
503 operator bool() const ynothrow
504 {
505 return true;
506 }
507
508 void
509 lock()
510 {}
511
512 bool
513 try_lock() yimpl(ynothrow)
514 {
515 return true;
516 }
517
518 template<typename _tRep, typename _tPeriod>
519 bool
520 try_lock_for(const std::chrono::duration<_tRep, _tPeriod>&) yimpl(ynothrow)
521 {
522 return true;
523 }
524
525 template<typename _tClock, typename _tDuration>
526 bool
527 try_lock_until(const std::chrono::time_point<_tClock, _tDuration>&)
528 yimpl(ynothrow)
529 {
530 return true;
531 }
532
533 void
534 unlock() yimpl(ynothrow)
535 {}
536
537 friend void
538 swap(lock_base&, lock_base&) ynothrow
539 {}
540
541 mutex_type*
542 release() ynothrow
543 {
544 return {};
545 }
546
547 bool
548 owns_lock() const ynothrow
549 {
550 return true;
551 }
552
553 mutex_type*
554 mutex() const ynothrow
555 {
556 return {};
557 }
558 };
560
561
562
564 template<class _tMutex, bool _bEnableCheck = true>
565 class unique_lock : private yimpl(lock_base<_tMutex, _bEnableCheck>)
566 {
567 private:
568 using base = yimpl(lock_base<_tMutex, _bEnableCheck>);
569
570 public:
571 using mutex_type = _tMutex;
572
573 public:
574 unique_lock() ynothrow yimpl(= default);
575 using yimpl(base::base);
576 unique_lock(unique_lock&&) yimpl(= default);
577
584 unique_lock&
585 operator=(unique_lock&&) yimpl(= default);
586
587 using yimpl(base)::operator bool;
588
589 using yimpl(base)::lock;
590
592 using yimpl(base)::try_lock;
593
595
596 using yimpl(base)::try_lock_for;
597
598 using yimpl(base)::try_lock_until;
600
601 using yimpl(base)::unlock;
602
603 void
604 swap(unique_lock& u) ynothrow
605 {
606 swap(static_cast<base&>(*this), static_cast<base&>(u));
607 }
608
609 using yimpl(base)::release;
610
611 using yimpl(base)::owns_lock;
612
613 using yimpl(base)::mutex;
614 };
615
617 template<class _tMutex, bool _bEnableCheck>
618 inline void
619 swap(unique_lock<_tMutex, _bEnableCheck>& x,
620 unique_lock<_tMutex, _bEnableCheck>& y) ynothrow
621 {
622 x.swap(y);
623 }
624
625
627 template<class _tMutex, bool _bEnableCheck = true>
628 class shared_lock : private yimpl(lock_base<_tMutex, _bEnableCheck,
629 shared_lockable_adaptor<_tMutex>>)
630 {
631 private:
632 using base = yimpl(lock_base<_tMutex, _bEnableCheck,
633 shared_lockable_adaptor<_tMutex>>);
634
635 public:
636 using mutex_type = _tMutex;
637
638 public:
639 shared_lock() ynothrow yimpl(= default);
640 using yimpl(base::base);
641 shared_lock(shared_lock&&) yimpl(= default);
642
648 shared_lock&
649 operator=(shared_lock&&) yimpl(= default);
650
651 using yimpl(base)::operator bool;
652
654
655 void
656 lock()
657 {
658 base::lock_shared();
659 }
660
662 bool
663 try_lock()
664 {
665 return base::try_lock_shared();
666 }
667
669
670 template<typename _tRep, typename _tPeriod>
671 bool
672 try_lock_shared_for(const std::chrono::duration<_tRep, _tPeriod>& rel_time)
673 {
674 return base::template try_lock_shared_for(rel_time);
675 }
676
677 template<typename _tClock, typename _tDuration>
678 bool
679 try_lock_shared_until(const
680 std::chrono::time_point<_tClock, _tDuration>& abs_time)
681 {
682 return base::template try_lock_shared_until(abs_time);
683 }
685
686
687 using yimpl(base)::unlock;
688
689 void
690 swap(shared_lock& u) ynothrow
691 {
692 swap(static_cast<base&>(*this), static_cast<base&>(u));
693 }
694
695 using yimpl(base)::release;
696
697 using yimpl(base)::owns_lock;
698
699 using yimpl(base)::mutex;
700 };
701
703 template<class _tMutex, bool _bEnableCheck>
704 inline void
705 swap(shared_lock<_tMutex, _bEnableCheck>& x,
706 shared_lock<_tMutex, _bEnableCheck>& y) ynothrow
707 {
708 x.swap(y);
709 }
711
712
713 } // namespace threading;
714
721 namespace single_thread
722 {
723
729 using threading::defer_lock;
730 using threading::defer_lock_t;
731 using threading::try_to_lock;
732 using threading::try_to_lock_t;
733 using threading::adopt_lock;
734 using threading::adopt_lock_t;
736
737
739
740
746 class YB_API mutex : private yimpl(noncopyable), private yimpl(nonmovable)
747 {
748 public:
749 yconstfn
750 mutex() yimpl(= default);
751 ~mutex() yimpl(= default);
752
754 void
755 lock() yimpl(ynothrow)
756 {}
757
758 bool
759 try_lock() yimpl(ynothrow)
760 {
761 return true;
762 }
763
765 void
766 unlock() yimpl(ynothrow)
767 {}
768 };
769
770
771 class YB_API recursive_mutex
772 : private yimpl(noncopyable), private yimpl(nonmovable)
773 {
774 public:
775 recursive_mutex() yimpl(= default);
776 ~recursive_mutex() yimpl(= default);
777
778 void
779 lock() yimpl(ynothrow)
780 {}
781
782 bool
783 try_lock() yimpl(ynothrow)
784 {
785 return true;
786 }
787
789 void
790 unlock() yimpl(ynothrow)
791 {}
792 };
793
794
796
797 class YB_API timed_mutex : private yimpl(noncopyable), private yimpl(nonmovable)
798 {
799 public:
800 timed_mutex() yimpl(= default);
801 ~timed_mutex() yimpl(= default);
802
804
805 void
806 lock() yimpl(ynothrow)
807 {}
808
809 bool
810 try_lock() yimpl(ynothrow)
811 {
812 return true;
813 }
814
815 template<typename _tRep, typename _tPeriod>
816 bool
817 try_lock_for(const std::chrono::duration<_tRep, _tPeriod>&) yimpl(ynothrow)
818 {
819 return true;
820 }
821
822 template<typename _tClock, typename _tDuration>
823 bool
824 try_lock_until(const std::chrono::time_point<_tClock, _tDuration>&)
825 yimpl(ynothrow)
826 {
827 return true;
828 }
830
832 void
833 unlock() yimpl(ynothrow)
834 {}
835 };
836
837
838 class YB_API recursive_timed_mutex
839 : private yimpl(noncopyable), private yimpl(nonmovable)
840 {
841 public:
842 recursive_timed_mutex() yimpl(= default);
843 ~recursive_timed_mutex() yimpl(= default);
844
845 void
846 lock() yimpl(ynothrow)
847 {}
848
849 bool
850 try_lock() yimpl(ynothrow)
851 {
852 return true;
853 }
854
855 template<typename _tRep, typename _tPeriod>
856 bool
857 try_lock_for(const std::chrono::duration<_tRep, _tPeriod>&) yimpl(ynothrow)
858 {
859 return true;
860 }
861
862 template<typename _tClock, typename _tDuration>
863 bool
864 try_lock_until(const std::chrono::time_point<_tClock, _tDuration>&)
865 yimpl(ynothrow)
866 {
867 return true;
868 }
869
871 void
872 unlock() yimpl(ynothrow)
873 {}
874 };
876
877
882 class shared_timed_mutex : private yimpl(timed_mutex)
883 {
884 private:
885 using base = yimpl(timed_mutex);
886
887 public:
888 shared_timed_mutex() yimpl(= default);
889 ~shared_timed_mutex() yimpl(= default);
890
892
893 using yimpl(base)::lock;
894
895 using yimpl(base)::try_lock;
896
897 using yimpl(base)::try_lock_for;
898
899 using yimpl(base)::try_lock_until;
901
903 using yimpl(base)::unlock;
904
906
907 void
908 lock_shared() yimpl(ynothrow)
909 {}
910
911 bool
912 try_lock_shared() yimpl(ynothrow)
913 {
914 return true;
915 }
916
917 template<typename _tRep, typename _tPeriod>
918 bool
919 try_lock_shared_for(const std::chrono::duration<_tRep, _tPeriod>&)
920 yimpl(ynothrow)
921 {
922 return true;
923 }
924
925 template<typename _tClock, typename _tDuration>
926 bool
927 try_lock_shared_until(const std::chrono::time_point<_tClock, _tDuration>&)
928 yimpl(ynothrow)
929 {
930 return true;
931 }
933
935 void
936 unlock_shared()
937 {}
938 };
940
941
948 template<class _tMutex>
949 using lock_guard = threading::lock_guard
950 #ifdef NDEBUG
951 <_tMutex, false>;
952 #else
953 <_tMutex>;
954 #endif
955
956
957 template<class _tMutex>
958 using unique_lock = threading::unique_lock
959 #ifdef NDEBUG
960 <_tMutex, false>;
961 #else
962 <_tMutex>;
963 #endif
964
965
966 template<class _tMutex>
967 using shared_lock = threading::shared_lock
968 #ifdef NDEBUG
969 <_tMutex, false>;
970 #else
971 <_tMutex>;
972 #endif
973
974
975
981 template<class _tLock1, class _tLock2, class... _tLocks>
982 yconstfn int
983 try_lock(_tLock1&&, _tLock2&&, _tLocks&&...) yimpl(ynothrow)
984 {
985 return -1;
986 }
987
988 template<class _tLock1, class _tLock2, class... _tLocks>
989 void
990 lock(_tLock1&&, _tLock2&&, _tLocks&&...) yimpl(ynothrow)
991 {}
993
994
1000 struct YB_API once_flag : private yimpl(noncopyable), private yimpl(nonmovable)
1001 {
1002 yimpl(bool) state = {};
1003
1004 yconstfn
1005 once_flag() ynothrow yimpl(= default);
1006 };
1007
1019 template<typename _fCallable, typename... _tParams>
1020 inline void
1021 call_once(once_flag& flag, _fCallable&& f, _tParams&&... args)
1022 {
1023 if(!flag.state)
1024 {
1025 f(yforward(args)...);
1026 flag.state = true;
1027 }
1028 }
1030
1031
1032 } // namespace single_thread;
1033
1034
1035 namespace threading
1036 {
1037
1043 template<class _tMutex = single_thread::mutex,
1044 class _tLock = single_thread::unique_lock<_tMutex>>
1045 class unlock_delete : private noncopyable
1046 {
1047 public:
1048 using mutex_type = _tMutex;
1049 using lock_type = _tLock;
1050
1051 mutable lock_type lock;
1052
1053 unlock_delete(mutex_type& mtx)
1054 : lock(mtx)
1055 {}
1056 template<typename
1057 = yimpl(enable_if_t)<is_nothrow_move_constructible<lock_type>::value>>
1058 unlock_delete(lock_type&& lck) ynothrow
1059 : lock(std::move(lck))
1060 {}
1061 template<typename... _tParams>
1062 unlock_delete(mutex_type& mtx, _tParams&&... args) ynoexcept(
1063 std::declval<mutex_type&>()(std::declval<_tParams&&>()...))
1064 : lock(mtx, yforward(args)...)
1065 {}
1066
1068 template<typename _tPointer>
1069 void
1070 operator()(const _tPointer&) const ynothrow
1071 {
1072 lock.unlock();
1073 }
1074 };
1075
1076
1081 template<typename _type, class _tMutex = single_thread::mutex,
1082 class _tLock = single_thread::unique_lock<_tMutex>>
1083 using locked_ptr = std::unique_ptr<_type, unlock_delete<_tMutex, _tLock>>;
1084
1085 } // namespace threading;
1086
1087 } // namespace ystdex;
1088
1089 #endif
1090
ystdex::threading::lock_base::owns
bool owns
Definition: pseudo_mutex.h:287
ystdex::threading::lockable_adaptor::ref
reference ref
Definition: pseudo_mutex.h:77
ystdex::threading::unique_lock::swap
void swap(unique_lock< _tMutex, _bEnableCheck > &x, unique_lock< _tMutex, _bEnableCheck > &y)
Definition: pseudo_mutex.h:619
ystdex::threading::unlock_delete::lock_type
_tLock lock_type
Definition: pseudo_mutex.h:1049
ystdex::threading::lock_base::lock_base
lock_base(lock_base &&u)
Definition: pseudo_mutex.h:338
ystdex::threading::defer_lock_t
Definition: pseudo_mutex.h:51
ystdex::single_thread::lock_guard
threading::lock_guard< _tMutex > lock_guard
Definition: pseudo_mutex.h:953
ystdex::threading::unique_lock::mutex_type
_tMutex mutex_type
Definition: pseudo_mutex.h:571
ystdex::threading::lock_base< _tMutex, false, _tReference >::lock_base
lock_base(mutex_type &, try_to_lock_t)
Definition: pseudo_mutex.h:484
ystdex::single_thread::recursive_timed_mutex::try_lock_until
bool try_lock_until(const std::chrono::time_point< _tClock, _tDuration > &)
Definition: pseudo_mutex.h:864
ystdex::single_thread::shared_timed_mutex::try_lock_shared
bool try_lock_shared()
Definition: pseudo_mutex.h:912
ystdex::threading::lock_base< _tMutex, false, _tReference >::lock_base
lock_base(mutex_type &, const std::chrono::duration< _tRep, _tPeriod > &)
Definition: pseudo_mutex.h:493
ystdex::threading::lock_guard::lock_guard
lock_guard(mutex_type &m)
Definition: pseudo_mutex.h:240
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:680
ystdex::single_thread::mutex::unlock
void unlock()
Definition: pseudo_mutex.h:766
ystdex::threading::shared_lockable_adaptor::reference
_tReference reference
Definition: pseudo_mutex.h:143
ystdex::single_thread::timed_mutex::unlock
void unlock()
Definition: pseudo_mutex.h:833
ystdex::threading::lock_base< _tMutex, false, _tReference >::mutex_type
_tMutex mutex_type
Definition: pseudo_mutex.h:476
ystdex::threading::shared_lockable_adaptor::try_lock_until
bool try_lock_until(const std::chrono::time_point< _tClock, _tDuration > &abs_time)
Definition: pseudo_mutex.h:190
ystdex::single_thread::shared_timed_mutex::unlock_shared
void unlock_shared()
Definition: pseudo_mutex.h:936
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
NPL::x
const TermNode &term ynothrow const TermNode &term ynothrow const TermNode &term ynothrow TermNode &term const TermNode &term ValueNode &node const ValueNode &node const _type & x
Definition: SContext.h:94
ystdex::threading::shared_lock::swap
void swap(shared_lock &u)
Definition: pseudo_mutex.h:690
ystdex::single_thread::recursive_timed_mutex::lock
void lock()
Definition: pseudo_mutex.h:846
ystdex::threading::lock_base::clear_members
void clear_members()
Definition: pseudo_mutex.h:383
ystdex::threading::adopt_lock
const struct ystdex::threading::adopt_lock_t adopt_lock
ystdex::threading::shared_lockable_adaptor::holder_type
_type holder_type
Definition: pseudo_mutex.h:142
CHRLib::f
f(d, s)
ystdex::threading::lock_base::lock_base
lock_base(mutex_type &m)
Definition: pseudo_mutex.h:297
ystdex::threading::shared_lock
Definition: pseudo_mutex.h:628
ystdex::threading::lockable_adaptor::try_lock
bool try_lock()
Definition: pseudo_mutex.h:105
ynoexcept_assert
#define ynoexcept_assert(_msg,...)
表达式 noexcept 静态断言。
Definition: ydef.h:747
ystdex::threading::lock_base< _tMutex, _bEnableCheck >::mutex_type
_tMutex mutex_type
Definition: pseudo_mutex.h:282
ystdex::threading::lock_base::lock
void lock()
Definition: pseudo_mutex.h:397
platform::bool
std::FILE *fp bool
Definition: FileIO.h:1280
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:262
ystdex::single_thread::timed_mutex::try_lock_for
bool try_lock_for(const std::chrono::duration< _tRep, _tPeriod > &)
Definition: pseudo_mutex.h:817
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: type_traits.hpp:343
ystdex::threading::shared_lockable_adaptor::unlock
void unlock()
Definition: pseudo_mutex.h:197
ystdex::threading::lock_base< _tMutex, false, _tReference >::swap
friend void swap(lock_base &, lock_base &)
Definition: pseudo_mutex.h:538
ystdex::threading::lock_base::try_lock_for
bool try_lock_for(const std::chrono::duration< _tRep, _tPeriod > &rel_time)
Definition: pseudo_mutex.h:416
ystdex::threading::shared_lockable_adaptor::try_lock
bool try_lock()
Definition: pseudo_mutex.h:174
CHRLib::args
_tParams && args
Definition: CharacterProcessing.h:538
ystdex::single_thread::mutex::lock
void lock()
Definition: pseudo_mutex.h:755
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:679
ystdex::threading::unlock_delete::mutex_type
_tMutex mutex_type
Definition: pseudo_mutex.h:1048
ystdex::single_thread::recursive_timed_mutex
Definition: pseudo_mutex.h:838
ystdex::single_thread::recursive_mutex::try_lock
bool try_lock()
Definition: pseudo_mutex.h:783
ystdex::threading::lock_base::operator=
lock_base & operator=(lock_base &&u)
Definition: pseudo_mutex.h:355
ystdex::threading::try_to_lock_t
Definition: pseudo_mutex.h:54
ystdex::single_thread::recursive_mutex::unlock
void unlock()
Definition: pseudo_mutex.h:790
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1022
ystdex::threading::lock_base::mutex
mutex_type * mutex() const
Definition: pseudo_mutex.h:466
ystdex::threading::lock_base< _tMutex, false, _tReference >::lock_base
lock_base(mutex_type &, adopt_lock_t)
Definition: pseudo_mutex.h:486
ystdex::single_thread::shared_timed_mutex::try_lock_shared_until
bool try_lock_shared_until(const std::chrono::time_point< _tClock, _tDuration > &)
Definition: pseudo_mutex.h:927
ystdex::threading::unlock_delete
解锁删除器。
Definition: pseudo_mutex.h:1045
ystdex::threading::shared_lock::swap
void swap(shared_lock< _tMutex, _bEnableCheck > &x, shared_lock< _tMutex, _bEnableCheck > &y)
Definition: pseudo_mutex.h:705
ystdex::threading::shared_lockable_adaptor::lock
void lock()
Definition: pseudo_mutex.h:167
ystdex::threading::shared_lock::try_lock_shared_for
bool try_lock_shared_for(const std::chrono::duration< _tRep, _tPeriod > &rel_time)
Definition: pseudo_mutex.h:672
ystdex::single_thread::timed_mutex::try_lock_until
bool try_lock_until(const std::chrono::time_point< _tClock, _tDuration > &)
Definition: pseudo_mutex.h:824
ystdex::throw_error
void throw_error(std::error_code ec, _tParams &&...args)
抛出错误： std::system_error 或允许相同构造函数参数的异常。
Definition: ystdex/exception.h:206
ystdex::threading::adopt_lock_t
Definition: pseudo_mutex.h:57
ystdex::threading::lock_base::lock_base
lock_base(mutex_type &m, const std::chrono::time_point< _tClock, _tDuration > &abs_time)
Definition: pseudo_mutex.h:323
ystdex::threading::lockable_adaptor::holder_type
_type holder_type
Definition: pseudo_mutex.h:73
ystdex::threading::lock_base::unlock
void unlock()
Definition: pseudo_mutex.h:432
ystdex::threading::lock_guard::~lock_guard
~lock_guard()
Definition: pseudo_mutex.h:252
ystdex::threading::lockable_adaptor::reference
_tReference reference
Definition: pseudo_mutex.h:74
ystdex::threading::defer_lock
const struct ystdex::threading::defer_lock_t defer_lock
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:766
ystdex::threading::lock_base::pm
mutex_type * pm
Definition: pseudo_mutex.h:286
ystdex::threading::lockable_adaptor::lockable_adaptor
lockable_adaptor(holder_type &m)
Definition: pseudo_mutex.h:82
ystdex::single_thread::recursive_timed_mutex::unlock
void unlock()
Definition: pseudo_mutex.h:872
ystdex::threading::lock_base::get_ref
reference get_ref()
Definition: pseudo_mutex.h:389
ystdex
特性测试宏。
Definition: ydef.h:822
ystdex::threading::lock_base::try_lock_until
bool try_lock_until(const std::chrono::time_point< _tClock, _tDuration > &abs_time)
Definition: pseudo_mutex.h:424
ystdex::threading::lock_guard::reference
_tReference reference
Definition: pseudo_mutex.h:229
ystdex::threading::unlock_delete::unlock_delete
unlock_delete(mutex_type &mtx, _tParams &&...args)
Definition: pseudo_mutex.h:1062
ystdex::threading::lock_base::check_lock
void check_lock()
Definition: pseudo_mutex.h:372
ystdex::threading::shared_lockable_adaptor::ref
reference ref
Definition: pseudo_mutex.h:146
ystdex::single_thread::timed_mutex::try_lock
bool try_lock()
Definition: pseudo_mutex.h:810
ref.hpp
引用包装。
ystdex::threading::lock_guard< _tMutex, false, _tReference >::mutex_type
_tMutex mutex_type
Definition: pseudo_mutex.h:263
base.h
基类实用设施。
ystdex::threading::lock_base::lock_base
lock_base()
Definition: pseudo_mutex.h:290
ystdex::threading::unlock_delete::lock
lock_type lock
Definition: pseudo_mutex.h:1051
ystdex::threading::shared_lock::try_lock
bool try_lock()
Definition: pseudo_mutex.h:663
exception.h
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:786
ystdex::single_thread::shared_timed_mutex::try_lock_shared_for
bool try_lock_shared_for(const std::chrono::duration< _tRep, _tPeriod > &)
Definition: pseudo_mutex.h:919
ystdex::threading::lock_guard< _tMutex, false, _tReference >::lock_guard
lock_guard(mutex_type &, adopt_lock_t)
Definition: pseudo_mutex.h:268
ystdex::threading::lock_base::try_lock
bool try_lock()
Definition: pseudo_mutex.h:406
ystdex::swap
void swap(container_adaptor< _tSeqCon > &x, container_adaptor< _tSeqCon > &y)
Definition: container.hpp:179
ystdex::threading::unlock_delete::operator()
void operator()(const _tPointer &) const
删除：解锁。
Definition: pseudo_mutex.h:1070
ystdex::threading::lock_base::lock_base
lock_base(mutex_type &m, const std::chrono::duration< _tRep, _tPeriod > &rel_time)
Definition: pseudo_mutex.h:328
ystdex::threading::lock_base< _tMutex, false, _tReference >::lock_base
lock_base(mutex_type &, defer_lock_t)
Definition: pseudo_mutex.h:482
ystdex::threading::unlock_delete::unlock_delete
unlock_delete(lock_type &&lck)
Definition: pseudo_mutex.h:1058
ystdex::single_thread::call_once
void call_once(once_flag &flag, _fCallable &&f, _tParams &&...args)
按标识调用函数，保证调用一次。
Definition: pseudo_mutex.h:1021
ystdex::threading::lock_guard::mutex_type
_tMutex mutex_type
Definition: pseudo_mutex.h:228
ystdex::threading::lock_guard::owned
mutex_type & owned
Definition: pseudo_mutex.h:232
std
Definition: memory.hpp:1183
ystdex::single_thread::shared_lock
threading::shared_lock< _tMutex > shared_lock
Definition: pseudo_mutex.h:971
ystdex::threading::lock_guard< _tMutex, false, _tReference >::lock_guard
lock_guard(mutex_type &)
Definition: pseudo_mutex.h:266
ystdex::threading::lockable_adaptor::try_lock_until
bool try_lock_until(const std::chrono::time_point< _tClock, _tDuration > &abs_time)
Definition: pseudo_mutex.h:121
ystdex::threading::shared_lock::mutex_type
_tMutex mutex_type
Definition: pseudo_mutex.h:636
ystdex::threading::lock_base::lock_base
lock_base(mutex_type &m, defer_lock_t)
Definition: pseudo_mutex.h:303
ystdex::threading::lockable_adaptor
Definition: pseudo_mutex.h:69
ystdex::threading::lockable_adaptor::unlock
void unlock()
Definition: pseudo_mutex.h:128
ystdex::single_thread::recursive_timed_mutex::try_lock_for
bool try_lock_for(const std::chrono::duration< _tRep, _tPeriod > &)
Definition: pseudo_mutex.h:857
ystdex::single_thread::try_lock
int try_lock(_tLock1 &&, _tLock2 &&, _tLocks &&...)
Definition: pseudo_mutex.h:983
ystdex::single_thread::once_flag
Definition: pseudo_mutex.h:1000
ystdex::threading::lock_base< _tMutex, false, _tReference >::mutex
mutex_type * mutex() const
Definition: pseudo_mutex.h:554
ystdex::noncopyable
不可复制对象：禁止派生类调用默认原型的复制构造函数和复制赋值操作符。
Definition: base.h:41
ystdex::threading::shared_lockable_adaptor
Definition: pseudo_mutex.h:138
ystdex::threading::lock_base< _tMutex, false, _tReference >::release
mutex_type * release()
Definition: pseudo_mutex.h:542
ystdex::threading::lock_base< _tMutex, false, _tReference >::unlock
void unlock()
Definition: pseudo_mutex.h:534
ystdex::threading::lock_base::lock_base
lock_base(mutex_type &m, try_to_lock_t)
Definition: pseudo_mutex.h:310
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:995
ystdex::single_thread::recursive_mutex
Definition: pseudo_mutex.h:771
yassume
#define yassume(_expr)
假定：环境语义。
Definition: cassert.h:105
ystdex::threading::lock_base< _tMutex, false, _tReference >::lock_base
lock_base(mutex_type &, const std::chrono::time_point< _tClock, _tDuration > &)
Definition: pseudo_mutex.h:489
ystdex::threading::lock_base< _tMutex, false, _tReference >::lock
void lock()
Definition: pseudo_mutex.h:509
ystdex::single_thread::lock
void lock(_tLock1 &&, _tLock2 &&, _tLocks &&...)
Definition: pseudo_mutex.h:990
ystdex::single_thread::recursive_timed_mutex::try_lock
bool try_lock()
Definition: pseudo_mutex.h:850
ystdex::threading::lock_guard::lock_guard
lock_guard(mutex_type &m, adopt_lock_t)
Definition: pseudo_mutex.h:249
ystdex::threading::lock_guard
Definition: pseudo_mutex.h:222
ystdex::single_thread::mutex::try_lock
bool try_lock()
Definition: pseudo_mutex.h:759
ystdex::threading::unlock_delete::unlock_delete
unlock_delete(mutex_type &mtx)
Definition: pseudo_mutex.h:1053
ystdex::single_thread::recursive_mutex::lock
void lock()
Definition: pseudo_mutex.h:779
ystdex::threading::locked_ptr
std::unique_ptr< _type, unlock_delete< _tMutex, _tLock >> locked_ptr
独占所有权的锁定指针。
Definition: pseudo_mutex.h:1083
ystdex::single_thread::mutex
Definition: pseudo_mutex.h:746
ystdex::single_thread::unique_lock
threading::unique_lock< _tMutex > unique_lock
Definition: pseudo_mutex.h:962
YB_API
#define YB_API
YBase 应用程序编程接口：用于向库文件约定链接。
Definition: ydef.h:592
ystdex::threading::lock_base::swap
friend void swap(lock_base &x, lock_base &y)
Definition: pseudo_mutex.h:444
ystdex::threading::try_to_lock
const struct ystdex::threading::try_to_lock_t try_to_lock
ystdex::threading::lock_base< _tMutex, false, _tReference >::try_lock_for
bool try_lock_for(const std::chrono::duration< _tRep, _tPeriod > &)
Definition: pseudo_mutex.h:520
ystdex::single_thread::shared_timed_mutex
Definition: pseudo_mutex.h:882
ystdex::single_thread::timed_mutex
Definition: pseudo_mutex.h:797
ystdex::threading::lock_base< _tMutex, false, _tReference >::try_lock_until
bool try_lock_until(const std::chrono::time_point< _tClock, _tDuration > &)
Definition: pseudo_mutex.h:527
ystdex::threading::shared_lock::try_lock_shared_until
bool try_lock_shared_until(const std::chrono::time_point< _tClock, _tDuration > &abs_time)
Definition: pseudo_mutex.h:679
ystdex::threading::lockable_adaptor::lock
void lock()
Definition: pseudo_mutex.h:98
ystdex::threading::lock_base< _tMutex, false, _tReference >::owns_lock
bool owns_lock() const
Definition: pseudo_mutex.h:548
ystdex::threading::lock_base::release
mutex_type * release()
Definition: pseudo_mutex.h:451
ystdex::threading::unique_lock
Definition: pseudo_mutex.h:565
ystdex::threading::shared_lockable_adaptor::shared_lockable_adaptor
shared_lockable_adaptor(holder_type &m)
Definition: pseudo_mutex.h:149
ystdex::threading::lock_base
锁基类：可适配独占锁和共享锁。
Definition: pseudo_mutex.h:276
ystdex::threading::lock_base< _tMutex, false, _tReference >::try_lock
bool try_lock()
Definition: pseudo_mutex.h:513
ystdex::threading::lock_base< _tMutex, _bEnableCheck >::reference
_tMutex & reference
Definition: pseudo_mutex.h:283
ystdex::threading::shared_lockable_adaptor::try_lock_for
bool try_lock_for(const std::chrono::duration< _tRep, _tPeriod > &rel_time)
Definition: pseudo_mutex.h:183
ystdex::threading::lockable_adaptor::try_lock_for
bool try_lock_for(const std::chrono::duration< _tRep, _tPeriod > &rel_time)
Definition: pseudo_mutex.h:114
ystdex::threading::lock_base::owns_lock
bool owns_lock() const
Definition: pseudo_mutex.h:460
ystdex::single_thread::timed_mutex::lock
void lock()
Definition: pseudo_mutex.h:806
ynoexcept
#define ynoexcept(...)
YSLib 无异常抛出保证：指定特定的异常规范。
Definition: ydef.h:746
ystdex::threading::lock_base::~lock_base
~lock_base()
Definition: pseudo_mutex.h:343
ystdex::threading::lock_base::lock_base
lock_base(mutex_type &m, adopt_lock_t)
Definition: pseudo_mutex.h:314