A bug, apr_os_thread_current() not equal r-connection-current_thread

2011-11-15 Thread zhiguo zhao
Hi,
   I failed with this on windows with branch 2.4.x,  in a handle hook,

apr_os_thread_t t = apr_os_thread_current();
apr_os_thread_t *t1;
apr_os_thread_get(t1,  r-connection-current_thread);
printf(EQUALS %d\n,apr_os_thread_equal(t,t1));

I think t and t1 must be equal, But it Not.

I think this is a bug, Is this?


Re: A bug, apr_os_thread_current() not equal r-connection-current_thread

2011-11-15 Thread William A. Rowe Jr.

On 11/15/2011 7:43 AM, zhiguo zhao wrote:

Hi,
I failed with this on windows with branch 2.4.x,  in a handle hook,

apr_os_thread_t t = apr_os_thread_current();
apr_os_thread_t *t1;
apr_os_thread_get(t1,  r-connection-current_thread);
printf(EQUALS %d\n,apr_os_thread_equal(t,t1));

I think t and t1 must be equal, But it Not.

I think this is a bug, Is this?


No, it's not.

/**
 * Compare two thread id's
 * @param tid1 1st Thread ID to compare
 * @param tid2 2nd Thread ID to compare
 * @return non-zero if the two threads are equal, zero otherwise
 */
APR_DECLARE(int) apr_os_thread_equal(apr_os_thread_t tid1,
 apr_os_thread_t tid2);

This behavior is by design, use the designated comparator.


Re: A bug, apr_os_thread_current() not equal r-connection-current_thread

2011-11-15 Thread zhiguo zhao
Why not.
In mpm\winnt\child.c


/*
 * worker_main()
 * Main entry point for the worker threads. Worker threads block in
 * win*_get_connection() awaiting a connection to service.
 */
static DWORD __stdcall worker_main(void *thread_num_val)
{
apr_thread_t *thd = NULL;
apr_os_thread_t osthd;
static int requests_this_child = 0;
winnt_conn_ctx_t *context = NULL;
int thread_num = (int)thread_num_val;
ap_sb_handle_t *sbh;
apr_bucket *e;
int rc;
conn_rec *c;
apr_int32_t disconnected;

/* here get real os thread */
osthd = apr_os_thread_current();
/* create a apr_thread_t */
apr_os_thread_put(thd, osthd, pchild);

/*osthd and thd will not changed */

while (1) {

ap_update_child_status_from_indexes(0, thread_num, SERVER_READY,
NULL);

/* Grab a connection off the network */
context = winnt_get_connection(context);

if (!context) {
/* Time for the thread to exit */
break;
}

/* Have we hit MaxConnectionsPerChild connections? */
if (ap_max_requests_per_child) {
requests_this_child++;
if (requests_this_child  ap_max_requests_per_child) {
SetEvent(max_requests_per_child_event);
}
}

e = context-overlapped.Pointer;

ap_create_sb_handle(sbh, context-ptrans, 0, thread_num);
c = ap_run_create_connection(context-ptrans, ap_server_conf,
 context-sock, thread_num, sbh,
 context-ba);

if (!c)
{
/* ap_run_create_connection closes the socket on failure */
context-accept_socket = INVALID_SOCKET;
if (e)
apr_bucket_free(e);
continue;
}

/* c-current_thread changed, the thd */
c-current_thread = thd;

/* follow ap_process_connection(c, context-sock) logic
 * as it left us no chance to reinject our first data bucket.
 */
ap_update_vhost_given_ip(c);

rc = ap_run_pre_connection(c, context-sock);
if (rc != OK  rc != DONE) {
c-aborted = 1;
}

if (e  c-aborted)
{
apr_bucket_free(e);
}
else if (e)
{
core_ctx_t *ctx;
core_net_rec *net;
ap_filter_t *filt;

filt = c-input_filters;
while ((strcmp(filt-frec-name, core_in) != 0)  filt-next)
filt = filt-next;
net = filt-ctx;
ctx = net-in_ctx;

if (net-in_ctx)
ctx = net-in_ctx;
else
{
ctx = apr_pcalloc(c-pool, sizeof(*ctx));
ctx-b = apr_brigade_create(c-pool, c-bucket_alloc);
ctx-tmpbb = apr_brigade_create(c-pool, c-bucket_alloc);

/* seed the brigade with AcceptEx read heap bucket */
e = context-overlapped.Pointer;
APR_BRIGADE_INSERT_HEAD(ctx-b, e);

/* also seed the brigade with the client socket. */
e = apr_bucket_socket_create(net-client_socket,
 c-bucket_alloc);
APR_BRIGADE_INSERT_TAIL(ctx-b, e);
net-in_ctx = ctx;
}
}

if (!c-aborted)
{
ap_run_process_connection(c);

apr_socket_opt_get(context-sock, APR_SO_DISCONNECTED,
   disconnected);

if (!disconnected) {
context-accept_socket = INVALID_SOCKET;
ap_lingering_close(c);
}
}
}

ap_update_child_status_from_indexes(0, thread_num, SERVER_DEAD,
(request_rec *) NULL);

return 0;
}


2011/11/16 William A. Rowe Jr. wr...@rowe-clan.net

 On 11/15/2011 7:43 AM, zhiguo zhao wrote:

 Hi,
I failed with this on windows with branch 2.4.x,  in a handle hook,

 apr_os_thread_t t = apr_os_thread_current();
 apr_os_thread_t *t1;
 apr_os_thread_get(t1,  r-connection-current_thread)**;
 printf(EQUALS %d\n,apr_os_thread_equal(t,**t1));

 I think t and t1 must be equal, But it Not.

 I think this is a bug, Is this?


 No, it's not.

 /**
  * Compare two thread id's
  * @param tid1 1st Thread ID to compare
  * @param tid2 2nd Thread ID to compare
  * @return non-zero if the two threads are equal, zero otherwise
  */
 APR_DECLARE(int) apr_os_thread_equal(apr_os_**thread_t tid1,
 apr_os_thread_t tid2);

 This behavior is by design, use the designated comparator.



Re: A bug, apr_os_thread_current() not equal r-connection-current_thread

2011-11-15 Thread zhiguo zhao
Sorry, I make a mistack.


apr_os_thread_t t = apr_os_thread_current();
apr_os_thread_t *t1;
apr_os_thread_get(t1,  r-connection-current_thread);
printf(EQUALS %d\n,apr_os_thread_equal(t, *t1));
Tow different type data to comp, so it's will fail.