00001 // Filename: asyncTaskBase.cxx 00002 // Created by: drose (09Feb10) 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 "asyncTaskBase.h" 00016 #include "thread.h" 00017 #include "atomicAdjust.h" 00018 00019 TypeHandle AsyncTaskBase::_type_handle; 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Function: AsyncTaskBase::Constructor 00023 // Access: Protected 00024 // Description: 00025 //////////////////////////////////////////////////////////////////// 00026 AsyncTaskBase:: 00027 AsyncTaskBase() { 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: AsyncTaskBase::Destructor 00032 // Access: Published, Virtual 00033 // Description: 00034 //////////////////////////////////////////////////////////////////// 00035 AsyncTaskBase:: 00036 ~AsyncTaskBase() { 00037 } 00038 00039 //////////////////////////////////////////////////////////////////// 00040 // Function: AsyncTaskBase::record_task 00041 // Access: Protected 00042 // Description: Indicates that this task is now the current task 00043 // running on the indicated thread, presumably the 00044 // current thread. 00045 //////////////////////////////////////////////////////////////////// 00046 void AsyncTaskBase:: 00047 record_task(Thread *current_thread) { 00048 nassertv(current_thread->_current_task == NULL); 00049 00050 void *result = AtomicAdjust::compare_and_exchange_ptr 00051 ((void * TVOLATILE &)current_thread->_current_task, 00052 (void *)NULL, (void *)this); 00053 00054 // If the return value is other than NULL, someone else must have 00055 // assigned the task first, in another thread. That shouldn't be 00056 // possible. 00057 00058 // But different versions of gcc appear to have problems compiling these 00059 // assertions correctly. 00060 #ifndef __GNUC__ 00061 nassertv(result == NULL); 00062 nassertv(current_thread->_current_task == this); 00063 #endif // __GNUC__ 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: AsyncTaskBase::clear_task 00068 // Access: Protected 00069 // Description: Indicates that this task is no longer running on the 00070 // indicated thread. 00071 //////////////////////////////////////////////////////////////////// 00072 void AsyncTaskBase:: 00073 clear_task(Thread *current_thread) { 00074 nassertv(current_thread->_current_task == this); 00075 00076 void *result = AtomicAdjust::compare_and_exchange_ptr 00077 ((void * TVOLATILE &)current_thread->_current_task, 00078 (void *)this, (void *)NULL); 00079 00080 // If the return value is other than this, someone else must have 00081 // assigned the task first, in another thread. That shouldn't be 00082 // possible. 00083 00084 // But different versions of gcc appear to have problems compiling these 00085 // assertions correctly. 00086 #ifndef __GNUC__ 00087 nassertv(result == this); 00088 nassertv(current_thread->_current_task == NULL); 00089 #endif // __GNUC__ 00090 }