1 Star 0 Fork 8

Happy小瓶盖/Xipkpublib_Update

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
TraceNoProc.c.20160125 2.88 KB
一键复制 编辑 原始数据 按行查看 历史
suitianmou 提交于 2016-03-17 14:03 . ʼ1.2汾
/*******************************************************
* 公 司: 大连同方软银科技有限公司
* 程 序 名: TraceNoProc.c
* 程序功能: 流水号操作函数簇
* 输入参数:
* 输出参数:
* 返 回 值:
* 作 者: yangwc
* 开发日期: 2007/1
* 修 改 人:
* 修改日期:
*******************************************************/
#include "kernel/syspub.h"
#include "kernel/xipcmstc.h"
static int shm_id, sem_id;
static struct sembuf p={0,-1,0}, v={0,1,0};
int init_id(TxipCMStc *xip)
{
key_t shm_key,sem_key;
static long *par;
union semun {
int val;
struct semid_ds *buf;
unsigned short *array;
} arg;
shm_key = ftok((char *)getenv("HOME"), Mxip_shmkey);
sem_key = ftok((char *)getenv("HOME"), Mxip_semkey);
if (-1 == (shm_id = shmget(shm_key ,sizeof(long),IPC_EXCL|IPC_CREAT|0700)))
{
if (-1 == (shm_id = shmget(shm_key ,sizeof(long),IPC_CREAT)))
{
XIPLOG("E", "Get shm_key err");
return -1;
}
}
else
{
if ((long *)-1 == (par = (long *)shmat(shm_id,(char *)0,0700)))
{
XIPLOG("E", "init - shmat err");
return -1;
}
*par = 0L;
if (-1 == (shmdt((char *)par)))
{
XIPLOG("E", "init - shmdt err");
return -1;
}
}
if (-1 == (sem_id = semget(sem_key,1,IPC_EXCL|IPC_CREAT|0700)))
{
if (-1 == (sem_id = semget(sem_key,1,IPC_CREAT)))
{
XIPLOG("E", "Get sem_key err");
return -1;
}
}
else
{
arg.val = 1;
if (-1 == (semctl(sem_id, 0 ,SETVAL,arg)))
{
XIPLOG("E", "Set sectl err");
return (-1);
}
}
return(0);
}
int move_id(TxipCMStc *xip)
{
if (shmctl(shm_id,IPC_RMID,NULL) == -1)
{
XIPLOG("E", "error in closing shmctl...");
return -1;
}
if (semctl(sem_id,0,IPC_RMID,NULL) < 0)
{
XIPLOG("E", "error in closing semctl...");
return -1;
}
return (0);
}
long get_tlsrno( TxipCMStc *xip )
{
static long *par;
static long tlsrno;
if (-1 == init_id(xip)) return -1;
semop(sem_id,&p,1);
if ((long *)-1 == (par = (long *)shmat(shm_id,(char *)0,0600)))
{
XIPLOG("E", "In Get shmat err");
semop(sem_id, &v, 1);
return -1;
}
*par += 1;
if (*par > Mxip_maxseq) *par = Mxip_minseq;
if (*par < Mxip_minseq) *par = Mxip_minseq;
tlsrno = *par;
if ( -1 == (shmdt((char *)par)) )
{
XIPLOG("E", "In Get shmdt err");
semop(sem_id, &v, 1);
return -1;
}
semop(sem_id,&v,1);
return(tlsrno);
}
long set_tlsrno(TxipCMStc *xip, long tlsrno)
{
long *par;
if (-1 == init_id(xip))
{
return -1;
}
if (0 > (par = (long *)shmat(shm_id,(char *)0,0))) return(-1);
*par = tlsrno;
if (-1 == (shmdt((char *)par)))
{
return -1;
}
return(tlsrno);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liuze5516/Xipkpublib_Update.git
git@gitee.com:liuze5516/Xipkpublib_Update.git
liuze5516
Xipkpublib_Update
Xipkpublib_Update
master

搜索帮助