/* Called after a peer disconnects */ void mf_peer_context_free(freerdp_peer* client, mfPeerContext* context) { if (context) { mf_info_peer_unregister(context->info, context); dispatch_suspend(info_timer); stream_free(context->s); rfx_context_free(context->rfx_context); //nsc_context_free(context->nsc_context); #ifdef CHANNEL_AUDIN_SERVER if (context->audin) audin_server_context_free(context->audin); #endif //#ifdef CHANNEL_RDPSND_SERVER mf_peer_rdpsnd_stop(); if (context->rdpsnd) rdpsnd_server_context_free(context->rdpsnd); //#endif //#ifdef WITH_SERVER_CHANNELS WTSDestroyVirtualChannelManager(context->vcm); //#endif } }
static void do_test(void) { size_t i; char buf[1000]; dispatch_group_t g = dispatch_group_create(); for (i = 0; i < QUEUES; i++) { #ifdef WIN32 _snprintf(buf, sizeof(buf), "com.example.memoryload-node#%ld", i); #else snprintf(buf, sizeof(buf), "com.example.memoryload-node#%ld", (long int)i); #endif queues[i] = dispatch_queue_create(buf, NULL); dispatch_suspend(queues[i]); } for (i = 0; i < QUEUES; i++) { dispatch_group_async_f(g, queues[i], g, start_node); } dispatch_group_notify_f(g, dispatch_get_main_queue(), NULL, collect); for (i = 0; i < QUEUES; i++) { dispatch_resume(queues[i]); dispatch_release(queues[i]); } }
/* Called after a peer disconnects */ void mf_peer_context_free(freerdp_peer* client, mfPeerContext* context) { if (context) { mf_info_peer_unregister(context->info, context); dispatch_suspend(info_timer); Stream_Free(context->s, TRUE); rfx_context_free(context->rfx_context); //nsc_context_free(context->nsc_context); #ifdef CHANNEL_AUDIN_SERVER if (context->audin) audin_server_context_free(context->audin); #endif //#ifdef CHANNEL_RDPSND_SERVER mf_peer_rdpsnd_stop(); if (context->rdpsnd) rdpsnd_server_context_free(context->rdpsnd); //#endif WTSCloseServer(context->vcm); } }
static void onSocketDataReceived(SocketClientRef client, size_t available) { if( ! listener ) return; dispatch_suspend(client->source); CRESTRequestRef request = NULL; size_t maxRead = sizeof(client->buffer) - 1; if( available > maxRead ) available = maxRead; if( available > 14 ) { int i = 0; char c; while( i < available && recv(client->fd, &c, 1, 0) > 0 && c > 0 ) { client->buffer[i] = c; i++; } request = CRESTRequestCreateWithBytes((UInt8 const *)&client->buffer, i); } CFDataRef responseData = handleRequest(request); ssize_t wd = send(client->fd, (void const *)CFDataGetBytePtr(responseData), (size_t)CFDataGetLength(responseData), 0); // todo #pragma unused(wd) CFRelease(responseData); CRESTRequestDealloc(request); closeSocketClient(client); }
static void do_test(void) { size_t i; char buf[1000]; count_down = COUNT; start = dispatch_time(0,0); for (i = 0; i < COUNT; i++) { #ifdef WIN32 _snprintf(buf, sizeof(buf), "com.example.starfish-node#%ld", i); #else snprintf(buf, sizeof(buf), "com.example.starfish-node#%ld", (long int)i); #endif queues[i] = dispatch_queue_create(buf, NULL); dispatch_suspend(queues[i]); } for (i = 0; i < COUNT; i++) { dispatch_async_f(queues[i], queues[i], start_node); } for (i = 0; i < COUNT; i++) { dispatch_resume(queues[i]); } }
void* InvokeDispatch(int n) { static int dummy = 0; static dispatch_queue_t queue = NULL; if (NULL == queue) queue = dispatch_queue_create("com.apple.gcd.examples.compare.invoke", NULL); dispatch_suspend(queue); for (int i = 0; i < n; i++) { dispatch_async(queue, ^{ dummy = i; }); // Assign variable to avoid over-optimization }
static VALUE rb_dispatch_suspend(VALUE self, SEL sel) { rb_dispatch_obj_t *dobj = RDispatch(self); OSSpinLockLock(&_suspensionLock); dobj->suspension_count++; OSSpinLockUnlock(&_suspensionLock); dispatch_suspend(dobj->obj); return Qnil; }
static int _bsd_send_repeat_msg(struct config_rule *r) { char vt[32], *msg; time_t tick; int len, status; if (r == NULL) return -1; if (r->type != DST_TYPE_FILE) return 0; if (r->last_count == 0) return 0; /* stop the timer */ dispatch_suspend(r->dup_timer); tick = time(NULL); memset(vt, 0, sizeof(vt)); ctime_r(&tick, vt); vt[19] = '\0'; msg = NULL; asprintf(&msg, "%s: --- last message repeated %u time%s ---\n", vt + 4, r->last_count, (r->last_count == 1) ? "" : "s"); r->last_count = 0; if (msg == NULL) return -1; len = strlen(msg); status = write(r->fd, msg, len); if ((status < 0) || (status < len)) { asldebug("%s: error writing repeat message (%s): %s\n", MY_ID, r->dst, strerror(errno)); /* Try re-opening the file (once) and write again */ close(r->fd); r->fd = open(r->dst, O_WRONLY | O_APPEND | O_CREAT | O_NOCTTY, 0644); if (r->fd < 0) { asldebug("%s: re-open failed for file: %s (%s)\n", MY_ID, r->dst, strerror(errno)); free(msg); return -1; } status = write(r->fd, msg, len); if ((status < 0) || (status < len)) { asldebug("%s: error re-writing message (%s): %s\n", MY_ID, r->dst, strerror(errno)); free(msg); return -1; } } free(msg); return 0; }
static void init_globals(void) { static dispatch_once_t once; dispatch_once(&once, ^{ timerq = dispatch_queue_create("hiem-sipc-timer-q", NULL); timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, timerq); dispatch_source_set_event_handler(timer, ^{ timer_ev(); } ); workq = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); eventq = dispatch_queue_create("heim-ipc.event-queue", NULL); dispatch_suspend(eventq); });
static int _gcdpoll_timeout_add(AvahiTimeout *t, const struct timeval *tv) { struct timeval e_tv; struct timeval now; int64_t nsecs; int ret; ret = gettimeofday(&now, NULL); if (ret != 0) return -1; if (!t->timer) { t->timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, mdns_sq); if (!t->timer) return -1; dispatch_set_context(t->timer, t); dispatch_source_set_event_handler_f(t->timer, gcdpollcb_timer); } else dispatch_suspend(t->timer); if ((tv->tv_sec == 0) && (tv->tv_usec == 0)) { dispatch_source_set_timer(t->timer, DISPATCH_TIME_NOW, DISPATCH_TIME_FOREVER /* one-shot */, 0); } else { timersub(tv, &now, &e_tv); nsecs = e_tv.tv_sec * NSEC_PER_SEC + e_tv.tv_usec * 1000; dispatch_source_set_timer(t->timer, dispatch_time(DISPATCH_TIME_NOW, nsecs), DISPATCH_TIME_FOREVER /* one-shot */, 0); } dispatch_resume(t->timer); return 0; }
void test_short_timer(void) { // Add a large number of timers with suspended target queue in front of // the timer being measured <rdar://problem/7401353> g = dispatch_group_create(); q = dispatch_queue_create("q", NULL); int i; for (i = 0; i < N; i++) { t[i] = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, q); dispatch_source_set_timer(t[i], DISPATCH_TIME_NOW, interval, 0); dispatch_group_enter(g); dispatch_source_set_registration_handler(t[i], ^{ dispatch_suspend(t[i]); dispatch_group_leave(g); }); dispatch_resume(t[i]); }
void object::suspend() { dispatch_suspend( native() ); }