Panda3D
asyncTaskBase.cxx
1 // Filename: asyncTaskBase.cxx
2 // Created by: drose (09Feb10)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "asyncTaskBase.h"
16 #include "thread.h"
17 #include "atomicAdjust.h"
18 
19 TypeHandle AsyncTaskBase::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: AsyncTaskBase::Constructor
23 // Access: Protected
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 AsyncTaskBase::
27 AsyncTaskBase() {
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: AsyncTaskBase::Destructor
32 // Access: Published, Virtual
33 // Description:
34 ////////////////////////////////////////////////////////////////////
35 AsyncTaskBase::
36 ~AsyncTaskBase() {
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: AsyncTaskBase::record_task
41 // Access: Protected
42 // Description: Indicates that this task is now the current task
43 // running on the indicated thread, presumably the
44 // current thread.
45 ////////////////////////////////////////////////////////////////////
46 void AsyncTaskBase::
47 record_task(Thread *current_thread) {
48  nassertv(current_thread->_current_task == NULL);
49 
51  ((void * TVOLATILE &)current_thread->_current_task,
52  (void *)NULL, (void *)this);
53 
54  // If the return value is other than NULL, someone else must have
55  // assigned the task first, in another thread. That shouldn't be
56  // possible.
57 
58  // But different versions of gcc appear to have problems compiling these
59  // assertions correctly.
60 #ifndef __GNUC__
61  nassertv(result == NULL);
62  nassertv(current_thread->_current_task == this);
63 #endif // __GNUC__
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: AsyncTaskBase::clear_task
68 // Access: Protected
69 // Description: Indicates that this task is no longer running on the
70 // indicated thread.
71 ////////////////////////////////////////////////////////////////////
72 void AsyncTaskBase::
73 clear_task(Thread *current_thread) {
74  nassertv(current_thread->_current_task == this);
75 
77  ((void * TVOLATILE &)current_thread->_current_task,
78  (void *)this, (void *)NULL);
79 
80  // If the return value is other than this, someone else must have
81  // assigned the task first, in another thread. That shouldn't be
82  // possible.
83 
84  // But different versions of gcc appear to have problems compiling these
85  // assertions correctly.
86 #ifndef __GNUC__
87  nassertv(result == this);
88  nassertv(current_thread->_current_task == NULL);
89 #endif // __GNUC__
90 }
A thread; that is, a lightweight process.
Definition: thread.h:51
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
static Pointer compare_and_exchange_ptr(Pointer &mem, Pointer old_value, Pointer new_value)
Atomic compare and exchange.