Annotation of sbbs/xpdev/threadwrap.c, revision 1.1

1.1     ! root        1: /* threadwrap.c */
        !             2: 
        !             3: /* Thread-related cross-platform development wrappers */
        !             4: 
        !             5: /* $Id: threadwrap.c,v 1.18 2003/04/26 21:47:55 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 2002 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: #if defined(__unix__)
        !            39:        #include <unistd.h>     /* _POSIX_THREADS */
        !            40:        #include <sys/param.h>  /* BSD */
        !            41: #endif
        !            42: 
        !            43: #include "threadwrap.h"        /* DLLCALL */
        !            44: 
        !            45: /****************************************************************************/
        !            46: /* Wrapper for Win32 create/begin thread function                                                      */
        !            47: /* Uses POSIX threads                                                                                                          */
        !            48: /****************************************************************************/
        !            49: #if defined(__unix__)
        !            50: #if defined(_POSIX_THREADS)
        !            51: #if defined(__BORLANDC__)
        !            52:         #pragma argsused
        !            53: #endif
        !            54: ulong _beginthread(void( *start_address )( void * )
        !            55:                ,unsigned stack_size, void *arglist)
        !            56: {
        !            57:        pthread_t       thread;
        !            58:        pthread_attr_t attr;
        !            59: 
        !            60:        pthread_attr_init(&attr);     /* initialize attribute structure */
        !            61: 
        !            62:        /* set thread attributes to PTHREAD_CREATE_DETACHED which will ensure
        !            63:           that thread resources are freed on exit() */
        !            64:        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
        !            65: 
        !            66:        /* Default stack size in BSD is too small for JS stuff */
        !            67: #ifdef BSD
        !            68:        if(stack_size==0)
        !            69:                stack_size=1<<17;
        !            70: #endif
        !            71:        if(stack_size!=0)
        !            72:                pthread_attr_setstacksize(&attr, stack_size);
        !            73: 
        !            74:        if(pthread_create(&thread
        !            75: #if defined(__BORLANDC__) /* a (hopefully temporary) work-around */
        !            76:                ,NULL
        !            77: #else
        !            78:                ,&attr  /* default attributes */
        !            79: #endif
        !            80:                /* POSIX defines this arg as "void *(*start_address)" */
        !            81:                ,(void * (*)(void *)) start_address
        !            82:                ,arglist)==0)
        !            83:                return((int) thread /* thread handle */);
        !            84: 
        !            85:        return(-1);     /* error */
        !            86: }
        !            87: #else
        !            88: 
        !            89: #error "Need _beginthread implementation for non-POSIX thread library."
        !            90: 
        !            91: #endif
        !            92: 
        !            93: #endif /* __unix__ */

unix.superglobalmegacorp.com

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