rpc_state* add_cb(rpc_state *state) { // Do nothing //uint32_t j = apr_atomic_add32(&n_rpc_, 1); uint32_t *res = (uint32_t*) state->raw_input; uint32_t k = *res; n_callbacks_[k] += 1; LOG_DEBUG("client callback exceuted. rpc no: %d", n_rpc_); if (n_callbacks_[k] == max_rpc_) { if (apr_atomic_dec32(&n_active_cli_) == 0) { tm_end_ = apr_time_now(); apr_thread_mutex_lock(mx_rpc_); apr_thread_cond_signal(cd_rpc_); apr_thread_mutex_unlock(mx_rpc_); } } if (n_callbacks_[k] % 1000000 == 0) { apr_atomic_add32(&n_rpc_, 1000000); tm_middle_ = apr_time_now(); uint64_t p = tm_middle_ - tm_begin_; double rate = n_rpc_ * 1.0 / p; LOG_INFO("rpc rate: %0.2f million per second", rate); } // do another rpc. if (max_rpc_ < 0 || n_issues_[k] < max_rpc_) { n_issues_[k]++; call_add(clis_[k], k); } return NULL; }
rpc_state* add_cb(rpc_state *state) { // Do nothing //uint32_t j = apr_atomic_add32(&n_rpc_, 1); n_rpc_ += 1; LOG_DEBUG("client callback exceuted. rpc no: %d", n_rpc_); if (n_rpc_ == max_rpc_ * n_client_) { tm_end_ = apr_time_now(); apr_thread_mutex_lock(mx_rpc_); apr_thread_cond_signal(cd_rpc_); apr_thread_mutex_unlock(mx_rpc_); } // } if (n_rpc_ % 1000000 == 0) { tm_middle_ = apr_time_now(); uint64_t p = tm_middle_ - tm_begin_; double rate = n_rpc_ * 1.0 / p; LOG_INFO("rpc rate: %0.2f million per second", rate); } if (max_rpc_ < 0 || n_issued_ < max_rpc_) { n_issued_++; call_add(cli_); } // do another rpc. return NULL; }
int main(int argc,char* argv[]) { lua_State *L; int ok; int res; char str[80]; printf("[C] Welcome to the simple embedded Lua example v2\n"); printf("[C] We are in C\n"); printf("[C] opening a Lua state & loading the libraries\n"); L=lua_open(); luaopen_base(L); luaopen_string(L); luaopen_math(L); printf("[C] now loading the SWIG wrappered library\n"); luaopen_example(L); printf("[C] all looks ok\n"); printf("\n"); printf("[C] lets load the file 'runme.lua'\n"); printf("[C] any lua code in this file will be executed\n"); if (luaL_loadfile(L, "runme.lua") || lua_pcall(L, 0, 0, 0)) { printf("[C] ERROR: cannot run lua file: %s",lua_tostring(L, -1)); exit(3); } printf("[C] We are now back in C, all looks ok\n"); printf("\n"); printf("[C] lets call the Lua function 'add(1,1)'\n"); printf("[C] using the C function 'call_add'\n"); ok=call_add(L,1,1,&res); printf("[C] the function returned %d with value %d\n",ok,res); printf("\n"); printf("[C] lets do this rather easier\n"); printf("[C] we will call the same Lua function using a generic C function 'call_va'\n"); ok=call_va(L,"add","ii>i",1,1,&res); printf("[C] the function returned %d with value %d\n",ok,res); printf("\n"); printf("[C] we will now use the same generic C function to call 'append(\"cat\",\"dog\")'\n"); ok=call_va(L,"append","ss>s","cat","dog",str); printf("[C] the function returned %d with value %s\n",ok,str); printf("\n"); printf("[C] we can also make some bad calls to ensure the code doesn't fail\n"); printf("[C] calling adds(1,2)\n"); ok=call_va(L,"adds","ii>i",1,2,&res); printf("[C] the function returned %d with value %d\n",ok,res); printf("[C] calling add(1,'fred')\n"); ok=call_va(L,"add","is>i",1,"fred",&res); printf("[C] the function returned %d with value %d\n",ok,res); printf("\n"); printf("[C] Note: no protection if you mess up the va-args, this is C\n"); printf("\n"); printf("[C] Finally we will call the wrappered gcd function gdc(6,9):\n"); printf("[C] This will pass the values to Lua, then call the wrappered function\n"); printf(" Which will get the values from Lua, call the C code \n"); printf(" and return the value to Lua and eventually back to C\n"); printf("[C] Certainly not the best way to do it :-)\n"); ok=call_va(L,"gcd","ii>i",6,9,&res); printf("[C] the function returned %d with value %d\n",ok,res); printf("\n"); printf("[C] all finished, closing the lua state\n"); lua_close(L); return 0; }
void test_printk(void){ call_add(); showCurAdd(); printk("Here begins test for printk.\n"); showCurAdd(); printk(" Numbers: %d, %d, %d, %d, %x.\n", 0, 42, 2011, -1024, 0xABCD); showCurAdd(); printk(" Strings: \"%s\", \"s\"\n", "hello", "world"); }
void* APR_THREAD_FUNC client_thread(apr_thread_t *th, void *v) { client_t *client = NULL; client_create(&client, NULL); strcpy(client->comm->ip, addr_); client->comm->port = port_; client_reg(client, ADD, add_cb); tm_begin_ = apr_time_now(); client_connect(client); cli_ = client; // printf("client connected.\n"); n_issued_ += max_outst_; for (int i = 0; i < max_outst_; i++) { call_add(cli_); } apr_thread_exit(th, APR_SUCCESS); return NULL; }
void* APR_THREAD_FUNC client_thread(apr_thread_t *th, void *v) { poll_mgr_t *mgr = NULL; client_t *client = NULL; poll_mgr_create(&mgr, 1); client_create(&client, mgr); strcpy(client->comm->ip, addr_); client->comm->port = port_; client_reg(client, ADD, add_cb); tm_begin_ = apr_time_now(); client_connect(client); int k = (intptr_t) v; mgrs_[k] = mgr; clis_[k] = client; // printf("client connected.\n"); n_issues_[k] += max_outst_; for (int i = 0; i < max_outst_; i++) { call_add(clis_[k], k); } apr_thread_exit(th, APR_SUCCESS); return NULL; }