Skip to content

Commit

Permalink
Refactor: added type casting(ngx_atomic_t) in the ngx_vhost_traffic_s…
Browse files Browse the repository at this point in the history
…tatus_node_init() and ngx_vhost_traffic_status_node_set()
  • Loading branch information
vozlt committed Feb 17, 2015
1 parent 2995495 commit cba50bd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ngx_http_vhost_traffic_status_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ static void ngx_vhost_traffic_status_node_init(ngx_http_request_t *r,

vtsn->stat_upstream.type = NGX_HTTP_VHOST_TRAFFIC_STATUS_UPSTREAM_NO;
vtsn->stat_request_counter = 1;
vtsn->stat_in_bytes = r->request_length;
vtsn->stat_out_bytes = r->connection->sent;
vtsn->stat_in_bytes = (ngx_atomic_t) r->request_length;
vtsn->stat_out_bytes = (ngx_atomic_t) r->connection->sent;
vtsn->stat_1xx_counter = 0;
vtsn->stat_2xx_counter = 0;
vtsn->stat_3xx_counter = 0;
Expand All @@ -644,8 +644,8 @@ static void ngx_vhost_traffic_status_node_set(ngx_http_request_t *r,
ngx_uint_t status = r->headers_out.status;

vtsn->stat_request_counter++;
vtsn->stat_in_bytes += r->request_length;
vtsn->stat_out_bytes += r->connection->sent;
vtsn->stat_in_bytes += (ngx_atomic_t) r->request_length;
vtsn->stat_out_bytes += (ngx_atomic_t) r->connection->sent;

ngx_vhost_traffic_status_add_rc(status, vtsn);
}
Expand Down

6 comments on commit cba50bd

@itpp16
Copy link

@itpp16 itpp16 commented on cba50bd Feb 17, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still getting errors,
warning C4197: 'ngx_atomic_t' : top-level volatile in cast is ignored

@vozlt
Copy link
Owner Author

@vozlt vozlt commented on cba50bd Feb 17, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your pull request is reopend.

@itpp16
Copy link

@itpp16 itpp16 commented on cba50bd Feb 18, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is with Windows/nginx, vc++ compiler (c99), can you explain what you are doing with atomic_t for which an int_t won't work ?

@vozlt
Copy link
Owner Author

@vozlt vozlt commented on cba50bd Feb 18, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, It works fine for me.
In code, I have declared the stat_(in|out)_bytes variables as a type of ngx_atomic_t, so just used for compatibility.
The point of ngx_atomic_t declaration in src/os/unix/ngx_atomic.h as follows:

typedef ~~~~                        ngx_atomic_int_t;
typedef ~~~~                        ngx_atomic_uint_t;
typedef volatile ngx_atomic_uint_t  ngx_atomic_t;

So maybe the ngx_atomic_uint_t type will be fine without warning in your environment.
Can I get the test result?(ngx_atomic_t to ngx_atomic_uint_t)

@itpp16
Copy link

@itpp16 itpp16 commented on cba50bd Feb 18, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats it, (ngx_atomic_uint_t) solves it ! something is missing in src/os/unix/ngx_atomic.h or it would have been typecasted.

@vozlt
Copy link
Owner Author

@vozlt vozlt commented on cba50bd Feb 21, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience and the test.
It applied.
7b5d42c

Please sign in to comment.