1 // BotThreading.C -*- C++ -*-
2 // Copyright (c) 2008 Clinton Ebadi
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 #include "BotThreading.H"
26 BotMutex::BotMutex (bool recursive)
28 pthread_t self = pthread_self ();
29 std::cerr << "Mutex Init..."
30 << " Mutex: " << &mutex
31 << " Thread: " << &self
33 pthread_mutexattr_init (&attrs);
36 pthread_mutexattr_settype (&attrs, PTHREAD_MUTEX_RECURSIVE);
38 pthread_mutex_init (&mutex, &attrs);
42 BotMutex::~BotMutex ()
44 pthread_t self = pthread_self ();
45 std::cerr << "Mutex Destroy..."
46 << " Mutex: " << &mutex
47 << " Thread: " << &self
49 pthread_mutex_destroy (&mutex);
50 pthread_mutexattr_destroy (&attrs);
53 void BotMutex::lock ()
55 pthread_t self = pthread_self ();
56 std::cerr << "< Mutex Lock..."
57 << " Mutex: " << &mutex
58 << " Thread: " << &self
60 pthread_mutex_lock (&mutex);
63 void BotMutex::unlock ()
65 pthread_t self = pthread_self ();
66 std::cerr << "> Mutex Unlock..."
67 << " Mutex: " << &mutex
68 << " Thread: " << &self
70 pthread_mutex_unlock (&mutex);
73 #else // non threaded noops
78 BotMutex::~BotMutex ()
81 void BotMutex::lock ()
84 void BotMutex::unlock ()
89 BotLock::BotLock (BotMutex & m)
92 pthread_t self = pthread_self ();
93 std::cerr << "Lock Init..."
95 << " Mutex: " << &mutex
96 << " Thread: " << &self
103 pthread_t self = pthread_self ();
104 std::cerr << "Lock Destroy..."
106 << " Mutex: " << &mutex
107 << " Thread: " << &self