void * osip_fifo_get (osip_fifo_t * ff) { void *el; int i = osip_sem_wait (ff->qisempty); if (i != 0) return NULL; osip_mutex_lock (ff->qislocked); if (ff->etat != vide) { el = osip_list_get (ff->queue, 0); osip_list_remove (ff->queue, 0); /* ff->nb_elt--; */ } else { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "no element in fifo.\n")); osip_mutex_unlock (ff->qislocked); return 0; /* pile vide */ } /* if (ff->nb_elt <= 0) */ if (osip_list_size (ff->queue) <= 0) ff->etat = vide; else ff->etat = ok; osip_mutex_unlock (ff->qislocked); return el; }
int osip_fifo_insert (osip_fifo_t * ff, void *el) { #ifdef OSIP_MT osip_mutex_lock (ff->qislocked); #endif if (ff->etat != plein) { /* ff->nb_elt++; */ osip_list_add (ff->queue, el, 0); /* insert at end of queue */ } else { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "too much traffic in fifo.\n")); #ifdef OSIP_MT osip_mutex_unlock (ff->qislocked); #endif return -1; /* stack is full */ } /* if (ff->nb_elt >= MAX_LEN) */ if (osip_list_size (ff->queue) >= MAX_LEN) ff->etat = plein; else ff->etat = ok; #ifdef OSIP_MT osip_sem_post (ff->qisempty); osip_mutex_unlock (ff->qislocked); #endif return 0; }
int window_loglines_print() { char buf1[200]; int x, y; getmaxyx(stdscr,y,x); if (log_buf1!='\0') { /* int xpos; */ osip_mutex_lock(log_mutex); snprintf(buf1,199, "%199.199s", " "); attrset(COLOR_PAIR(4)); mvaddnstr(y-1,0,buf1,x-1); /* xpos = (x - strlen(log_buf1))/2; if (xpos<0) xpos = 0; */ /* mvaddnstr(y-1,xpos,log_buf1,x-1); */ mvaddnstr(y-1,0,log_buf1,x-1); osip_mutex_unlock(log_mutex); } if (log_buf2!='\0') { /* int xpos; */ osip_mutex_lock(log_mutex); snprintf(buf1,199, "%199.199s", " "); attrset(COLOR_PAIR(4)); mvaddnstr(y-2,0,buf1,x-1); /* xpos = (x - strlen(log_buf2))/2; if (xpos<0) xpos = 0; */ /* mvaddnstr(y-2,xpos,log_buf2,x-1); */ mvaddnstr(y-2,0,log_buf2,x-1); osip_mutex_unlock(log_mutex); } if (log_buf3!='\0') { /* int xpos; */ osip_mutex_lock(log_mutex); snprintf(buf1,199, "%199.199s", " "); attrset(COLOR_PAIR(4)); mvaddnstr(y-3,0,buf1,x-1); /* xpos = (x - strlen(log_buf3))/2; if (xpos<0) xpos = 0; */ /* mvaddnstr(y-3,xpos,log_buf3,x-1); */ mvaddnstr(y-3,0,log_buf3,x-1); osip_mutex_unlock(log_mutex); } return 0; }
void CIstTransaction::ExecuteTimer() { #ifdef OSIP_MT osip_mutex_lock(ict_fastmutex); #endif /* handle ict timers */ CSipEvent* evt; evt = TimerITriger(); if (evt != NULL) transactionff->Add(evt); else { evt = TimerHTriger(); if (evt != NULL) transactionff->Add(evt); else { evt = TimerGTriger(); if (evt != NULL) transactionff->Add(evt); } } #ifdef OSIP_MT osip_mutex_unlock(ict_fastmutex); #endif }
void * osip_fifo_tryget (osip_fifo_t * ff) { void *el; #ifdef OSIP_MT if (0 != osip_sem_trywait (ff->qisempty)) { /* no elements... */ return NULL; } osip_mutex_lock (ff->qislocked); #else if (ff->etat == vide) return NULL; #endif if (ff->etat != vide) { el = osip_list_get (ff->queue, 0); osip_list_remove (ff->queue, 0); /* ff->nb_elt--; */ } #ifdef OSIP_MT else { /* this case MUST never happen... */ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO4, NULL, "no element in fifo.\n")); osip_mutex_unlock (ff->qislocked); return 0; } #endif /* if (ff->nb_elt <= 0) */ if (osip_list_size (ff->queue) <= 0) ff->etat = vide; else ff->etat = ok; #ifdef OSIP_MT osip_mutex_unlock (ff->qislocked); #endif return el; }
void * osip_fifo_get (osip_fifo_t * ff) { void *el = NULL; #ifdef OSIP_MT int i = osip_sem_wait (ff->qisempty); if (i != 0) return NULL; osip_mutex_lock (ff->qislocked); #endif if (ff->state != osip_empty) { el = osip_list_get (&ff->queue, 0); osip_list_remove (&ff->queue, 0); /* ff->nb_elt--; */ } else { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "no element in fifo.\n")); #ifdef OSIP_MT osip_mutex_unlock (ff->qislocked); #endif return 0; /* pile vide */ } /* if (ff->nb_elt <= 0) */ if (osip_list_size (&ff->queue) <= 0) ff->state = osip_empty; else ff->state = osip_ok; #ifdef OSIP_MT osip_mutex_unlock (ff->qislocked); #endif return el; }
int osip_cond_wait (struct osip_cond *_cond, struct osip_mutex *_mut) { int ret1 = 0, ret2 = 0, ret3 = 0; if (!_cond) return -1; if (osip_mutex_lock (_cond->mut)) return -1; if (osip_mutex_unlock (_mut)) return -1; ret1 = osip_sem_wait (_cond->sem); ret2 = osip_mutex_lock (_mut); ret3 = osip_mutex_unlock (_cond->mut); if (ret1 || ret2 || ret3) return -1; return 0; }
int osip_fifo_size (osip_fifo_t * ff) { int i; #ifdef OSIP_MT osip_mutex_lock (ff->qislocked); #endif i = osip_list_size (ff->queue); #ifdef OSIP_MT osip_mutex_unlock (ff->qislocked); #endif return i; }
int osip_cond_timedwait (struct osip_cond *_cond, struct osip_mutex *_mut, const struct timespec *abstime) { DWORD dwRet; struct timespec now; int timeout_ms; HANDLE sem; if (!_cond) return -1; sem = *((HANDLE *) _cond->sem); if (sem == NULL) return -1; if (abstime == NULL) return -1; __osip_clock_gettime (OSIP_CLOCK_REALTIME, &now); timeout_ms = _delta_time (&now, abstime); if (timeout_ms <= 0) return 1; /* ETIMEDOUT; */ if (osip_mutex_unlock (_mut)) return -1; dwRet = WaitForSingleObject (sem, timeout_ms); if (osip_mutex_lock (_mut)) return -1; switch (dwRet) { case WAIT_OBJECT_0: return 0; break; case WAIT_TIMEOUT: return 1; /* ETIMEDOUT; */ break; default: return -1; break; } }
void CIctTransaction::ExecuteTimer() { #ifdef OSIP_MT osip_mutex_lock(ict_fastmutex); #endif /* handle ict timers */ CSipEvent* evt; if (1 <= transactionff->GetSize()) { } else { evt = TimerBTriger(); if (evt != NULL) transactionff->Add(evt); else { evt = TimerATriger(); if (evt != NULL) transactionff->Add(evt); else { evt = TimerDTriger(); if (evt != NULL) transactionff->Add(evt); } } } #ifdef OSIP_MT osip_mutex_unlock(ict_fastmutex); #endif }
void josua_printf(char *chfr, ...) { va_list ap; char buf1[256]; VA_START (ap, chfr); vsnprintf(buf1,255, chfr, ap); if (log_mutex==NULL) { log_mutex = osip_mutex_init(); } osip_mutex_lock(log_mutex); /* snprintf(log_buf1,199, "%80.80s\n", buf1); */ if (log_buf1=='\0') snprintf(log_buf1,255, "[%s]", buf1); else if (log_buf2=='\0') { if (log_buf1!='\0') snprintf(log_buf2,255, "%s", log_buf1); snprintf(log_buf1,255, "[%s]", buf1); } else { if (log_buf2!='\0') snprintf(log_buf3,255, "%s", log_buf2); snprintf(log_buf2,255, "%s", log_buf1); snprintf(log_buf1,255, "[%s]", buf1); } osip_mutex_unlock(log_mutex); va_end (ap); }
int eXosip_unlock (void) { return osip_mutex_unlock ((struct osip_mutex *) eXosip.j_mutexlock); }