drawsemop.h

来自「有了操作系统、TCP/IP协议栈、文件系统」· C头文件 代码 · 共 114 行

H
114
字号
/*** $Id: drawsemop.h,v 1.11 2003/12/11 05:07:04 weiym Exp $**** drawsemop.h: operations for drawing semaphore.**** Copyright (C) 2003 Feynman Software.** Copyright (C) 2000 ~ 2002 Wei Yongming.***/#ifndef GUI_DRAWSEMOP_H    #define GUI_DRAWSEMOP_H#ifdef __cplusplusextern "C" {#endif  /* __cplusplus */#include <errno.h>static inline void my_sem_op (int num, int op){    struct sembuf sb;again:    sb.sem_num = num;    sb.sem_op = op;    sb.sem_flg = SEM_UNDO;    if (semop (SHAREDRES_SEMID, &sb, 1) == -1) {        if (errno == EINTR) {            goto again;        }    }}#define lock_draw_sem()     my_sem_op(_IDX_SEM_DRAW, -1)#define unlock_draw_sem()   my_sem_op(_IDX_SEM_DRAW, 1)#define lock_scr_sem()      my_sem_op(_IDX_SEM_SCR, -1)#define unlock_scr_sem()    my_sem_op(_IDX_SEM_SCR, 1)#ifdef _CURSOR_SUPPORT#define lock_cursor_sem()   my_sem_op(_IDX_SEM_CURSOR, -1)#define unlock_cursor_sem() my_sem_op(_IDX_SEM_CURSOR, 1)static inline int get_sem_pid (int num){    int pid;    union semun ignored;    pid = semctl (SHAREDRES_SEMID, num, GETPID, ignored);#ifdef _DEBUG    if (pid == -1)        perror ("get_sem_pid");#endif    return pid;}#define get_cursor_sem_pid() get_sem_pid(_IDX_SEM_CURSOR)static inline int get_hidecursor_sem_val (void){    int val;    union semun ignored;    val = semctl (SHAREDRES_SEMID, _IDX_SEM_HIDECOUNT, GETVAL, ignored);#ifdef _DEBUG    if (val == -1)        perror ("get_hidecursor_sem_val");#endif    return val;}static inline void reset_hidecursor_sem (void){    int ret;    union semun sunion;    sunion.val = 0;    ret = semctl (SHAREDRES_SEMID, _IDX_SEM_HIDECOUNT, SETVAL, sunion) == -1;#ifdef _DEBUG    if (ret == -1)        perror ("reset_hidecursor_sem");#endif}static inline void inc_hidecursor_sem (void){    struct sembuf sb;again:    sb.sem_num = _IDX_SEM_HIDECOUNT;    sb.sem_op = 1;    sb.sem_flg = 0;    if (semop (SHAREDRES_SEMID, &sb, 1) == -1) {        if (errno == EINTR) {            goto again;        }    }}#endif /* _CURSOR_SUPPORT */#ifdef __cplusplus}#endif  /* __cplusplus */#endif // GUI_DRAWSEMOP_H

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?