|
|
1.1 ! root 1: /* semwrap.h */ ! 2: ! 3: /* Semaphore-related cross-platform development wrappers */ ! 4: ! 5: /* $Id: semwrap.h,v 1.10 2004/11/10 23:13:09 rswindell Exp $ */ ! 6: ! 7: /**************************************************************************** ! 8: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 10: * * ! 11: * Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html * ! 12: * * ! 13: * This library is free software; you can redistribute it and/or * ! 14: * modify it under the terms of the GNU Lesser General Public License * ! 15: * as published by the Free Software Foundation; either version 2 * ! 16: * of the License, or (at your option) any later version. * ! 17: * See the GNU Lesser General Public License for more details: lgpl.txt or * ! 18: * http://www.fsf.org/copyleft/lesser.html * ! 19: * * ! 20: * Anonymous FTP access to the most recent released source is available at * ! 21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 22: * * ! 23: * Anonymous CVS access to the development source and modification history * ! 24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 26: * (just hit return, no password is necessary) * ! 27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 28: * * ! 29: * For Synchronet coding style and modification guidelines, see * ! 30: * http://www.synchro.net/source.html * ! 31: * * ! 32: * You are encouraged to submit any modifications (preferably in Unix diff * ! 33: * format) via e-mail to [email protected] * ! 34: * * ! 35: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 36: ****************************************************************************/ ! 37: ! 38: #ifndef _SEMWRAP_H ! 39: #define _SEMWRAP_H ! 40: ! 41: #include "gen_defs.h" ! 42: ! 43: #if defined(__cplusplus) ! 44: extern "C" { ! 45: #endif ! 46: ! 47: #if defined(__unix__) ! 48: #if defined(USE_XP_SEMAPHORES) ! 49: #include "xpsem.h" ! 50: #define sem_init(x, y, z) xp_sem_init(x, y, z) ! 51: #define sem_destroy(x) xp_sem_destroy(x) ! 52: #define sem_close(x) xp_sem_close(x) ! 53: #define sem_unlink(x) xp_sem_unlink(x) ! 54: #define sem_wait(x) xp_sem_wait(x) ! 55: #define sem_trywait(x) xp_sem_trywait(x) ! 56: #define sem_post(x) xp_sem_post(x) ! 57: #define sem_getvalue(x,y) xp_sem_getvalue(x,y) ! 58: #define sem_timedwait(x,y) xp_sem_timedwait(x,y) ! 59: #define sem_t xp_sem_t ! 60: #else ! 61: #include <semaphore.h> /* POSIX semaphores */ ! 62: #endif ! 63: ! 64: #elif defined(_WIN32) ! 65: ! 66: #include <process.h> /* _beginthread */ ! 67: ! 68: /* POSIX semaphores */ ! 69: typedef HANDLE sem_t; ! 70: int sem_init(sem_t*, int pshared, unsigned int value); ! 71: int sem_post(sem_t*); ! 72: int sem_getvalue(sem_t*, int* value); ! 73: int sem_destroy(sem_t*); ! 74: #define sem_wait(psem) sem_trywait_block(psem,INFINITE) ! 75: #define sem_trywait(psem) sem_trywait_block(psem,0) ! 76: ! 77: #elif defined(__OS2__) /* These have *not* been tested! */ ! 78: ! 79: /* POSIX semaphores */ ! 80: typedef HEV sem_t; ! 81: #define sem_init(psem,ps,v) DosCreateEventSem(NULL,psem,0,0); ! 82: #define sem_wait(psem) DosWaitEventSem(*(psem),-1) ! 83: #define sem_post(psem) DosPostEventSem(*(psem)) ! 84: #define sem_destroy(psem) DosCloseEventSem(*(psem)) ! 85: ! 86: #else ! 87: ! 88: #error "Need semaphore wrappers." ! 89: ! 90: #endif ! 91: ! 92: /* NOT POSIX */ ! 93: int sem_trywait_block(sem_t* psem, unsigned long timeout); ! 94: ! 95: ! 96: /* Change semaphore to "unsignaled" (NOT POSIX) */ ! 97: #define sem_reset(psem) while(sem_trywait(psem)==0) ! 98: ! 99: #if defined(__cplusplus) ! 100: } ! 101: #endif ! 102: ! 103: #endif /* Don't add anything after this line */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.