Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
AbortableMutex.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Execution_AbortableMutex_h_
5#define _Stroika_Foundation_Execution_AbortableMutex_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <memory>
10#include <mutex>
11
12#include "Stroika/Foundation/Common/Common.h"
13
14/*
15 *
16 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
17 *
18 *
19 * TODO:
20 * @todo CONSIDER DEPRECATING - since totally unused as of 2024-06-24 - I think - and looks like a bad idea.
21 *
22 * @todo http://stroika-bugs.sophists.com/browse/STK-600
23 * Rename this to InterruptibleMutex - and simple wrapper around any existing timed mutex, but with args
24 * saying time freq to check, and automatically so try with shorter timeouts.
25 *
26 * @todo TOTALLY UNTESTED
27 *
28 * @todo May need (want) to add try_lock etc (Lockable versus BasicLockable)
29 *
30 * @todo Initial implementation is inefficent (using timed_mutex). COULD do #ifdef based
31 * more efficient impls, directly using pthread_mutex (since it returns on EINTR) I think.
32 *
33 * Not SURE how todo better with MSFT - but I'm sure they have some alertable API that
34 * comes down to a mutex (or close)
35 *
36 * But this is a good enough start -- good enuf to test if this fixes any issues and is
37 * a reasonable placeholder.
38 *
39 * @todo Need AbortableRecursiveMutex, and possibly AbortableTimedMutex, and AbortableTimedRecursiveMutext.
40 *
41 * @todo Add regtests for this
42 *
43 * @todo make NOT copyable - /moveable etc - just like std::mutex (for docs - autodone by priovate fM_).
44 *
45 * Notes:
46 *
47 *
48 *
49 */
50
52
53 /**
54 * This is equivalent to std::mutex, except that when a thread is blocked in a lock() call
55 * it can still be interrupted by Thread::Abort ().
56 *
57 * This is not generally necessary for quick mutexes, but for any mutex use where you could
58 * block/lock for an extended time, it makes sense to use this instead. This is completely
59 * compatible with std::mutex otherwise, and can be used with std::lock_guard<> etc.
60 */
62 public:
63 /**
64 * \note ***Cancelation Point***
65 */
66 nonvirtual void lock ();
67
68 /**
69 */
70 nonvirtual void unlock ();
71
72 private:
73 timed_mutex fM_;
74 };
75
76}
77
78/*
79 ********************************************************************************
80 ***************************** Implementation Details ***************************
81 ********************************************************************************
82 */
83#include "AbortableMutex.inl"
84
85#endif /*_Stroika_Foundation_Execution_AbortableMutex_h_*/