BlackMutex.h
Go to the documentation of this file.
1  /*
2 
3  ####################################################################################
4  # BlackLib Library controls Beaglebone Black's inputs and outputs. #
5  # Copyright (C) 2013-2015 by Yigit YUCE #
6  ####################################################################################
7  # #
8  # This file is part of BlackLib library. #
9  # #
10  # BlackLib library is free software: you can redistribute it and/or modify #
11  # it under the terms of the GNU Lesser General Public License as published by #
12  # the Free Software Foundation, either version 3 of the License, or #
13  # (at your option) any later version. #
14  # #
15  # BlackLib library is distributed in the hope that it will be useful, #
16  # but WITHOUT ANY WARRANTY; without even the implied warranty of #
17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18  # GNU Lesser General Public License for more details. #
19  # #
20  # You should have received a copy of the GNU Lesser General Public License #
21  # along with this program. If not, see <http://www.gnu.org/licenses/>. #
22  # #
23  # For any comment or suggestion please contact the creator of BlackLib Library #
24  # at ygtyce@gmail.com #
25  # #
26  ####################################################################################
27 
28  */
29 
30 
31 
32 #ifndef BLACKMUTEX_H_
33 #define BLACKMUTEX_H_
34 
35 #include <pthread.h>
36 
37 namespace BlackLib
38 {
39 
40  // ########################################### BLACKMUTEX DECLARATION STARTS ############################################ //
41 
255  {
256  public:
257 
262  {
265  };
266 
303 
307  virtual ~BlackMutex();
308 
387  bool lock();
388 
471  bool tryLock();
472 
562  bool timedLock(unsigned int sec);
563 
574  bool unlock();
575 
651  bool isLocked();
652 
694  bool isRecursive();
695 
779  unsigned int getLockedCount();
780 
781  private:
782  pthread_mutex_t mutex;
783  unsigned int lockCount;
785  };
786 
787  // ############################################ BLACKMUTEX DECLARATION ENDS ############################################# //
788 
789 
790 } /* namespace BlackLib */
791 
792 #endif /* BLACKMUTEX_H_ */
BlackMutex(BlackMutex::mutexMode mm=BlackMutex::NonRecursive)
Constructor of BlackMutex class.
Definition: BlackMutex.cpp:13
bool lock()
Locks the mutex.
Definition: BlackMutex.cpp:42
bool timedLock(unsigned int sec)
Locks the mutex until the time expires.
Definition: BlackMutex.cpp:51
unsigned int getLockedCount()
Exports the mutex lock count.
Definition: BlackMutex.cpp:93
bool isLocked()
Checks the mutex lock state.
Definition: BlackMutex.cpp:83
mutexMode mode
is used to hold the mutex mode property
Definition: BlackMutex.h:784
bool isRecursive()
Checks the mutex recursiveness.
Definition: BlackMutex.cpp:88
Prevents accessing the same memory location at the same time from different threads.
Definition: BlackMutex.h:254
Definition: BlackMutex.h:263
mutexMode
Definition: BlackMutex.h:261
virtual ~BlackMutex()
Destructor of BlackMutex class.
Definition: BlackMutex.cpp:37
Definition: BlackMutex.h:264
bool tryLock()
Tries lock the mutex.
Definition: BlackMutex.cpp:64
bool unlock()
Unlocks the mutex.
Definition: BlackMutex.cpp:73
unsigned int lockCount
is used to hold the mutex lock count
Definition: BlackMutex.h:783
Definition: BlackADC.cpp:36
pthread_mutex_t mutex
is used to hold the mutex posix data structure
Definition: BlackMutex.h:782