!7 优化RegisterRemoteEndpoint、THREAD_Create等接口
Merge pull request !7 from zjucx/master
This commit is contained in:
commit
8c50e3a5b6
|
@ -21,7 +21,8 @@
|
|||
#define MIN_STACK_SIZE 0x8000
|
||||
static int g_threadCount = 0;
|
||||
static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_key_t g_localKey = 0;
|
||||
static pthread_key_t g_localKey = -1;
|
||||
static pthread_once_t g_localKeyOnce = PTHREAD_ONCE_INIT;
|
||||
|
||||
MutexId MUTEX_InitValue()
|
||||
{
|
||||
|
@ -59,6 +60,11 @@ void MUTEX_GlobalUnlock(void)
|
|||
pthread_mutex_unlock(&g_mutex);
|
||||
}
|
||||
|
||||
static void KeyCreate()
|
||||
{
|
||||
(void) pthread_key_create(&g_localKey, NULL);
|
||||
}
|
||||
|
||||
ThreadId THREAD_Create(Runnable run, void *argv, const ThreadAttr *attr)
|
||||
{
|
||||
pthread_attr_t threadAttr;
|
||||
|
@ -72,7 +78,7 @@ ThreadId THREAD_Create(Runnable run, void *argv, const ThreadAttr *attr)
|
|||
#endif
|
||||
pthread_attr_setschedpolicy(&threadAttr, SCHED_RR);
|
||||
pthread_attr_setschedparam(&threadAttr, &sched);
|
||||
pthread_key_create(&g_localKey, NULL);
|
||||
(void) pthread_once(&g_localKeyOnce, KeyCreate);
|
||||
pthread_t threadId = 0;
|
||||
int errno = pthread_create(&threadId, &threadAttr, run, argv);
|
||||
if (errno != 0) {
|
||||
|
|
|
@ -382,7 +382,6 @@ static int RegisterRemoteEndpoint(const IpcContext *context, SvcIdentity *identi
|
|||
IpcIoInit(&req, data, MAX_DATA_LEN, 0);
|
||||
IpcIoPushUint32(&req, RES_ENDPOINT);
|
||||
IpcIoPushUint32(&req, OP_POST);
|
||||
IpcIoPushUint32(&req, identity->handle);
|
||||
uint8 retry = 0;
|
||||
while (retry < MAX_RETRY_TIMES) {
|
||||
++retry;
|
||||
|
@ -428,15 +427,18 @@ static int OnSamgrServerExit(const IpcContext *context, void *ipcMsg, IpcIo *dat
|
|||
router->policyNum = 0;
|
||||
}
|
||||
|
||||
SvcIdentity old = endpoint->identity;
|
||||
while (endpoint->registerEP(endpoint->context, &endpoint->identity) != EC_SUCCESS) {
|
||||
HILOG_ERROR(HILOG_MODULE_SAMGR, "Reconnect to samgr server failed!");
|
||||
sleep(RETRY_INTERVAL);
|
||||
}
|
||||
SvcIdentity new = endpoint->identity;
|
||||
if (old.handle != new.handle || old.cookie != new.cookie || old.token != new.token) {
|
||||
HILOG_ERROR(HILOG_MODULE_SAMGR, "Samgr server identity error!");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
SvcIdentity identity;
|
||||
identity.handle = SAMGR_HANDLE;
|
||||
identity.token = SAMGR_TOKEN;
|
||||
identity.cookie = SAMGR_COOKIE;
|
||||
SvcIdentity identity = {SAMGR_HANDLE, SAMGR_TOKEN, SAMGR_COOKIE};
|
||||
(void)UnregisterDeathCallback(identity, endpoint->deadId);
|
||||
(void)RegisterDeathCallback(endpoint->context, identity, OnSamgrServerExit, endpoint, &endpoint->deadId);
|
||||
int remain = RegisterRemoteFeatures(endpoint);
|
||||
|
|
|
@ -187,10 +187,7 @@ static int ProcEndpoint(SamgrServer *server, int32 option, void *origin, IpcIo *
|
|||
int index = SASTORA_FindHandleByPid(&g_server.store, pid, &handle);
|
||||
if (index == INVALID_INDEX) {
|
||||
SvcIdentity identity = {(uint32)INVALID_INDEX, (uint32)INVALID_INDEX, (uint32)INVALID_INDEX};
|
||||
identity.handle = IpcIoPopUint32(req);
|
||||
if (identity.handle == (uint32)INVALID_INDEX) { // generate handle
|
||||
(void)GenServiceHandle(&identity, GetCallingTid(origin));
|
||||
}
|
||||
(void)GenServiceHandle(&identity, GetCallingTid(origin));
|
||||
|
||||
handle.pid = pid;
|
||||
handle.uid = GetCallingUid(origin);
|
||||
|
|
Loading…
Reference in New Issue