LCOV - code coverage report
Current view: top level - plugins/http - http_timer.h (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 0 25 0.0 %
Date: 2023-07-05 22:20:52 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2022 Cisco and/or its affiliates.
       3             :  * Licensed under the Apache License, Version 2.0 (the "License");
       4             :  * you may not use this file except in compliance with the License.
       5             :  * You may obtain a copy of the License at:
       6             :  *
       7             :  *     http://www.apache.org/licenses/LICENSE-2.0
       8             :  *
       9             :  * Unless required by applicable law or agreed to in writing, software
      10             :  * distributed under the License is distributed on an "AS IS" BASIS,
      11             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             :  * See the License for the specific language governing permissions and
      13             :  * limitations under the License.
      14             :  */
      15             : 
      16             : #ifndef SRC_PLUGINS_HTTP_HTTP_TIMER_H_
      17             : #define SRC_PLUGINS_HTTP_HTTP_TIMER_H_
      18             : 
      19             : #include <http/http.h>
      20             : #include <vppinfra/tw_timer_2t_1w_2048sl.h>
      21             : 
      22             : #define HTTP_CONN_TIMEOUT 60
      23             : 
      24             : typedef void (http_conn_timeout_fn) (void *);
      25             : 
      26             : typedef struct http_tw_ctx_
      27             : {
      28             :   tw_timer_wheel_2t_1w_2048sl_t tw;
      29             :   clib_spinlock_t tw_lock;
      30             :   http_conn_timeout_fn *cb_fn;
      31             : } http_tw_ctx_t;
      32             : 
      33             : extern http_tw_ctx_t http_tw_ctx;
      34             : 
      35             : void http_timers_init (vlib_main_t *vm, http_conn_timeout_fn *cb_fn);
      36             : 
      37             : static inline void
      38           0 : http_conn_timer_start (http_conn_t *hc)
      39             : {
      40           0 :   http_tw_ctx_t *twc = &http_tw_ctx;
      41             :   u32 hs_handle;
      42             :   u64 timeout;
      43             : 
      44           0 :   timeout = HTTP_CONN_TIMEOUT;
      45           0 :   hs_handle = hc->c_thread_index << 24 | hc->c_c_index;
      46             : 
      47           0 :   clib_spinlock_lock (&twc->tw_lock);
      48           0 :   hc->timer_handle =
      49           0 :     tw_timer_start_2t_1w_2048sl (&twc->tw, hs_handle, 0, timeout);
      50           0 :   clib_spinlock_unlock (&twc->tw_lock);
      51           0 : }
      52             : 
      53             : static inline void
      54           0 : http_conn_timer_stop (http_conn_t *hc)
      55             : {
      56           0 :   http_tw_ctx_t *twc = &http_tw_ctx;
      57             : 
      58           0 :   if (hc->timer_handle == ~0)
      59           0 :     return;
      60             : 
      61           0 :   clib_spinlock_lock (&twc->tw_lock);
      62           0 :   tw_timer_stop_2t_1w_2048sl (&twc->tw, hc->timer_handle);
      63           0 :   hc->timer_handle = ~0;
      64           0 :   clib_spinlock_unlock (&twc->tw_lock);
      65             : }
      66             : 
      67             : static inline void
      68           0 : http_conn_timer_update (http_conn_t *hc)
      69             : {
      70           0 :   http_tw_ctx_t *twc = &http_tw_ctx;
      71             :   u64 timeout;
      72             : 
      73           0 :   if (hc->timer_handle == ~0)
      74           0 :     return;
      75             : 
      76           0 :   timeout = HTTP_CONN_TIMEOUT;
      77             : 
      78           0 :   clib_spinlock_lock (&twc->tw_lock);
      79           0 :   tw_timer_update_2t_1w_2048sl (&twc->tw, hc->timer_handle, timeout);
      80           0 :   clib_spinlock_unlock (&twc->tw_lock);
      81             : }
      82             : 
      83             : #endif /* SRC_PLUGINS_HTTP_HTTP_TIMER_H_ */
      84             : 
      85             : /*
      86             :  * fd.io coding-style-patch-verification: ON
      87             :  *
      88             :  * Local Variables:
      89             :  * eval: (c-set-style "gnu")
      90             :  * End:
      91             :  */

Generated by: LCOV version 1.14