ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

thread.c
Go to the documentation of this file.
00001 /*
00002  * msvcrt.dll thread functions
00003  *
00004  * Copyright 2000 Jon Griffiths
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include <precomp.h>
00022 #include <malloc.h>
00023 #include <process.h>
00024 
00025 typedef void (*_beginthread_start_routine_t)(void *);
00026 typedef unsigned int (__stdcall *_beginthreadex_start_routine_t)(void *);
00027 
00028 /********************************************************************/
00029 
00030 typedef struct {
00031   HANDLE thread;
00032   _beginthread_start_routine_t start_address;
00033   void *arglist;
00034 } _beginthread_trampoline_t;
00035 
00036 /*********************************************************************
00037  *      _beginthread_trampoline
00038  */
00039 static DWORD CALLBACK _beginthread_trampoline(LPVOID arg)
00040 {
00041     _beginthread_trampoline_t local_trampoline;
00042     thread_data_t *data = msvcrt_get_thread_data();
00043 
00044     memcpy(&local_trampoline,arg,sizeof(local_trampoline));
00045     data->handle = local_trampoline.thread;
00046     free(arg);
00047 
00048     local_trampoline.start_address(local_trampoline.arglist);
00049     return 0;
00050 }
00051 
00052 /*********************************************************************
00053  *      _beginthread (MSVCRT.@)
00054  */
00055 uintptr_t _beginthread(
00056   _beginthread_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
00057   unsigned int stack_size, /* [in] Stack size for new thread or 0 */
00058   void *arglist)           /* [in] Argument list to be passed to new thread or NULL */
00059 {
00060   _beginthread_trampoline_t* trampoline;
00061   HANDLE thread;
00062 
00063   TRACE("(%p, %d, %p)\n", start_address, stack_size, arglist);
00064 
00065   trampoline = malloc(sizeof(*trampoline));
00066   if(!trampoline) {
00067       *_errno() = EAGAIN;
00068       return -1;
00069   }
00070 
00071   thread = CreateThread(NULL, stack_size, _beginthread_trampoline,
00072           trampoline, CREATE_SUSPENDED, NULL);
00073   if(!thread) {
00074       free(trampoline);
00075       *_errno() = EAGAIN;
00076       return -1;
00077   }
00078 
00079   trampoline->thread = thread;
00080   trampoline->start_address = start_address;
00081   trampoline->arglist = arglist;
00082 
00083   if(ResumeThread(thread) == -1) {
00084       free(trampoline);
00085       *_errno() = EAGAIN;
00086       return -1;
00087   }
00088 
00089   return (uintptr_t)thread;
00090 }
00091 
00092 /*********************************************************************
00093  *      _endthread (MSVCRT.@)
00094  */
00095 void CDECL _endthread(void)
00096 {
00097   TRACE("(void)\n");
00098 
00099   /* FIXME */
00100   ExitThread(0);
00101 }

Generated on Sat May 26 2012 04:23:03 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.