fix a bug about get_reads_from_value
[c11tester.git] / action.cc
1 #include <stdio.h>
2 #define __STDC_FORMAT_MACROS
3 #include <inttypes.h>
4 #include <stdlib.h>
5
6 #include "model.h"
7 #include "action.h"
8 #include "clockvector.h"
9 #include "common.h"
10 #include "threads-model.h"
11 #include "wildcard.h"
12
13 #define ACTION_INITIAL_CLOCK 0
14
15 /** @brief A special value to represent a successful trylock */
16 #define VALUE_TRYSUCCESS 1
17
18 /** @brief A special value to represent a failed trylock */
19 #define VALUE_TRYFAILED 0
20
21 /**
22  * @brief Construct a new ModelAction
23  *
24  * @param type The type of action
25  * @param order The memory order of this action. A "don't care" for non-ATOMIC
26  * actions (e.g., THREAD_* or MODEL_* actions).
27  * @param loc The location that this action acts upon
28  * @param value (optional) A value associated with the action (e.g., the value
29  * read or written). Defaults to a given macro constant, for debugging purposes.
30  * @param thread (optional) The Thread in which this action occurred. If NULL
31  * (default), then a Thread is assigned according to the scheduler.
32  */
33 ModelAction::ModelAction(action_type_t type, memory_order order, void *loc,
34                                                                                                  uint64_t value, Thread *thread) :
35         location(loc),
36         position(NULL),
37         reads_from(NULL),
38         last_fence_release(NULL),
39         uninitaction(NULL),
40         cv(NULL),
41         rf_cv(NULL),
42         value(value),
43         reads_from_value(VALUE_NONE),
44         type(type),
45         order(order),
46         original_order(order),
47         seq_number(ACTION_INITIAL_CLOCK)
48 {
49         /* References to NULL atomic variables can end up here */
50         ASSERT(loc || type == ATOMIC_FENCE || type == NOOP);
51
52         Thread *t = thread ? thread : thread_current();
53         this->tid = t!= NULL ? t->get_id() : -1;
54 }
55
56
57 /**
58  * @brief Construct a new ModelAction for sleep actions
59  *
60  * @param type The type of action: THREAD_SLEEP
61  * @param order The memory order of this action. A "don't care" for non-ATOMIC
62  * actions (e.g., THREAD_* or MODEL_* actions).
63  * @param loc The location that this action acts upon
64  * @param value The time duration a thread is scheduled to sleep.
65  * @param _time The this sleep action is constructed
66  */
67 ModelAction::ModelAction(action_type_t type, memory_order order, uint64_t value, uint64_t _time) :
68         location(NULL),
69         position(NULL),
70         time(_time),
71         last_fence_release(NULL),
72         uninitaction(NULL),
73         cv(NULL),
74         rf_cv(NULL),
75         value(value),
76         reads_from_value(VALUE_NONE),
77         type(type),
78         order(order),
79         original_order(order),
80         seq_number(ACTION_INITIAL_CLOCK)
81 {
82         Thread *t = thread_current();
83         this->tid = t!= NULL ? t->get_id() : -1;
84 }
85
86 /**
87  * @brief Construct a new ModelAction
88  *
89  * @param type The type of action
90  * @param order The memory order of this action. A "don't care" for non-ATOMIC
91  * actions (e.g., THREAD_* or MODEL_* actions).
92  * @param loc The location that this action acts upon
93  * @param value (optional) A value associated with the action (e.g., the value
94  * read or written). Defaults to a given macro constant, for debugging purposes.
95  * @param size (optional) The Thread in which this action occurred. If NULL
96  * (default), then a Thread is assigned according to the scheduler.
97  */
98 ModelAction::ModelAction(action_type_t type, memory_order order, void *loc,
99                                                                                                  uint64_t value, int size) :
100         location(loc),
101         position(NULL),
102         reads_from(NULL),
103         last_fence_release(NULL),
104         uninitaction(NULL),
105         cv(NULL),
106         rf_cv(NULL),
107         value(value),
108         reads_from_value(VALUE_NONE),
109         type(type),
110         order(order),
111         original_order(order),
112         seq_number(ACTION_INITIAL_CLOCK)
113 {
114         /* References to NULL atomic variables can end up here */
115         ASSERT(loc);
116         this->size = size;
117         Thread *t = thread_current();
118         this->tid = t->get_id();
119 }
120
121
122 /**
123  * @brief Construct a new ModelAction with source line number (requires llvm support)
124  *
125  * @param type The type of action
126  * @param order The memory order of this action. A "don't care" for non-ATOMIC
127  * actions (e.g., THREAD_* or MODEL_* actions).
128  * @param loc The location that this action acts upon
129  * @param value (optional) A value associated with the action (e.g., the value
130  * read or written). Defaults to a given macro constant, for debugging purposes.
131  * @param size (optional) The Thread in which this action occurred. If NULL
132  * (default), then a Thread is assigned according to the scheduler.
133  */
134 ModelAction::ModelAction(action_type_t type, const char * position, memory_order order, void *loc,
135                                                                                                  uint64_t value, int size) :
136         location(loc),
137         position(position),
138         reads_from(NULL),
139         last_fence_release(NULL),
140         uninitaction(NULL),
141         cv(NULL),
142         rf_cv(NULL),
143         value(value),
144         reads_from_value(VALUE_NONE),
145         type(type),
146         order(order),
147         original_order(order),
148         seq_number(ACTION_INITIAL_CLOCK)
149 {
150         /* References to NULL atomic variables can end up here */
151         ASSERT(loc);
152         this->size = size;
153         Thread *t = thread_current();
154         this->tid = t->get_id();
155 }
156
157
158 /**
159  * @brief Construct a new ModelAction with source line number (requires llvm support)
160  *
161  * @param type The type of action
162  * @param position The source line number of this atomic operation
163  * @param order The memory order of this action. A "don't care" for non-ATOMIC
164  * actions (e.g., THREAD_* or MODEL_* actions).
165  * @param loc The location that this action acts upon
166  * @param value (optional) A value associated with the action (e.g., the value
167  * read or written). Defaults to a given macro constant, for debugging purposes.
168  * @param thread (optional) The Thread in which this action occurred. If NULL
169  * (default), then a Thread is assigned according to the scheduler.
170  */
171 ModelAction::ModelAction(action_type_t type, const char * position, memory_order order,
172                                                                                                  void *loc, uint64_t value, Thread *thread) :
173         location(loc),
174         position(position),
175         reads_from(NULL),
176         last_fence_release(NULL),
177         uninitaction(NULL),
178         cv(NULL),
179         rf_cv(NULL),
180         value(value),
181         reads_from_value(VALUE_NONE),
182         type(type),
183         order(order),
184         original_order(order),
185         seq_number(ACTION_INITIAL_CLOCK)
186 {
187         /* References to NULL atomic variables can end up here */
188         ASSERT(loc || type == ATOMIC_FENCE);
189
190         Thread *t = thread ? thread : thread_current();
191         this->tid = t->get_id();
192 }
193
194
195 /** @brief ModelAction destructor */
196 ModelAction::~ModelAction()
197 {
198         /**
199          * We can't free the clock vector:
200          * Clock vectors are snapshotting state. When we delete model actions,
201          * they are at the end of the node list and have invalid old clock
202          * vectors which have already been rolled back to an unallocated state.
203          */
204
205         /*
206            if (cv)
207                 delete cv; */
208 }
209
210 int ModelAction::getSize() const {
211         return size;
212 }
213
214 void ModelAction::copy_from_new(ModelAction *newaction)
215 {
216         seq_number = newaction->seq_number;
217 }
218
219 void ModelAction::set_seq_number(modelclock_t num)
220 {
221         /* ATOMIC_UNINIT actions should never have non-zero clock */
222         ASSERT(!is_uninitialized());
223         ASSERT(seq_number == ACTION_INITIAL_CLOCK);
224         seq_number = num;
225 }
226
227 bool ModelAction::is_thread_start() const
228 {
229         return type == THREAD_START;
230 }
231
232 bool ModelAction::is_thread_join() const
233 {
234         return type == THREAD_JOIN || type == PTHREAD_JOIN;
235 }
236
237 bool ModelAction::is_mutex_op() const
238 {
239         return type == ATOMIC_LOCK || type == ATOMIC_TRYLOCK || type == ATOMIC_UNLOCK || type == ATOMIC_WAIT || type == ATOMIC_NOTIFY_ONE || type == ATOMIC_NOTIFY_ALL;
240 }
241
242 bool ModelAction::is_lock() const
243 {
244         return type == ATOMIC_LOCK;
245 }
246
247 bool ModelAction::is_sleep() const
248 {
249         return type == THREAD_SLEEP;
250 }
251
252 bool ModelAction::is_wait() const {
253         return type == ATOMIC_WAIT;
254 }
255
256 bool ModelAction::is_notify() const {
257         return type == ATOMIC_NOTIFY_ONE || type == ATOMIC_NOTIFY_ALL;
258 }
259
260 bool ModelAction::is_notify_one() const {
261         return type == ATOMIC_NOTIFY_ONE;
262 }
263
264 bool ModelAction::is_unlock() const
265 {
266         return type == ATOMIC_UNLOCK;
267 }
268
269 bool ModelAction::is_trylock() const
270 {
271         return type == ATOMIC_TRYLOCK;
272 }
273
274 bool ModelAction::is_success_lock() const
275 {
276         return type == ATOMIC_LOCK || (type == ATOMIC_TRYLOCK && value == VALUE_TRYSUCCESS);
277 }
278
279 bool ModelAction::is_failed_trylock() const
280 {
281         return (type == ATOMIC_TRYLOCK && value == VALUE_TRYFAILED);
282 }
283
284 /** @return True if this operation is performed on a C/C++ atomic variable */
285 bool ModelAction::is_atomic_var() const
286 {
287         return is_read() || could_be_write();
288 }
289
290 bool ModelAction::is_uninitialized() const
291 {
292         return type == ATOMIC_UNINIT;
293 }
294
295 bool ModelAction::is_read() const
296 {
297         return type == ATOMIC_READ || type == ATOMIC_RMWR || type == ATOMIC_RMWRCAS || type == ATOMIC_RMW;
298 }
299
300 bool ModelAction::is_write() const
301 {
302         return type == ATOMIC_WRITE || type == ATOMIC_RMW || type == ATOMIC_INIT || type == ATOMIC_UNINIT || type == NONATOMIC_WRITE;
303 }
304
305 bool ModelAction::could_be_write() const
306 {
307         return is_write() || is_rmwr();
308 }
309
310 bool ModelAction::is_yield() const
311 {
312         return type == THREAD_YIELD;
313 }
314
315 bool ModelAction::is_rmwr() const
316 {
317         return type == ATOMIC_RMWR || type == ATOMIC_RMWRCAS;
318 }
319
320 bool ModelAction::is_rmwrcas() const
321 {
322         return type == ATOMIC_RMWRCAS;
323 }
324
325 bool ModelAction::is_rmw() const
326 {
327         return type == ATOMIC_RMW;
328 }
329
330 bool ModelAction::is_rmwc() const
331 {
332         return type == ATOMIC_RMWC;
333 }
334
335 bool ModelAction::is_fence() const
336 {
337         return type == ATOMIC_FENCE;
338 }
339
340 bool ModelAction::is_initialization() const
341 {
342         return type == ATOMIC_INIT;
343 }
344
345 bool ModelAction::is_annotation() const
346 {
347         return type == ATOMIC_ANNOTATION;
348 }
349
350 bool ModelAction::is_relaxed() const
351 {
352         return order == std::memory_order_relaxed;
353 }
354
355 bool ModelAction::is_acquire() const
356 {
357         switch (order) {
358         case std::memory_order_acquire:
359         case std::memory_order_acq_rel:
360         case std::memory_order_seq_cst:
361                 return true;
362         default:
363                 return false;
364         }
365 }
366
367 bool ModelAction::is_release() const
368 {
369         switch (order) {
370         case std::memory_order_release:
371         case std::memory_order_acq_rel:
372         case std::memory_order_seq_cst:
373                 return true;
374         default:
375                 return false;
376         }
377 }
378
379 bool ModelAction::is_seqcst() const
380 {
381         return order == std::memory_order_seq_cst;
382 }
383
384 bool ModelAction::same_var(const ModelAction *act) const
385 {
386         if (act->is_wait() || is_wait()) {
387                 if (act->is_wait() && is_wait()) {
388                         if (((void *)value) == ((void *)act->value))
389                                 return true;
390                 } else if (is_wait()) {
391                         if (((void *)value) == act->location)
392                                 return true;
393                 } else if (act->is_wait()) {
394                         if (location == ((void *)act->value))
395                                 return true;
396                 }
397         }
398
399         return location == act->location;
400 }
401
402 bool ModelAction::same_thread(const ModelAction *act) const
403 {
404         return tid == act->tid;
405 }
406
407 void ModelAction::copy_typeandorder(ModelAction * act)
408 {
409         this->type = act->type;
410         this->order = act->order;
411 }
412
413 /**
414  * Get the Thread which is the operand of this action. This is only valid for
415  * THREAD_* operations (currently only for THREAD_CREATE and THREAD_JOIN). Note
416  * that this provides a central place for determining the conventions of Thread
417  * storage in ModelAction, where we generally aren't very type-safe (e.g., we
418  * store object references in a (void *) address.
419  *
420  * For THREAD_CREATE, this yields the Thread which is created.
421  * For THREAD_JOIN, this yields the Thread we are joining with.
422  *
423  * @return The Thread which this action acts on, if exists; otherwise NULL
424  */
425 Thread * ModelAction::get_thread_operand() const
426 {
427         if (type == THREAD_CREATE) {
428                 /* thread_operand is set in execution.cc */
429                 return thread_operand;
430         } else if (type == PTHREAD_CREATE) {
431                 return thread_operand;
432         } else if (type == THREAD_JOIN) {
433                 /* THREAD_JOIN uses (Thread *) for location */
434                 return (Thread *)get_location();
435         } else if (type == PTHREAD_JOIN) {
436                 // return NULL;
437                 // thread_operand is stored in execution::pthread_map;
438                 return (Thread *)get_location();
439         } else
440                 return NULL;
441 }
442
443 /**
444  * @brief Convert the read portion of an RMW
445  *
446  * Changes an existing read part of an RMW action into either:
447  *  -# a full RMW action in case of the completed write or
448  *  -# a READ action in case a failed action.
449  *
450  * @todo  If the memory_order changes, we may potentially need to update our
451  * clock vector.
452  *
453  * @param act The second half of the RMW (either RMWC or RMW)
454  */
455 void ModelAction::process_rmw(ModelAction *act)
456 {
457         this->order = act->order;
458         if (act->is_rmwc())
459                 this->type = ATOMIC_READ;
460         else if (act->is_rmw()) {
461                 this->type = ATOMIC_RMW;
462                 this->value = act->value;
463         }
464 }
465
466 /**
467  * @brief Check if this action should be backtracked with another, due to
468  * potential synchronization
469  *
470  * The is_synchronizing method should only explore interleavings if:
471  *  -# the operations are seq_cst and don't commute or
472  *  -# the reordering may establish or break a synchronization relation.
473  *
474  * Other memory operations will be dealt with by using the reads_from relation.
475  *
476  * @param act The action to consider exploring a reordering
477  * @return True, if we have to explore a reordering; otherwise false
478  */
479 bool ModelAction::could_synchronize_with(const ModelAction *act) const
480 {
481         // Same thread can't be reordered
482         if (same_thread(act))
483                 return false;
484
485         // Different locations commute
486         if (!same_var(act) && !is_fence() && !act->is_fence())
487                 return false;
488
489         // Explore interleavings of seqcst writes/fences to guarantee total
490         // order of seq_cst operations that don't commute
491         if ((could_be_write() || act->could_be_write() || is_fence() || act->is_fence()) && is_seqcst() && act->is_seqcst())
492                 return true;
493
494         // Explore synchronizing read/write pairs
495         if (is_acquire() && act->is_release() && is_read() && act->could_be_write())
496                 return true;
497
498         // lock just released...we can grab lock
499         if ((is_lock() || is_trylock()) && (act->is_unlock() || act->is_wait()))
500                 return true;
501
502         // lock just acquired...we can fail to grab lock
503         if (is_trylock() && act->is_success_lock())
504                 return true;
505
506         // other thread stalling on lock...we can release lock
507         if (is_unlock() && (act->is_trylock() || act->is_lock()))
508                 return true;
509
510         if (is_trylock() && (act->is_unlock() || act->is_wait()))
511                 return true;
512
513         if (is_notify() && act->is_wait())
514                 return true;
515
516         if (is_wait() && act->is_notify())
517                 return true;
518
519         // Otherwise handle by reads_from relation
520         return false;
521 }
522
523 bool ModelAction::is_conflicting_lock(const ModelAction *act) const
524 {
525         // Must be different threads to reorder
526         if (same_thread(act))
527                 return false;
528
529         // Try to reorder a lock past a successful lock
530         if (act->is_success_lock())
531                 return true;
532
533         // Try to push a successful trylock past an unlock
534         if (act->is_unlock() && is_trylock() && value == VALUE_TRYSUCCESS)
535                 return true;
536
537         // Try to push a successful trylock past a wait
538         if (act->is_wait() && is_trylock() && value == VALUE_TRYSUCCESS)
539                 return true;
540
541         return false;
542 }
543
544 /**
545  * Create a new clock vector for this action. Note that this function allows a
546  * user to clobber (and leak) a ModelAction's existing clock vector. A user
547  * should ensure that the vector has already either been rolled back
548  * (effectively "freed") or freed.
549  *
550  * @param parent A ModelAction from which to inherit a ClockVector
551  */
552 void ModelAction::create_cv(const ModelAction *parent)
553 {
554         if (parent)
555                 cv = new ClockVector(parent->cv, this);
556         else
557                 cv = new ClockVector(NULL, this);
558 }
559
560 void ModelAction::set_try_lock(bool obtainedlock)
561 {
562         value = obtainedlock ? VALUE_TRYSUCCESS : VALUE_TRYFAILED;
563 }
564
565 /**
566  * @brief Get the value read by this load
567  *
568  * We differentiate this function from ModelAction::get_write_value and
569  * ModelAction::get_value for the purpose of RMW's, which may have both a
570  * 'read' and a 'write' value.
571  *
572  * Note: 'this' must be a load.
573  *
574  * @return The value read by this load
575  */
576 uint64_t ModelAction::get_reads_from_value() const
577 {
578         ASSERT(is_read());
579         if (reads_from) {
580                 if (reads_from->is_uninitialized())
581                         return reads_from_value;
582                 else
583                         return reads_from->get_write_value();
584         }
585
586         return VALUE_NONE;      // Only for new actions with no reads-from
587 }
588
589 /**
590  * @brief Get the value written by this store
591  *
592  * We differentiate this function from ModelAction::get_reads_from_value and
593  * ModelAction::get_value for the purpose of RMW's, which may have both a
594  * 'read' and a 'write' value.
595  *
596  * Note: 'this' must be a store.
597  *
598  * @return The value written by this store
599  */
600 uint64_t ModelAction::get_write_value() const
601 {
602         ASSERT(is_write());
603         return value;
604 }
605
606 /**
607  * @brief Get the value returned by this action
608  *
609  * For atomic reads (including RMW), an operation returns the value it read.
610  * For atomic writes, an operation returns the value it wrote. For other
611  * operations, the return value varies (sometimes is a "don't care"), but the
612  * value is simply stored in the "value" field.
613  *
614  * @return This action's return value
615  */
616 uint64_t ModelAction::get_return_value() const
617 {
618         if (is_read())
619                 return get_reads_from_value();
620         else if (is_write())
621                 return get_write_value();
622         else
623                 return value;
624 }
625
626 /**
627  * Update the model action's read_from action
628  * @param act The action to read from; should be a write
629  */
630 void ModelAction::set_read_from(ModelAction *act)
631 {
632         ASSERT(act);
633
634         reads_from = act;
635         if (act->is_uninitialized()) {  // WL
636                 uint64_t val = *((uint64_t *) location);
637                 ModelAction * act_uninitialized = (ModelAction *)act;
638                 act_uninitialized->set_value(val);
639                 reads_from = act_uninitialized;
640                 reads_from_value = val;
641
642 // disabled by WL, because LLVM IR is unable to detect atomic init
643 /*              model->assert_bug("May read from uninitialized atomic:\n"
644                                 "    action %d, thread %d, location %p (%s, %s)",
645                                 seq_number, id_to_int(tid), location,
646                                 get_type_str(), get_mo_str());
647  */
648         }
649 }
650
651 /**
652  * Synchronize the current thread with the thread corresponding to the
653  * ModelAction parameter.
654  * @param act The ModelAction to synchronize with
655  * @return True if this is a valid synchronization; false otherwise
656  */
657 bool ModelAction::synchronize_with(const ModelAction *act)
658 {
659         if (*this < *act)
660                 return false;
661         cv->merge(act->cv);
662         return true;
663 }
664
665 bool ModelAction::has_synchronized_with(const ModelAction *act) const
666 {
667         return cv->synchronized_since(act);
668 }
669
670 /**
671  * Check whether 'this' happens before act, according to the memory-model's
672  * happens before relation. This is checked via the ClockVector constructs.
673  * @return true if this action's thread has synchronized with act's thread
674  * since the execution of act, false otherwise.
675  */
676 bool ModelAction::happens_before(const ModelAction *act) const
677 {
678         return act->cv->synchronized_since(this);
679 }
680
681 const char * ModelAction::get_type_str() const
682 {
683         switch (this->type) {
684         case THREAD_CREATE: return "thread create";
685         case THREAD_START: return "thread start";
686         case THREAD_YIELD: return "thread yield";
687         case THREAD_JOIN: return "thread join";
688         case THREAD_FINISH: return "thread finish";
689         case THREAD_SLEEP: return "thread sleep";
690         case THREADONLY_FINISH: return "pthread_exit finish";
691
692         case PTHREAD_CREATE: return "pthread create";
693         case PTHREAD_JOIN: return "pthread join";
694
695         case ATOMIC_UNINIT: return "uninitialized";
696         case NONATOMIC_WRITE: return "nonatomic write";
697         case ATOMIC_READ: return "atomic read";
698         case ATOMIC_WRITE: return "atomic write";
699         case ATOMIC_RMW: return "atomic rmw";
700         case ATOMIC_FENCE: return "fence";
701         case ATOMIC_RMWR: return "atomic rmwr";
702         case ATOMIC_RMWRCAS: return "atomic rmwrcas";
703         case ATOMIC_RMWC: return "atomic rmwc";
704         case ATOMIC_INIT: return "init atomic";
705         case ATOMIC_LOCK: return "lock";
706         case ATOMIC_UNLOCK: return "unlock";
707         case ATOMIC_TRYLOCK: return "trylock";
708         case ATOMIC_WAIT: return "wait";
709         case ATOMIC_NOTIFY_ONE: return "notify one";
710         case ATOMIC_NOTIFY_ALL: return "notify all";
711         case ATOMIC_ANNOTATION: return "annotation";
712         default: return "unknown type";
713         };
714 }
715
716 const char * ModelAction::get_mo_str() const
717 {
718         switch (this->order) {
719         case std::memory_order_relaxed: return "relaxed";
720         case std::memory_order_acquire: return "acquire";
721         case std::memory_order_release: return "release";
722         case std::memory_order_acq_rel: return "acq_rel";
723         case std::memory_order_seq_cst: return "seq_cst";
724         default: return "unknown";
725         }
726 }
727
728 /** @brief Print nicely-formatted info about this ModelAction */
729 void ModelAction::print() const
730 {
731         const char *type_str = get_type_str(), *mo_str = get_mo_str();
732
733         model_print("%-4d %-2d   %-14s  %7s  %14p   %-#18" PRIx64,
734                                                         seq_number, id_to_int(tid), type_str, mo_str, location, get_return_value());
735         if (is_read()) {
736                 if (reads_from)
737                         model_print("  %-3d", reads_from->get_seq_number());
738                 else
739                         model_print("  ?  ");
740         }
741         if (cv) {
742                 if (is_read())
743                         model_print(" ");
744                 else
745                         model_print("      ");
746                 cv->print();
747         } else
748                 model_print("\n");
749 }
750
751 /** @brief Get a (likely) unique hash for this ModelAction */
752 unsigned int ModelAction::hash() const
753 {
754         unsigned int hash = (unsigned int)this->type;
755         hash ^= ((unsigned int)this->order) << 3;
756         hash ^= seq_number << 5;
757         hash ^= id_to_int(tid) << 6;
758
759         if (is_read()) {
760                 if (reads_from)
761                         hash ^= reads_from->get_seq_number();
762                 hash ^= get_reads_from_value();
763         }
764         return hash;
765 }
766
767 /**
768  * Only valid for LOCK, TRY_LOCK, UNLOCK, and WAIT operations.
769  * @return The mutex operated on by this action, if any; otherwise NULL
770  */
771 cdsc::mutex * ModelAction::get_mutex() const
772 {
773         if (is_trylock() || is_lock() || is_unlock())
774                 return (cdsc::mutex *)get_location();
775         else if (is_wait())
776                 return (cdsc::mutex *)get_value();
777         else
778                 return NULL;
779 }