Sha256: 6ce758507ab5b6b865b4b96b60bf43a899cfeda35770e01ae0d58a508794d5e1
Contents?: true
Size: 935 Bytes
Versions: 74
Compression:
Stored size: 935 Bytes
Contents
/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ #ifdef _WIN32 #include <windows.h> #define sleep(x) Sleep(x) #endif #ifndef _WIN32 #include <unistd.h> #include <pthread.h> #endif int testAdd(int a, int b) { return a + b; }; int testFunctionAdd(int a, int b, int (*f)(int, int)) { return f(a, b); }; void testBlocking(int seconds) { sleep(seconds); }; struct async_data { void (*fn)(int); int value; }; static void* asyncThreadCall(void *data) { struct async_data* d = (struct async_data *) data; if (d != NULL && d->fn != NULL) { (*d->fn)(d->value); } return NULL; } void testAsyncCallback(void (*fn)(int), int value) { #ifndef _WIN32 pthread_t t; struct async_data d; d.fn = fn; d.value = value; pthread_create(&t, NULL, asyncThreadCall, &d); pthread_join(t, NULL); #else (*fn)(value); #endif }
Version data entries
74 entries across 71 versions & 16 rubygems