#include <sys/time.h>#include <pthread.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include "base.h"#include "singleton.h"static Singleton* Singleton_construct(void* addr);static pthread_once_t once_control = PTHREAD_ONCE_INIT;static Singleton* singleton = NULL;Singleton* Singleton_construct(void* addr){if (addr == NULL) {return NULL;}struct timeval tv;int errCode = gettimeofday(&tv, NULL);if (errCode) {fprintf(stderr, "gettimeofday error. [err=%s]",strerror(errCode));abort();}Singleton* singleton = addr;singleton->currentTime = tv.tv_sec * 1000000 + tv.tv_usec;return singleton;}Singleton* getSingleton(){void init() {singleton = new(Singleton);if (singleton == NULL) {fprintf(stderr, "Fail to new singleton.\n");abort();}}int errCode = pthread_once(&once_control, init);if (errCode) {fprintf(stderr, "pthread_once error. [err=%s]",strerror(errCode));abort();}return singleton;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。