targets/Linux/plc_Linux_main.c
changeset 3302 c89fc366bebd
parent 3295 0375d801fff7
child 3334 d7e0ddb5974b
equal deleted inserted replaced
2744:577118ebd179 3302:c89fc366bebd
   233 
   233 
   234 void LockPython(void)
   234 void LockPython(void)
   235 {
   235 {
   236     pthread_mutex_lock(&python_mutex);
   236     pthread_mutex_lock(&python_mutex);
   237 }
   237 }
       
   238 
       
   239 struct RT_to_nRT_signal_s {
       
   240     pthread_cond_t WakeCond;
       
   241     pthread_mutex_t WakeCondLock;
       
   242 };
       
   243 
       
   244 typedef struct RT_to_nRT_signal_s RT_to_nRT_signal_t;
       
   245 
       
   246 #define _LogAndReturnNull(text) \
       
   247     {\
       
   248     	char mstr[256] = text " for ";\
       
   249         strncat(mstr, name, 255);\
       
   250         LogMessage(LOG_CRITICAL, mstr, strlen(mstr));\
       
   251         return NULL;\
       
   252     }
       
   253 
       
   254 void *create_RT_to_nRT_signal(char* name){
       
   255     RT_to_nRT_signal_t *sig = (RT_to_nRT_signal_t*)malloc(sizeof(RT_to_nRT_signal_t));
       
   256 
       
   257     if(!sig) 
       
   258     	_LogAndReturnNull("Failed allocating memory for RT_to_nRT signal");
       
   259 
       
   260     pthread_cond_init(&sig->WakeCond, NULL);
       
   261     pthread_mutex_init(&sig->WakeCondLock, NULL);
       
   262 
       
   263     return (void*)sig;
       
   264 }
       
   265 
       
   266 void delete_RT_to_nRT_signal(void* handle){
       
   267     RT_to_nRT_signal_t *sig = (RT_to_nRT_signal_t*)handle;
       
   268 
       
   269     pthread_cond_destroy(&sig->WakeCond);
       
   270     pthread_mutex_destroy(&sig->WakeCondLock);
       
   271 
       
   272     free(sig);
       
   273 }
       
   274 
       
   275 int wait_RT_to_nRT_signal(void* handle){
       
   276     int ret;
       
   277     RT_to_nRT_signal_t *sig = (RT_to_nRT_signal_t*)handle;
       
   278     pthread_mutex_lock(&sig->WakeCondLock);
       
   279     ret = pthread_cond_wait(&sig->WakeCond, &sig->WakeCondLock);
       
   280     pthread_mutex_unlock(&sig->WakeCondLock);
       
   281     return ret;
       
   282 }
       
   283 
       
   284 int unblock_RT_to_nRT_signal(void* handle){
       
   285     RT_to_nRT_signal_t *sig = (RT_to_nRT_signal_t*)handle;
       
   286     return pthread_cond_signal(&sig->WakeCond);
       
   287 }
       
   288 
       
   289 void nRT_reschedule(void){
       
   290     sched_yield();
       
   291 }