bool ConnectionContext::check_closed() { if (sync_get(&close_flag_) == 1) return true; else if (type_ & ConnectionContext::ssl && sync_get(&shutdown_flag_) == 1) return true; return false; }
AIO_COMM_API heap& get_global_heap() { heap * global_heap = sync_get(g_global_heap); if (global_heap == 0){ init_global_heap_once(); global_heap = sync_get(g_global_heap); } AIO_PRE_CONDITION(global_heap != 0); return *global_heap; }
void main(int argc,char* argv[]) { int i,j,t,k,l,m,yoda,limu,lim,seed,str,etr; printf("Enter number of iterations\n"); scanf("%d",&l); printf("Enter number upto which you want to count\n"); scanf("%d",&seed); printf("Enter minimum number of threads\n"); scanf("%d",&str); printf("Enter maximum number of threads\n"); scanf("%d",&etr); assert(etr>=str); double records[etr+1-str]; for(i=0;i<etr+1-str;i++) { records[i]=0; } pthread_t p[etr]; for(m=str;m<=etr;m++) { //Number of iterations for averaging : for(yoda=0;yoda<l;yoda++) { struct timeval start,end; sync_init(&x); value=0; lim=seed; limu=lim/m; gettimeofday(&start,NULL); //Create 'm-1' threads for(j=0;j<m-1;j++) { k=pthread_create(&p[j],NULL,counter,(void*)&limu); lim-=limu; } //Remainder added to the last thread: k=pthread_create(&p[m-1],NULL,counter,(void*)&lim); //Wait for those 'm' threads to finish: for(j=0;j<m;j++) { pthread_join(p[j],NULL); } gettimeofday(&end,NULL); records[m-str]+=((end.tv_sec-start.tv_sec)*1000000 + end.tv_usec-start.tv_usec)/1000000.0; value+=sync_get(&x); } printf("Final value (average) of counter for %d threads : %d\n",m,sync_get(&x)); } for(j=0;j<etr+1-str;j++) { printf("Average time taken for %d threads : %lf\n",j+str,records[j]/l); } }
void IOCPWebServer::CheckAndDelete(ConnectionContext *ctx) { long ret = sync_dec(&ctx->ref_); assert(ret >= 0); if (ret != 0) return; if (ctx->type_ == ConnectionContext::https && sync_get(&ctx->close_flag_) != 1 && sync_get(&ctx->shutdown_flag_) != 1) ctx->Shutdown(); else { if (cbOnClosed) cbOnClosed(ctx); delete ctx; } }
int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, freenect_depth_format fmt) { if (index < 0 || index >= MAX_KINECTS) { printf("Error: Invalid index [%d]\n", index); return -1; } if (!thread_running || !kinects[index] || kinects[index]->depth.fmt != fmt) if (setup_kinect(index, fmt, 1)) return -1; sync_get(depth, timestamp, &kinects[index]->depth); return 0; }
int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, freenect_video_format fmt) { if (index < 0 || index >= MAX_KINECTS) { printf("Error: Invalid index [%d]\n", index); return -1; } if (!thread_running || !kinects[index] || kinects[index]->video.fmt != fmt) if (setup_kinect(index, fmt, 0)) return -1; sync_get(video, timestamp, &kinects[index]->video); return 0; }
void socket_ops::connect(iocp::socket &socket, iocp::operation *op, const iocp::address &addr, unsigned short port) { iocp::service &service = socket.service(); service.work_started(); iocp::error_code ec = socket.open(); if (ec.value() == iocp::error::already_open) ec.set_value(0); // IOCP needs socket to bind an address before calling ConnectEx if (!ec && !sync_get(&socket.already_binded_)) { ec = service.bind(socket.socket_, iocp::address(0U), 0); if (!ec) sync_set(&socket.already_binded_, 1); } if (ec) service.on_completion(op, ec); else service.connect(socket.socket_, op, addr, port); }