Category : C Source Code
Archive   : TASK_C.ZIP
Filename : TSETUP.C

 
Output of file : TSETUP.C contained in archive : TASK_C.ZIP
/*****************************************************
File: TSETUP.C John M. DLugosz
function to set up a new thread.
Companion to TSW.ASM
*****************************************************/

static void task_return ()
{ /* 'called' then thread function returns */
exit(0);
}

/* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */

unsigned setup_thread (thread, arg, workspace, size)
void (far *thread)(); /* function to startup */
void far *arg; /* argument to (*thread)() */
unsigned near *workspace; /* stack for new thread */
int size; /* size of workspace in bytes */
{
/* set up stack on workspace so it can be "returned" to.
switching to this task will then start up the passed function.

how to set up the stack:
+4 workspace+(size of stack) is beyond end
+3 task argument 'arg'
+2 task return 'task_return'
+1 return from do_tswitch 'thread'
saveSP saved SI,DI,
saved BP

everything being put on the stack is a far pointer, so make
the stack an array of such. The odd word (saved BP) is skipped
over after the cast in the return statement by subtracting 2.
*/

void far * near *saveSP= (void far * near *)workspace;

saveSP += (size/(sizeof *saveSP)) -4; /* see chart above */
saveSP[1]= thread;
saveSP[2]= task_return;
saveSP[3]= arg;
return (unsigned)saveSP -2;
}


  3 Responses to “Category : C Source Code
Archive   : TASK_C.ZIP
Filename : TSETUP.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/