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 20 namespace mindspore { 21 namespace uuid_generator { ToString()22std::string UUID::ToString() { 23 std::ostringstream ret; 24 ret << *this; 25 return ret.str(); 26 } 27 } // namespace uuid_generator 28 29 namespace localid_generator { GenLocalActorId()30int GenLocalActorId() { 31 static std::atomic<int> localActorId(0); 32 return localActorId.fetch_add(1); 33 } 34 35 #ifdef HTTP_ENABLED 36 // not support muti-thread GenHttpClientConnId()37int GenHttpClientConnId() { 38 static int httpClientConnId = 1; 39 if (httpClientConnId == INT_MAX) { 40 httpClientConnId = 1; 41 } 42 return httpClientConnId++; 43 } 44 45 // not support muti-thread GenHttpServerConnId()46int GenHttpServerConnId() { 47 static int httpServerConnId = 1; 48 if (httpServerConnId == INT_MAX) { 49 httpServerConnId = 1; 50 } 51 return httpServerConnId++; 52 } 53 #endif 54 } // namespace localid_generator 55 } // namespace mindspore 56