1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
| #include <stdlib.h> | #include <upnp/upnp.h> | #include <upnp/TimerThread.h> | | //auxiliary function | int | cmp_func(void* p1, void* p2){ | return 2; | } | | int main(int argc, char *argv[]) | { | pthread_mutexattr_t __mutexattr; | pthread_mutexattr_init(&__mutexattr); | | pthread_mutex_t mutex; | pthread_mutex_init(&mutex, &__mutexattr); | | pthread_condattr_t __cond_attr; | pthread_condattr_init(&__cond_attr); | | pthread_cond_t condition; | pthread_cond_init(&condition, &__cond_attr); | | LinkedList eventQ; | ListInit(&eventQ, &cmp_func, &UpnpFree); | | FreeList freeEvents; | FreeListAlloc(&freeEvents); | | ThreadPoolJob persistentJob; | ThreadPoolRemove(0, 8, &persistentJob); | | ThreadPoolAttr attr; | TPAttrInit(&attr); | | ThreadPool tp = { | .mutex = mutex, | .condition = condition, | .start_and_shutdown = condition, | .lastJobId = 4, | .shutdown = 5, | .totalThreads = 6, | .persistentThreads = 7, | .jobFreeList = freeEvents, | .lowJobQ = eventQ, | .medJobQ = eventQ, | .highJobQ = eventQ, | .persistentJob = &persistentJob, | .attr = attr, | .stats = (ThreadPoolStats) { | .totalTimeHQ = 1.5, | .totalJobsHQ = 9, | .avgWaitHQ = 2.5, | .totalTimeMQ = 3.5, | .totalJobsMQ = 10, | .avgWaitMQ = 4.5, | .totalTimeLQ = 5.5, | .totalJobsLQ = 1, | .avgWaitLQ = 6.5, | .totalWorkTime = 7.5, | .totalIdleTime = 8.5, | .workerThreads = 2, | .idleThreads = 3, | .persistentThreads = 4, | .totalThreads = 5, | .maxThreads = 4, | .currentJobsHQ = 6, | .currentJobsLQ = 7, | .currentJobsMQ = 8}}; | TimerThread timer = { | .mutex = mutex, | .condition = condition, | .lastEventId = 1, | .eventQ = eventQ, | .shutdown = 3, | .freeEvents = freeEvents, | .tp = &tp}; | struct tm* __tp = getdate("__string"); | time_t time_1 = mktime(__tp); | ThreadPoolJob job; | ThreadPoolRemove(&tp, 9, &job); | | int* id = (int*) malloc(sizeof(int)*256); | TimerThreadSchedule( | &timer, | time_1, | ABS_SEC, | &job, | SHORT_TERM, | id); //target call | return 0; | } |
|