Пример #1
0
void web_server::run(void)
{
	pthread_attr_t attr;

	pthread_check(pthread_attr_init(&attr), "pthread_attr_init");
	pthread_check(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED), "pthread_attr_setdetachstate");

	for(;;)
	{
		int client_fd = accept(fd, NULL, NULL);

		if (client_fd == -1)
		{
			dolog(LOG_INFO, "web_server: accept failed: %s", strerror(errno));

			continue;
		}

		std::string host = get_endpoint_name(client_fd);

		dolog(LOG_INFO, "web_server: connected with %s", host.c_str());

		http_client_t *p_client = new http_client_t;
		p_client -> p_server = this;
		p_client -> fd = client_fd;

		pthread_t thread;
		pthread_check(pthread_create(&thread, &attr, thread_wrapper_http_server, reinterpret_cast<void *>(p_client)), "pthread_create");
	}
}
Пример #2
0
void start_web_server(config_t *config, std::vector<client_t *> *clients, pthread_mutex_t *clients_mutex, pools *ppools, statistics_global *ps, fips140 *pfips140, scc *pscc, data_logger *dl, users *pusers)
{
	web_server *ws = new web_server(config, clients, clients_mutex, ppools, ps, pfips140, pscc, dl, pusers);

	pthread_attr_t attr;
	pthread_check(pthread_attr_init(&attr), "pthread_attr_init");
	pthread_check(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED), "pthread_attr_setdetachstate");

	pthread_t thread;
	pthread_check(pthread_create(&thread, &attr, start_web_server_thread_wrapper, ws), "pthread_create");
}
Пример #3
0
    bool set_priority(int priority) {
#ifndef _POSIX_PRIORITY_SCHEDULING
      return false;
#else        
      int _policy;
      struct sched_param params;

      pthread_check(pthread_getschedparam(native_, &_policy, &params));
      int max = sched_get_priority_max(_policy);
      int min = sched_get_priority_min(_policy);

      if(min > priority) {
        priority = min;
      }
      else if(max < priority) {
        priority = max;
      }

      params.sched_priority = priority;

      int err = pthread_setschedparam(native_, _policy, &params);
      if(err == ENOTSUP) return false;

      return true;
#endif
    }
Пример #4
0
    int priority() {
      int _policy;
      struct sched_param params;

      pthread_check(pthread_getschedparam(native_, &_policy, &params));

      return params.sched_priority;
    }
Пример #5
0
    void wait(Mutex& mutex) {
      if(cDebugLockGuard) {
        std::cout << "[[ " << pthread_self() << "   CUnlocking " << mutex.describe() << " ]]\n";
      }

      pthread_check(pthread_cond_wait(&native_, mutex.native()));

      if(cDebugLockGuard) {
        std::cout << "[[ " << pthread_self() << "   CLocked " << mutex.describe() << " ]]\n";
      }
    }
Пример #6
0
int pthread_setschedparam(pthread_t t, int pol,  const struct sched_param *p)
{
  struct _pthread_v *pv;
    int r, pr = 0;
    //if (!t.p) t = pthread_self();

    if ((r = pthread_check(t)) != 0)
        return r;

    if (pol < SCHED_MIN || pol > SCHED_MAX || p == NULL)
        return EINVAL;
    if (pol != SCHED_OTHER)
        return ENOTSUP;
    pr = p->sched_priority;
    if (pr < sched_get_priority_min(pol) || pr > sched_get_priority_max(pol))
      return EINVAL;

    /* See msdn: there are actually 7 priorities:
    THREAD_PRIORITY_IDLE    -      -15
    THREAD_PRIORITY_LOWEST          -2
    THREAD_PRIORITY_BELOW_NORMAL    -1
    THREAD_PRIORITY_NORMAL           0
    THREAD_PRIORITY_ABOVE_NORMAL     1
    THREAD_PRIORITY_HIGHEST          2
    THREAD_PRIORITY_TIME_CRITICAL   15
    */
    if (pr <= THREAD_PRIORITY_IDLE) {
        pr = THREAD_PRIORITY_IDLE;
    } else if (pr <= THREAD_PRIORITY_LOWEST) {
        pr = THREAD_PRIORITY_LOWEST;
    } else if (pr >= THREAD_PRIORITY_TIME_CRITICAL) {
        pr = THREAD_PRIORITY_TIME_CRITICAL;
    } else if (pr >= THREAD_PRIORITY_HIGHEST) {
        pr = THREAD_PRIORITY_HIGHEST;
    }
    pv = __pth_gpointer_locked (t);
    if (SetThreadPriority(pv->h, pr)) {
        pv->sched_pol = pol;
        pv->sched.sched_priority = p->sched_priority;
    } else
        r = EINVAL;
    return r;
}
Пример #7
0
int pthread_getschedparam(pthread_t t, int *pol, struct sched_param *p)
{
    int r;
    //if (!t)
    //  t = pthread_self();

    if ((r = pthread_check(t)) != 0)
    {
        return r;
    }

    if (!p || !pol)
    {
        return EINVAL;
    }
    *pol = __pth_gpointer_locked (t)->sched_pol;
    p->sched_priority = __pth_gpointer_locked (t)->sched.sched_priority;

    return 0;
}
Пример #8
0
 void set(T val) {
   pthread_check(pthread_setspecific(native_, reinterpret_cast<void*>(val)));
 }
Пример #9
0
 ~ThreadData() {
   pthread_check(pthread_key_delete(native_));
 }
Пример #10
0
 ThreadData() {
   pthread_check(pthread_key_create(&native_, NULL));
 }
Пример #11
0
 void cancel() {
   pthread_check(pthread_cancel(native_));
 }
Пример #12
0
 void signal() {
   pthread_check(pthread_cond_signal(&native_));
 }
Пример #13
0
 ~Condition() {
   pthread_check(pthread_cond_destroy(&native_));
 }
Пример #14
0
 void init() {
   pthread_check(pthread_cond_init(&native_, NULL));
 }
Пример #15
0
 void init() {
   pthread_mutexattr_t attr;
   pthread_mutexattr_init(&attr);
   pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   pthread_check(pthread_mutex_init(&native_, &attr));
 }
Пример #16
0
 void kill(int sig) {
   pthread_check(pthread_kill(native_, sig));
 }
Пример #17
0
 void broadcast() {
   pthread_check(pthread_cond_broadcast(&native_));
 }
Пример #18
0
 void detach() {
   pthread_check(pthread_detach(native_));
 }