| 986 | } |
| 987 | |
| 988 | void Compute(OpKernelContext* ctx) override { |
| 989 | Var* resource; |
| 990 | const bool sparse = false; |
| 991 | mutex* mu = GetTrainingVariableMutex<Device, T>(ctx, 0, sparse, &resource); |
| 992 | core::ScopedUnref scoped_unref(resource); |
| 993 | if (use_exclusive_lock_ && mu != nullptr) { |
| 994 | mutex_lock l1(*mu); |
| 995 | // Don't try to acquire a lock on the second ref as they share the same |
| 996 | // mutex. |
| 997 | // |
| 998 | // mutex_lock l2(*ctx->input_ref_mutex(1)); |
| 999 | DoValidate(ctx); |
| 1000 | if (!ctx->status().ok()) return; |
| 1001 | DoCompute(ctx); |
| 1002 | } else { |
| 1003 | DoValidate(ctx); |
| 1004 | if (!ctx->status().ok()) return; |
| 1005 | DoCompute(ctx); |
| 1006 | } |
| 1007 | MaybeForwardRefInputToRefOutput(ctx, 0, 0); |
| 1008 | } |
| 1009 | |
| 1010 | private: |
| 1011 | bool use_exclusive_lock_; |
nothing calls this directly
no test coverage detected