commit 2025-09-10 15:27 edit a bit ZCppMain/ZCProcess_Linux.H
This commit is contained in:
@ -34,9 +34,9 @@ namespace ZNsMain
|
|||||||
|
|
||||||
enum ZEThread
|
enum ZEThread
|
||||||
{
|
{
|
||||||
ZEThread_OK =0 ,
|
ZEThread_OK = 0 ,
|
||||||
ZEThread_Invalid=EINVAL , // 쓰레드 관련 함수 에러.
|
ZEThread_Invalid= EINVAL , // 쓰레드 관련 함수 에러.
|
||||||
ZEThread_TimeOut=ETIMEDOUT
|
ZEThread_TimeOut= ETIMEDOUT
|
||||||
};/*
|
};/*
|
||||||
enum ZEThread*/
|
enum ZEThread*/
|
||||||
|
|
||||||
@ -472,7 +472,7 @@ namespace ZNsMain
|
|||||||
|
|
||||||
static bool SetupRTS(int AI_FileID, int AI_SigNo=SIGRTMIN, int AI_Flag=O_RDWR | /*O_NONBLOCK|*/O_ASYNC, pid_t AI_PId=::getpid())
|
static bool SetupRTS(int AI_FileID, int AI_SigNo=SIGRTMIN, int AI_Flag=O_RDWR | /*O_NONBLOCK|*/O_ASYNC, pid_t AI_PId=::getpid())
|
||||||
{
|
{
|
||||||
if (::fcntl(AI_FileID, F_SETFL, AI_Flag) < 0)
|
if (::fcntl(AI_FileID, F_SETFL , AI_Flag ) < 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -480,11 +480,11 @@ namespace ZNsMain
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (::fcntl(AI_FileID, F_SETOWN, AI_PId) < 0)
|
if (::fcntl(AI_FileID, F_SETOWN, AI_PId ) < 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}/*
|
}/*
|
||||||
if (::fcntl(AI_FileID, F_SETOWN, AI_PId) < 0)*/
|
if (::fcntl(AI_FileID, F_SETOWN, AI_PId ) < 0)*/
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}/*
|
}/*
|
||||||
@ -1059,7 +1059,8 @@ namespace ZNsMain
|
|||||||
|
|
||||||
bool Close()
|
bool Close()
|
||||||
{
|
{
|
||||||
bool VB_IsOK=(::shmctl(mh_FileMap, IPC_RMID, 0)!=-1) ;
|
bool VB_IsOK =
|
||||||
|
( ::shmctl(mh_FileMap, IPC_RMID, 0) != -1 ) ;
|
||||||
|
|
||||||
mh_FileMap=EInvalidID; return VB_IsOK;
|
mh_FileMap=EInvalidID; return VB_IsOK;
|
||||||
|
|
||||||
@ -1171,15 +1172,15 @@ namespace ZNsMain
|
|||||||
if((mh_Mutex=::semget((key_t)AL_KeyID, 1, AI_Flag))==-1)*/
|
if((mh_Mutex=::semget((key_t)AL_KeyID, 1, AI_Flag))==-1)*/
|
||||||
|
|
||||||
this->Init(); return true;
|
this->Init(); return true;
|
||||||
}/*
|
s }/*
|
||||||
bool Make(long AL_KeyID, int AI_Flag=IPC_CREAT | IPC_EXCL | 0664)*/
|
bool Make(long AL_KeyID, int AI_Flag=IPC_CREAT | IPC_EXCL | 0664)*/
|
||||||
|
|
||||||
bool Lock()
|
bool Lock()
|
||||||
{
|
{
|
||||||
struct sembuf sembuf_Obj;
|
struct sembuf sembuf_Obj ;
|
||||||
sembuf_Obj.sem_num= 0; // semaphore 배열에서 몇 번째 semaphore 인지를 지정
|
sembuf_Obj.sem_num = 0 ; // semaphore 배열에서 몇 번째 semaphore 인지를 지정
|
||||||
sembuf_Obj.sem_op =-1;
|
sembuf_Obj.sem_op = -1 ;
|
||||||
sembuf_Obj.sem_flg=SEM_UNDO;
|
sembuf_Obj.sem_flg = SEM_UNDO ;
|
||||||
|
|
||||||
return ::semop(mh_Mutex, &sembuf_Obj, 1)==0 ;
|
return ::semop(mh_Mutex, &sembuf_Obj, 1)==0 ;
|
||||||
}/*
|
}/*
|
||||||
@ -1187,12 +1188,12 @@ namespace ZNsMain
|
|||||||
|
|
||||||
bool UnLock()
|
bool UnLock()
|
||||||
{
|
{
|
||||||
struct sembuf sembuf_Obj;
|
struct sembuf sembuf_Obj ;
|
||||||
sembuf_Obj.sem_num=0 ; // semaphore 배열에서 몇 번째 semaphore 인지를 지정
|
sembuf_Obj.sem_num = 0 ; // semaphore 배열에서 몇 번째 semaphore 인지를 지정
|
||||||
sembuf_Obj.sem_op =1 ;
|
sembuf_Obj.sem_op = 1 ;
|
||||||
sembuf_Obj.sem_flg=SEM_UNDO;
|
sembuf_Obj.sem_flg = SEM_UNDO ;
|
||||||
|
|
||||||
return ::semop(mh_Mutex,&sembuf_Obj, 1)==0 ;
|
return ::semop(mh_Mutex, &sembuf_Obj, 1)==0 ;
|
||||||
}/*
|
}/*
|
||||||
bool UnLock()*/
|
bool UnLock()*/
|
||||||
|
|
||||||
@ -1204,10 +1205,10 @@ namespace ZNsMain
|
|||||||
// 동기화되지 않는다. 프로세스가 이 함수를 수행하지 않고 종료해도 커
|
// 동기화되지 않는다. 프로세스가 이 함수를 수행하지 않고 종료해도 커
|
||||||
// 널은 자동적으로 semaphore 를 삭제하지 않는다.
|
// 널은 자동적으로 semaphore 를 삭제하지 않는다.
|
||||||
|
|
||||||
union semun SemUnion;
|
union semun SemUnion ;
|
||||||
|
|
||||||
const bool CB_IsOK =
|
const bool CB_IsOK =
|
||||||
(::semctl(mh_Mutex, 0, IPC_RMID, SemUnion)!=-1);
|
(::semctl(mh_Mutex, 0, IPC_RMID, SemUnion) != -1);
|
||||||
|
|
||||||
mh_Mutex=0; return CB_IsOK;
|
mh_Mutex=0; return CB_IsOK;
|
||||||
}/*
|
}/*
|
||||||
@ -1246,13 +1247,13 @@ namespace ZNsMain
|
|||||||
class ZCMutexData*/
|
class ZCMutexData*/
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ZCMutexData* mp_MutexData ;
|
ZCMutexData* mp_CMutexData ;
|
||||||
ZCShareMemory mo_CShareMemory;
|
ZCShareMemory mo_CShareMemory;
|
||||||
public :
|
public :
|
||||||
|
|
||||||
ZCProcessMutexPosix()
|
ZCProcessMutexPosix()
|
||||||
{
|
{
|
||||||
mp_MutexData=0;
|
mp_CMutexData=0;
|
||||||
}/*
|
}/*
|
||||||
ZCProcessMutexPosix()*/
|
ZCProcessMutexPosix()*/
|
||||||
|
|
||||||
@ -1276,7 +1277,7 @@ namespace ZNsMain
|
|||||||
}/*
|
}/*
|
||||||
if(mo_CShareMemory.LinkMap()==false)*/
|
if(mo_CShareMemory.LinkMap()==false)*/
|
||||||
|
|
||||||
mp_MutexData=(ZCMutexData*)mo_CShareMemory.GetStartAddress();
|
mp_CMutexData=(ZCMutexData*)mo_CShareMemory.GetStartAddress();
|
||||||
}
|
}
|
||||||
else // mo_CShareMemory.ShmGet(AL_MapKey,sizeof(ZCMutexData))==true
|
else // mo_CShareMemory.ShmGet(AL_MapKey,sizeof(ZCMutexData))==true
|
||||||
{
|
{
|
||||||
@ -1286,14 +1287,14 @@ namespace ZNsMain
|
|||||||
}/*
|
}/*
|
||||||
if(mo_CShareMemory.LinkMap()==false)*/
|
if(mo_CShareMemory.LinkMap()==false)*/
|
||||||
|
|
||||||
mp_MutexData=(ZCMutexData*)mo_CShareMemory.GetStartAddress();
|
mp_CMutexData = (ZCMutexData*)mo_CShareMemory.GetStartAddress();
|
||||||
|
|
||||||
::memset(mp_MutexData, 0x00, sizeof(ZCMutexData));
|
::memset(mp_CMutexData, 0x00, sizeof(ZCMutexData));
|
||||||
|
|
||||||
::pthread_mutexattr_init (&mp_MutexData->mo_PThreadMutexAttr);
|
::pthread_mutexattr_init (&mp_CMutexData->mo_PThreadMutexAttr);
|
||||||
::pthread_mutexattr_settype (&mp_MutexData->mo_PThreadMutexAttr, PTHREAD_MUTEX_RECURSIVE); // 이전에는 PTHREAD_MUTEX_ERRORCHECK 로 설정했었다. 2007-05-24 20:04:00
|
::pthread_mutexattr_settype (&mp_CMutexData->mo_PThreadMutexAttr, PTHREAD_MUTEX_RECURSIVE); // 이전에는 PTHREAD_MUTEX_ERRORCHECK 로 설정했었다. 2007-05-24 20:04:00
|
||||||
::pthread_mutexattr_setpshared(&mp_MutexData->mo_PThreadMutexAttr, PTHREAD_PROCESS_SHARED);
|
::pthread_mutexattr_setpshared(&mp_CMutexData->mo_PThreadMutexAttr, PTHREAD_PROCESS_SHARED );
|
||||||
::pthread_mutex_init (&mp_MutexData->mo_PThreadMutex, (const pthread_mutexattr_t*)&mp_MutexData->mo_PThreadMutexAttr);
|
::pthread_mutex_init (&mp_CMutexData->mo_PThreadMutex, (const pthread_mutexattr_t*)&mp_CMutexData->mo_PThreadMutexAttr);
|
||||||
}/*
|
}/*
|
||||||
else // mo_CShareMemory.ShmGet(AL_MapKey,sizeof(ZCMutexData))==true*/
|
else // mo_CShareMemory.ShmGet(AL_MapKey,sizeof(ZCMutexData))==true*/
|
||||||
|
|
||||||
@ -1310,7 +1311,7 @@ namespace ZNsMain
|
|||||||
|
|
||||||
int LockRaw()
|
int LockRaw()
|
||||||
{
|
{
|
||||||
return ::pthread_mutex_lock(&mp_MutexData->mo_PThreadMutex);
|
return ::pthread_mutex_lock(&mp_CMutexData->mo_PThreadMutex);
|
||||||
|
|
||||||
// EDEADLK 를 반환하는 경우를 체크할 것.
|
// EDEADLK 를 반환하는 경우를 체크할 것.
|
||||||
}/*
|
}/*
|
||||||
@ -1332,7 +1333,7 @@ namespace ZNsMain
|
|||||||
|
|
||||||
int LockRaw(const struct timespec& AR_TimeSpec)
|
int LockRaw(const struct timespec& AR_TimeSpec)
|
||||||
{
|
{
|
||||||
return ::pthread_mutex_timedlock(&mp_MutexData->mo_PThreadMutex, &AR_TimeSpec);
|
return ::pthread_mutex_timedlock(&mp_CMutexData->mo_PThreadMutex, &AR_TimeSpec);
|
||||||
|
|
||||||
// 성공이면 ZNsEnum::ZEThread_OK 를
|
// 성공이면 ZNsEnum::ZEThread_OK 를
|
||||||
// 시간초과이면 ZNsEnum::ZEThread_TimeOut 를 리턴
|
// 시간초과이면 ZNsEnum::ZEThread_TimeOut 를 리턴
|
||||||
@ -1345,10 +1346,11 @@ namespace ZNsMain
|
|||||||
{
|
{
|
||||||
timespec VO_TimeSpec;
|
timespec VO_TimeSpec;
|
||||||
|
|
||||||
VO_TimeSpec.tv_sec =time(NULL)+AL_MiliSec/1000;
|
VO_TimeSpec.tv_sec = time(NULL) + AL_MiliSec/1000 ;
|
||||||
VO_TimeSpec.tv_nsec=(AL_MiliSec%1000)*1000*1000;
|
VO_TimeSpec.tv_nsec = (AL_MiliSec%1000)* 1000*1000 ;
|
||||||
|
|
||||||
return ::pthread_mutex_timedlock(&mp_MutexData->mo_PThreadMutex, &VO_TimeSpec);
|
return ::pthread_mutex_timedlock
|
||||||
|
(&mp_CMutexData->mo_PThreadMutex, &VO_TimeSpec);
|
||||||
}/*
|
}/*
|
||||||
int Lock(long AL_MiliSec)*/
|
int Lock(long AL_MiliSec)*/
|
||||||
|
|
||||||
@ -1362,13 +1364,13 @@ namespace ZNsMain
|
|||||||
|
|
||||||
bool UnLock()
|
bool UnLock()
|
||||||
{
|
{
|
||||||
return ::pthread_mutex_unlock(&mp_MutexData->mo_PThreadMutex)==0;
|
return ::pthread_mutex_unlock(&mp_CMutexData->mo_PThreadMutex)==0;
|
||||||
}/*
|
}/*
|
||||||
bool UnLock()*/
|
bool UnLock()*/
|
||||||
|
|
||||||
void Close()
|
void Close()
|
||||||
{
|
{
|
||||||
::pthread_mutex_destroy(&mp_MutexData->mo_PThreadMutex);
|
::pthread_mutex_destroy(&mp_CMutexData->mo_PThreadMutex);
|
||||||
|
|
||||||
mo_CShareMemory.UnMap();
|
mo_CShareMemory.UnMap();
|
||||||
mo_CShareMemory.Close();
|
mo_CShareMemory.Close();
|
||||||
@ -1387,7 +1389,7 @@ namespace ZNsMain
|
|||||||
|
|
||||||
■ 기록자/판독자 lock(read-write lock) 으로 Window 의 수동리셋 이벤트를 구현할 수
|
■ 기록자/판독자 lock(read-write lock) 으로 Window 의 수동리셋 이벤트를 구현할 수
|
||||||
있다. 즉 특정 지점에서 다수의 쓰레드가 대기하다가 동시에 깨어나는 동작이 가능하
|
있다. 즉 특정 지점에서 다수의 쓰레드가 대기하다가 동시에 깨어나는 동작이 가능하
|
||||||
다. 물론 뮤텍스 조건변수로 수동리셋 이벤트를 구현하는 것이 더 효과적이다.
|
다. 물론 뮤텍스 조건 변수로 수동리셋 이벤트를 구현하는 것이 더 효과적이다.
|
||||||
|
|
||||||
■ POSIX.1b structure for a time value.
|
■ POSIX.1b structure for a time value.
|
||||||
This is like a `struct timeval' but has nanoseconds instead of microseconds.
|
This is like a `struct timeval' but has nanoseconds instead of microseconds.
|
||||||
|
Reference in New Issue
Block a user