1 /** 2 * Copyright 2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "async/uuid_generator.h" 18 #include <atomic> 19 #include <climits> 20 21 namespace mindspore { 22 namespace uuid_generator { GetRandomUUID()23UUID UUID::GetRandomUUID() { return UUID(mindspore::uuids::RandomBasedGenerator::GenerateRandomUuid()); } 24 ToString()25std::string UUID::ToString() { 26 std::ostringstream ret; 27 ret << *this; 28 return ret.str(); 29 } 30 } // namespace uuid_generator 31 32 namespace localid_generator { GenLocalActorId()33int GenLocalActorId() { 34 static std::atomic<int> localActorId(0); 35 return localActorId.fetch_add(1); 36 } 37 38 #ifdef HTTP_ENABLED 39 // not support muti-thread GenHttpClientConnId()40int GenHttpClientConnId() { 41 static int httpClientConnId = 1; 42 if (httpClientConnId == INT_MAX) { 43 httpClientConnId = 1; 44 } 45 return httpClientConnId++; 46 } 47 48 // not support muti-thread GenHttpServerConnId()49int GenHttpServerConnId() { 50 static int httpServerConnId = 1; 51 if (httpServerConnId == INT_MAX) { 52 httpServerConnId = 1; 53 } 54 return httpServerConnId++; 55 } 56 #endif 57 } // namespace localid_generator 58 } // namespace mindspore 59