python-on-a-chip online compiler

Dependencies:   mbed TSI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers thread.c Source File

thread.c

Go to the documentation of this file.
00001 /*
00002 # This file is Copyright 2007 Dean Hall.
00003 # This file is part of the PyMite VM.
00004 # This file is licensed under the MIT License.
00005 # See the LICENSE file for details.
00006 */
00007 
00008 
00009 #undef __FILE_ID__
00010 #define __FILE_ID__ 0x16
00011 
00012 
00013 /**
00014  * \file
00015  * \brief VM Thread
00016  *
00017  * Encapsulating a frame pointer, a root code object and thread state.
00018  */
00019 
00020 
00021 #include "pm.h"
00022 
00023 
00024 PmReturn_t
00025 thread_new(pPmObj_t pframe, pPmObj_t *r_pobj)
00026 {
00027     PmReturn_t retval = PM_RET_OK;
00028     pPmThread_t pthread = C_NULL;
00029 
00030     C_ASSERT(pframe != C_NULL);
00031 
00032     /* If it's not a frame, raise TypeError */
00033     if (OBJ_GET_TYPE(pframe) != OBJ_TYPE_FRM)
00034     {
00035         PM_RAISE(retval, PM_RET_EX_TYPE);
00036         return retval;
00037     }
00038 
00039     /* Allocate a thread */
00040     retval = heap_getChunk(sizeof(PmThread_t), (uint8_t **)r_pobj);
00041     PM_RETURN_IF_ERROR(retval);
00042 
00043     /* Set type, frame and initialize status */
00044     pthread = (pPmThread_t)*r_pobj;
00045     OBJ_SET_TYPE(pthread, OBJ_TYPE_THR);
00046     pthread->pframe = (pPmFrame_t)pframe;
00047     pthread->interpctrl = INTERP_CTRL_CONT;
00048 
00049     return retval;
00050 }