Panda3D

mutexSimpleImpl.cxx

00001 // Filename: mutexSimpleImpl.cxx
00002 // Created by:  drose (19Jun07)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "selectThreadImpl.h"
00016 
00017 #ifdef THREAD_SIMPLE_IMPL
00018 
00019 #include "mutexSimpleImpl.h"
00020 #include "threadSimpleImpl.h"
00021 #include "threadSimpleManager.h"
00022 
00023 ////////////////////////////////////////////////////////////////////
00024 //     Function: MutexSimpleImpl::do_acquire
00025 //       Access: Private
00026 //  Description: 
00027 ////////////////////////////////////////////////////////////////////
00028 void MutexSimpleImpl::
00029 do_acquire() {
00030   // By the time we get here, we already know that someone else is
00031   // holding the lock: (_flags & F_lock_count) != 0.
00032   ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
00033   ThreadSimpleImpl *thread = manager->get_current_thread();
00034 
00035   while ((_flags & F_lock_count) != 0) {
00036     manager->enqueue_block(thread, this);
00037     manager->next_context();
00038   }
00039   
00040   _flags |= F_lock_count;
00041 }
00042 
00043 ////////////////////////////////////////////////////////////////////
00044 //     Function: MutexSimpleImpl::do_release
00045 //       Access: Private
00046 //  Description: 
00047 ////////////////////////////////////////////////////////////////////
00048 void MutexSimpleImpl::
00049 do_release() {
00050   // By the time we get here, we already know that someone else is
00051   // blocked on this mutex: (_flags & F_waiters) != 0.
00052   ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
00053   if (manager->unblock_one(this)) {
00054     // There had been a thread waiting on this mutex.  Switch contexts
00055     // immediately, to make fairness more likely.
00056     ThreadSimpleImpl *thread = manager->get_current_thread();
00057     manager->enqueue_ready(thread, false);
00058     manager->next_context();
00059   }
00060 }
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //     Function: MutexSimpleImpl::do_release_quietly
00064 //       Access: Private
00065 //  Description: 
00066 ////////////////////////////////////////////////////////////////////
00067 void MutexSimpleImpl::
00068 do_release_quietly() {
00069   ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
00070   manager->unblock_one(this);
00071 }
00072 
00073 #endif  // THREAD_SIMPLE_IMPL
 All Classes Functions Variables Enumerations