| 411 | } |
| 412 | |
| 413 | Status EagerContext::AddFunctionDef(const FunctionDef& fdef) { |
| 414 | bool is_first_ref = false; |
| 415 | { |
| 416 | mutex_lock l(cache_mu_); |
| 417 | auto* registered_function = |
| 418 | gtl::FindPtrOrNull(registered_functions_, fdef.signature().name()); |
| 419 | if (registered_function == nullptr) { |
| 420 | registered_function = new RegisteredFunction; |
| 421 | registered_function->cached_kernel_keys = |
| 422 | absl::make_unique<std::vector<Fprint128>>(); |
| 423 | gtl::InsertOrUpdate(®istered_functions_, fdef.signature().name(), |
| 424 | registered_function); |
| 425 | } else { |
| 426 | registered_function->Ref(); |
| 427 | } |
| 428 | is_first_ref = registered_function->RefCountIsOne(); |
| 429 | } |
| 430 | if (is_first_ref) { |
| 431 | TF_RETURN_IF_ERROR(func_lib_def_.AddFunctionDef(fdef)); |
| 432 | return MaybeRegisterFunctionRemotely(fdef); |
| 433 | } |
| 434 | return Status::OK(); |
| 435 | } |
| 436 | |
| 437 | Status EagerContext::RemoveFunction(const string& func) { |
| 438 | bool is_last_ref = false; |