view src/os/unix/ngx_freebsd_rfork_thread.h @ 676:bfa81a0490a2 NGINX_1_3_1

nginx 1.3.1 *) Security: now nginx/Windows ignores trailing dot in URI path component, and does not allow URIs with ":$" in it. Thanks to Vladimir Kochetkov, Positive Research Center. *) Feature: the "proxy_pass", "fastcgi_pass", "scgi_pass", "uwsgi_pass" directives, and the "server" directive inside the "upstream" block, now support IPv6 addresses. *) Feature: the "resolver" directive now support IPv6 addresses and an optional port specification. *) Feature: the "least_conn" directive inside the "upstream" block. *) Feature: it is now possible to specify a weight for servers while using the "ip_hash" directive. *) Bugfix: a segmentation fault might occur in a worker process if the "image_filter" directive was used; the bug had appeared in 1.3.0. *) Bugfix: nginx could not be built with ngx_cpp_test_module; the bug had appeared in 1.1.12. *) Bugfix: access to variables from SSI and embedded perl module might not work after reconfiguration. Thanks to Yichun Zhang. *) Bugfix: in the ngx_http_xslt_filter_module. Thanks to Kuramoto Eiji. *) Bugfix: memory leak if $geoip_org variable was used. Thanks to Denis F. Latypoff. *) Bugfix: in the "proxy_cookie_domain" and "proxy_cookie_path" directives.
author Igor Sysoev <http://sysoev.ru>
date Tue, 05 Jun 2012 00:00:00 +0400
parents d0f7a625f27c
children
line wrap: on
line source


/*
 * Copyright (C) Igor Sysoev
 * Copyright (C) Nginx, Inc.
 */


#ifndef _NGX_FREEBSD_RFORK_THREAD_H_INCLUDED_
#define _NGX_FREEBSD_RFORK_THREAD_H_INCLUDED_


#include <sys/ipc.h>
#include <sys/sem.h>
#include <sched.h>

typedef pid_t  ngx_tid_t;

#define ngx_log_pid    ngx_thread_self()
#define ngx_log_tid    0

#define NGX_TID_T_FMT  "%P"


#define NGX_MUTEX_LIGHT      1

#define NGX_MUTEX_LOCK_BUSY  0x80000000

typedef volatile struct {
    ngx_atomic_t  lock;
    ngx_log_t    *log;
    int           semid;
} ngx_mutex_t;


#define NGX_CV_SIGNAL        64

typedef struct {
    int           signo;
    int           kq;
    ngx_tid_t     tid;
    ngx_log_t    *log;
} ngx_cond_t;


#define ngx_thread_sigmask(how, set, oset)                         \
            (sigprocmask(how, set, oset) == -1) ? ngx_errno : 0

#define ngx_thread_sigmask_n   "sigprocmask()"

#define ngx_thread_join(t, p)

#define ngx_setthrtitle(n)     setproctitle(n)


extern char    *ngx_freebsd_kern_usrstack;
extern size_t   ngx_thread_stack_size;


static ngx_inline ngx_int_t
ngx_gettid()
{
    char  *sp;

    if (ngx_thread_stack_size == 0) {
        return 0;
    }

#if ( __i386__ )

    __asm__ volatile ("mov %%esp, %0" : "=q" (sp));

#elif ( __amd64__ )

    __asm__ volatile ("mov %%rsp, %0" : "=q" (sp));

#else

#error "rfork()ed threads are not supported on this platform"

#endif

    return (ngx_freebsd_kern_usrstack - sp) / ngx_thread_stack_size;
}


ngx_tid_t ngx_thread_self();


typedef ngx_uint_t               ngx_tls_key_t;

#define NGX_THREAD_KEYS_MAX      16

extern void    **ngx_tls;

ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key);
#define ngx_thread_key_create_n  "the tls key creation"

ngx_err_t ngx_thread_set_tls(ngx_tls_key_t key, void *value);
#define ngx_thread_set_tls_n     "the tls key setting"


static void *
ngx_thread_get_tls(ngx_tls_key_t key)
{
    if (key >= NGX_THREAD_KEYS_MAX) {
        return NULL;
    }

    return ngx_tls[key * NGX_THREAD_KEYS_MAX + ngx_gettid()];
}


#define ngx_mutex_trylock(m)  ngx_mutex_dolock(m, 1)
#define ngx_mutex_lock(m)     (void) ngx_mutex_dolock(m, 0)
ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try);
void ngx_mutex_unlock(ngx_mutex_t *m);


typedef int (*ngx_rfork_thread_func_pt)(void *arg);


#endif /* _NGX_FREEBSD_RFORK_THREAD_H_INCLUDED_ */