Annotation of sbbs/xpdev/threadwrap.h, revision 1.1.1.1

1.1       root        1: /* threadwrap.h */
                      2: 
                      3: /* Thread-related cross-platform development wrappers */
                      4: 
                      5: /* $Id: threadwrap.h,v 1.27 2004/11/05 01:35:08 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 2003 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 _THREADWRAP_H
                     39: #define _THREADWRAP_H
                     40: 
                     41: #include "gen_defs.h"  /* HANDLE */
                     42: #include "wrapdll.h"   /* DLLEXPORT and DLLCALL */
                     43: 
                     44: #if defined(__cplusplus)
                     45: extern "C" {
                     46: #endif
                     47: 
                     48: #if defined(__unix__)
                     49: 
                     50:        #include <sys/param.h>
                     51:        #include <pthread.h>    /* POSIX threads and mutexes */
                     52: 
                     53:        /* Win32 thread API wrappers */
                     54:        ulong _beginthread(void( *start_address )( void * )
                     55:                        ,unsigned stack_size, void *arglist);
                     56: 
                     57:        #define GetCurrentThreadId()            pthread_self()
                     58: 
                     59: #elif defined(_WIN32)  
                     60: 
                     61:        #include <process.h>    /* _beginthread */
                     62:        #include <limits.h>             /* INT_MAX */
                     63:        #include <errno.h>              /* EAGAIN and EBUSY */
                     64: 
                     65:        /* POSIX threads */
                     66:        typedef DWORD pthread_t;
                     67:        #define pthread_self()                          GetCurrentThreadId()
                     68: 
                     69:        /* POSIX mutexes */
                     70: #if 1  /* Implemented as Win32 Critical Sections */
                     71:        typedef CRITICAL_SECTION pthread_mutex_t;
                     72:        #define pthread_mutex_init(pmtx,v)      InitializeCriticalSection(pmtx),0
                     73:        #define pthread_mutex_lock(pmtx)        EnterCriticalSection(pmtx),0
                     74:        #define pthread_mutex_unlock(pmtx)      LeaveCriticalSection(pmtx),0
                     75:        #define pthread_mutex_destroy(pmtx)     DeleteCriticalSection(pmtx),0
                     76:        /* TryEnterCriticalSection only available on NT4+ :-( */
                     77:        #define pthread_mutex_trylock(pmtx) (TryEnterCriticalSection(pmtx)?0:EBUSY)
                     78: 
                     79: #else  /* Implemented as Win32 Mutexes (much slower) */
                     80:        typedef HANDLE pthread_mutex_t;
                     81:        #define PTHREAD_MUTEX_INITIALIZER       CreateMutex(NULL,FALSE,NULL)
                     82:        #define pthread_mutex_init(pmtx,v)      (*(pmtx)=CreateMutex(NULL,FALSE,NULL))==NULL?-1:0)
                     83:        #define pthread_mutex_lock(pmtx)        (WaitForSingleObject(*(pmtx),INFINITE)==WAIT_OBJECT_0?0:EBUSY)
                     84:        #define pthread_mutex_unlock(pmtx)      (ReleaseMutex(*(pmtx))?0:GetLastError())
                     85:        #define pthread_mutex_destroy(pmtx)     (CloseHandle(*(pmtx))?0:GetLastError())
                     86:        #define pthread_mutex_trylock(pmtx) (WaitForSingleObject(*(pmtx),0)==WAIT_OBJECT_0?0:EBUSY)
                     87: #endif
                     88: 
                     89: #elif defined(__OS2__) /* These have *not* been tested! */
                     90: 
                     91:        /* POSIX mutexes */
                     92:        typedef HEV pthread_mutex_t;
                     93:        #define pthread_mutex_init(pmtx,v)      DosCreateMutexSem(NULL,pmtx,0,0)
                     94:        #define pthread_mutex_lock(pmtx)        DosRequestMutexSem(*(psem),-1)
                     95:        #define pthread_mutex_unlock(pmtx)      DosReleaseMutexSem(*(psem))
                     96:        #define pthread_mutex_destroy(pmtx)     DosCloseMutexSem(*(psem))
                     97: 
                     98: #else
                     99: 
                    100:        #error "Need thread wrappers."
                    101: 
                    102: #endif
                    103: 
                    104: #if defined(__cplusplus)
                    105: }
                    106: #endif
                    107: 
                    108: #include "semwrap.h"
                    109: 
                    110: #endif /* Don't add anything after this line */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.