2014-12-27 07:29:40 huguangshanse00 阅读数 947
  • Google Analytics和Google Tag Manager视频课程

    GA和GTM视屏教程在历经半个月的录制之后终于完成,总共有3.1G,可以说是GA和GTM最全面的中文教程了,由经验丰富的我讲解,我一直从事数据分析工作,在GA和GTM使用比较多,对此有一定的积累,目前两个谷歌账号管理过百个GTM容器,站点上的文章均为来自我实际工作总结或翻译。

    96 人正在学习 去看看 黄业忠

come from :Postgres-XC source code 1.04

 * gtm_lock.c
 * Handling for locks in GTM


#include "gtm/gtm_c.h"
#include "gtm/gtm_lock.h"
#include "gtm/elog.h"

/*
 * Acquire the request lock. Block if the lock is not available
 *
 * TODO We should track the locks acquired in the thread specific context. If an
 * error is thrown and cought, we don't want to keep holding to those locks
 * since that would lead to a deadlock. Right now, we assume that the caller
 * will appropriately catch errors and release the locks sanely.
 */
bool
GTM_RWLockAcquire(GTM_RWLock *lock, GTM_LockMode mode)
{
	int status;

	switch (mode)
	{
		case GTM_LOCKMODE_WRITE:
			status = pthread_rwlock_wrlock(&lock->lk_lock);
			break;

		case GTM_LOCKMODE_READ:
			status = pthread_rwlock_rdlock(&lock->lk_lock);
			break;

		default:
			elog(ERROR, "Invalid lockmode");
			break;
	}

	return status ? false : true;
}

/*
 * Release previously acquired lock
 */
bool
GTM_RWLockRelease(GTM_RWLock *lock)
{
	int status;
	status = pthread_rwlock_unlock(&lock->lk_lock);
	return status ? false : true;
}

/*
 * Initialize a lock
 */
int
GTM_RWLockInit(GTM_RWLock *lock)
{
	return pthread_rwlock_init(&lock->lk_lock, NULL);
}

/*
 * Destroy a lock
 */
int
GTM_RWLockDestroy(GTM_RWLock *lock)
{
	return pthread_rwlock_destroy(&lock->lk_lock);
}

/*
 * Conditionally acquire a lock. If the lock is not available, the function
 * immediately returns without blocking.
 *
 * Returns true if lock is successfully acquired. Otherwise returns false
 */
bool
GTM_RWLockConditionalAcquire(GTM_RWLock *lock, GTM_LockMode mode)
{
	int status;

	switch (mode)
	{
		case GTM_LOCKMODE_WRITE:
			status = pthread_rwlock_trywrlock(&lock->lk_lock);
			break;

		case GTM_LOCKMODE_READ:
			status = pthread_rwlock_tryrdlock(&lock->lk_lock);
			break;

		default:
			elog(ERROR, "Invalid lockmode");
			break;
	}

	return status ? false : true;
}

/*
 * Initialize a mutex lock
 */
int
GTM_MutexLockInit(GTM_MutexLock *lock)
{
	return pthread_mutex_init(&lock->lk_lock, NULL);
}

/*
 * Destroy a mutex lock
 */
int
GTM_MutexLockDestroy(GTM_MutexLock *lock)
{
	return pthread_mutex_destroy(&lock->lk_lock);
}

/*
 * Acquire a mutex lock
 *
 * Return true if the lock is successfully acquired, else return false.
 */
bool
GTM_MutexLockAcquire(GTM_MutexLock *lock)
{
	int status = pthread_mutex_lock(&lock->lk_lock);
	return status ? false : true;
}

/*
 * Release previously acquired lock
 */
bool
GTM_MutexLockRelease(GTM_MutexLock *lock)
{
	return pthread_mutex_unlock(&lock->lk_lock);
}

/*
 * Conditionally acquire a lock. If the lock is not available, the function
 * immediately returns without blocking.
 *
 * Returns true if lock is successfully acquired. Otherwise returns false
 */
bool
GTM_MutexLockConditionalAcquire(GTM_MutexLock *lock)
{
	int status = pthread_mutex_trylock(&lock->lk_lock);
	return status ? false : true;
}

/*
 * Initialize a condition variable
 */
int
GTM_CVInit(GTM_CV *cv)
{
	return pthread_cond_init(&cv->cv_condvar, NULL);
}

/*
 * Destroy the conditional variable
 */
int
GTM_CVDestroy(GTM_CV *cv)
{
	return pthread_cond_destroy(&cv->cv_condvar);
}

/*
 * Wake up all the threads waiting on this conditional variable
 */
int
GTM_CVBcast(GTM_CV *cv)
{
	return pthread_cond_broadcast(&cv->cv_condvar);
}

/*
 * Wake up only one thread waiting on this conditional variable
 */
int
GTM_CVSignal(GTM_CV *cv)
{
	return pthread_cond_signal(&cv->cv_condvar);
}

/*
 * Wait on a conditional variable. The caller must have acquired the mutex lock
 * already.
 */
int
GTM_CVWait(GTM_CV *cv, GTM_MutexLock *lock)
{
	return pthread_cond_wait(&cv->cv_condvar, &lock->lk_lock);
}

可以看出,GTM对线程锁的使用是非常明了,lock mode 只有两种: GTM_LOCKMODE_WRITE,GTM_LOCKMODE_READ;

作为Postgres-XC调度中心的GTM,提供GXID等全局事务相关处理,有关锁的代码部分太过简洁,估计后面会逐渐完善。



参考:

(1)读写锁pthread_rwlock_t的使用

(2)pthread_rwlock_t基本用法

(3)pthread_cond_signal与pthread_cond_wait详解 


2014-12-27 07:33:44 huguangshanse00 阅读数 948
  • Google Analytics和Google Tag Manager视频课程

    GA和GTM视屏教程在历经半个月的录制之后终于完成,总共有3.1G,可以说是GA和GTM最全面的中文教程了,由经验丰富的我讲解,我一直从事数据分析工作,在GA和GTM使用比较多,对此有一定的积累,目前两个谷歌账号管理过百个GTM容器,站点上的文章均为来自我实际工作总结或翻译。

    96 人正在学习 去看看 黄业忠

come from :Postgres-XC source code 1.04

 * standby_utils.c
 * Utilities for GTM standby global values

#include "gtm/gtm_c.h"
#include "gtm/standby_utils.h"
#include "gtm/gtm_lock.h"

/*
 * Variables to interact with GTM active under GTM standby mode.
 */
bool GTM_StandbyMode = false;
char *GTM_ActiveAddress;
int  GTM_ActivePort;

/* For thread safety, values above are protected by a lock */
static GTM_RWLock StandbyLock;

bool
Recovery_IsStandby(void)
{
	bool res;
	GTM_RWLockAcquire(&StandbyLock, GTM_LOCKMODE_READ);
	res = GTM_StandbyMode;
	GTM_RWLockRelease(&StandbyLock);
	return res;
}

void
Recovery_StandbySetStandby(bool standby)
{
	GTM_RWLockAcquire(&StandbyLock, GTM_LOCKMODE_WRITE);
	GTM_StandbyMode = standby;
	GTM_RWLockRelease(&StandbyLock);
}

void
Recovery_StandbySetConnInfo(const char *addr, int port)
{
	GTM_RWLockAcquire(&StandbyLock, GTM_LOCKMODE_WRITE);
	GTM_ActiveAddress = strdup(addr);
	GTM_ActivePort = port;
	GTM_RWLockRelease(&StandbyLock);
}

int
Recovery_StandbyGetActivePort(void)
{
	int res;

	GTM_RWLockAcquire(&StandbyLock, GTM_LOCKMODE_READ);
	res = GTM_ActivePort;
	GTM_RWLockRelease(&StandbyLock);

	return res;
}

char *
Recovery_StandbyGetActiveAddress(void)
{
	char *res;

	GTM_RWLockAcquire(&StandbyLock, GTM_LOCKMODE_READ);
	res = GTM_ActiveAddress;
	GTM_RWLockRelease(&StandbyLock);

	return res;
}

void
Recovery_InitStandbyLock(void)
{
	GTM_RWLockInit(&StandbyLock);
}



2011-09-20 11:33:08 PassWordPort 阅读数 410
  • Google Analytics和Google Tag Manager视频课程

    GA和GTM视屏教程在历经半个月的录制之后终于完成,总共有3.1G,可以说是GA和GTM最全面的中文教程了,由经验丰富的我讲解,我一直从事数据分析工作,在GA和GTM使用比较多,对此有一定的积累,目前两个谷歌账号管理过百个GTM容器,站点上的文章均为来自我实际工作总结或翻译。

    96 人正在学习 去看看 黄业忠

1,CST GTM 转换

        Date d = new Date("Tue Sep 20 11:23:35 CST 2011");
        SimpleDateFormat   format1   =   new   SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); 
        format1.setTimeZone(TimeZone.getTimeZone( "GMT+8:00")); 
        System.out.println(format1.format(d));
!:mysql不保存char CST 时间;

2,NULL ,“”

Object 判断NULL,判断“”;都必须的。

2019-10-13 12:57:35 qq_41564405 阅读数 15
  • Google Analytics和Google Tag Manager视频课程

    GA和GTM视屏教程在历经半个月的录制之后终于完成,总共有3.1G,可以说是GA和GTM最全面的中文教程了,由经验丰富的我讲解,我一直从事数据分析工作,在GA和GTM使用比较多,对此有一定的积累,目前两个谷歌账号管理过百个GTM容器,站点上的文章均为来自我实际工作总结或翻译。

    96 人正在学习 去看看 黄业忠
#标准时间转换GTM
from datetime import datetime

GMT_FORMAT = '%a %b %d %Y %H:%M:%S GMT 0800'
print(datetime.utcnow().strftime(GMT_FORMAT))
#Sun Oct 13 2019 04:54:36 GMT 0800



# GMT转换标准时间

gtm = "Sun Oct 13 2019 04:54:36 GMT 0800"
GMT_FORMAT = '%a %b %d %Y %H:%M:%S GMT 0800'
print(datetime.strptime(dd, GMT_FORMAT))

# 2019-10-13 04:54:36

 

2016-09-19 23:09:08 q392493617 阅读数 265
  • Google Analytics和Google Tag Manager视频课程

    GA和GTM视屏教程在历经半个月的录制之后终于完成,总共有3.1G,可以说是GA和GTM最全面的中文教程了,由经验丰富的我讲解,我一直从事数据分析工作,在GA和GTM使用比较多,对此有一定的积累,目前两个谷歌账号管理过百个GTM容器,站点上的文章均为来自我实际工作总结或翻译。

    96 人正在学习 去看看 黄业忠
一直在找机会调试GTM900C但是由于这样那样的原因一直没有成行,今天所有硬件软件齐全了,便开始了GTM900C的调试。
GTM900C是经由串口跟上位机通信的,一般的GTM900C的命令格式都是AT+"    "。
1.AT 说明书上说的是握手,但是由于使用命令后除了返回一个‘ok‘所以不能确定命令的功能。
2.ATE简化显示
3.AT+CLCC 来电显示
3.ATD号码  拨打电话
这里需要注意,ATD后面跟电话号码之间不加空格,并且号码需要以’;‘结尾否则不一定能拨打成功。
4.发送短信,先发送AT+CMGS="号码",再发送需要发送的短信的内容,最后以十六进制的形式发送0x1A。
最后特地提醒,所有命令后必须加回车,也就是/r.

LTM和GTM有什么区别

阅读数 4853

Date的用法

阅读数 108

没有更多推荐了,返回首页