Annotation of sbbs/src/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.34 2006/02/24 20:12:19 deuce 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 2005 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:        #include <unistd.h>     /* _POSIX_THREADS definition on FreeBSD (at least) */
                     53: 
                     54:        /* Win32 thread API wrappers */
                     55:        ulong _beginthread(void( *start_address )( void * )
                     56:                        ,unsigned stack_size, void *arglist);
                     57: 
                     58:        #define GetCurrentThreadId()            pthread_self()
                     59: 
                     60: #elif defined(_WIN32)  
                     61: 
                     62:        #include <process.h>    /* _beginthread */
                     63:        #include <limits.h>             /* INT_MAX */
                     64:        #include <errno.h>              /* EAGAIN and EBUSY */
                     65: 
                     66:        /* POSIX threads */
                     67:        typedef DWORD pthread_t;
                     68:        #define pthread_self()                          GetCurrentThreadId()
                     69: 
                     70:        /* POSIX mutexes */
                     71:        #ifdef PTHREAD_MUTEX_AS_WIN32_MUTEX     /* Much slower/heavier than critical sections */
                     72: 
                     73:                typedef HANDLE pthread_mutex_t;
                     74: 
                     75:        #else   /* Implemented as Win32 Critical Sections */
                     76: 
                     77:                typedef CRITICAL_SECTION pthread_mutex_t;
                     78: 
                     79:        #endif
                     80: 
                     81: #elif defined(__OS2__)
                     82: 
                     83:        /* POSIX mutexes */
                     84:        typedef TID pthread_t;
                     85:        typedef HEV pthread_mutex_t;
                     86: 
                     87: #else
                     88: 
                     89:        #error "Need thread wrappers."
                     90: 
                     91: #endif
                     92: 
                     93: /****************************************************************************/
                     94: /* Wrappers for POSIX thread (pthread) mutexes                                                         */
                     95: /****************************************************************************/
                     96: 
                     97: pthread_mutex_t pthread_mutex_initializer(void);
                     98: 
                     99: #if defined(_POSIX_THREADS)
                    100: 
                    101: #ifdef _DEBUG
                    102: #if defined (__FreeBSD__) || defined (__OpenBSD__)
                    103: #include <pthread_np.h>
                    104: #define        SetThreadName(c)        pthread_set_name_np(pthread_self(),c)
                    105: #else
                    106: #define SetThreadName(c)
                    107: #endif
                    108: #else
                    109: #define SetThreadName(c)
                    110: #endif
                    111: 
                    112: #else
                    113: 
                    114: int pthread_mutex_init(pthread_mutex_t*, void* attr);
                    115: int pthread_mutex_lock(pthread_mutex_t*);
                    116: int pthread_mutex_trylock(pthread_mutex_t*);
                    117: int pthread_mutex_unlock(pthread_mutex_t*);
                    118: int pthread_mutex_destroy(pthread_mutex_t*);
                    119: 
                    120: #define PTHREAD_MUTEX_INITIALIZER      pthread_mutex_initializer()
                    121: #define SetThreadName(c)
                    122: 
                    123: #endif
                    124: 
                    125: #if defined(__cplusplus)
                    126: }
                    127: #endif
                    128: 
                    129: #include "semwrap.h"
                    130: 
                    131: #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.