***************************************************************
** GTS.PRG - timestamp handler
** J Osako    9 Feb 1996	'This code is cursed'
** Copyright 1996 The Used Computer Store, All Rights Reserved
***************************************************************

**********
** get_timestamp() - generates a uniques timestamp
** for each transaction record. While this is 
** probably overkill, it is better to ensure safety 
** than rely on the law of averages.
** 		The function operates by the simple mechanism of
** locking a dummy table, getting a timestamp, and unlocking
** the table. The table, lck.dbf, in effect acts as a 
** semaphore; the calling program keeps retrying until it
** gets a lock. Both synchronization deadlock and 
** crash starvation are avoided through the simple 
** expedient of keeping and running the function and file 
** only on the active server; if the server crashes, there
** will be more serious problems than whether you can
** access the timestamp routine anyway.  
** 		The reason it was done this way, rather than 
** through conventional semaphores, is because there
** was no other way to insure atomic transactions 
** without resorting to assembly code, or at least a
**  C DOSLIB function.

FUNCTION get_timestamp

	IF !USED('lck')		&& set up lck on the first call of day
		USE lck IN 0
	ENDIF
	SELECT lck
	IF FLOCK()			
** FLOCK() repeats until successful; see the SET REPROCESS 
** statement at the beginning of UCSYS.PRG for details
		M.timestamp = TIME()	
		M.tr_date = DATE()	
** just in case; if the system is up overnight, the date
** gets corrected. tr_date is a PUBLIC variable in UCSYS.PRG
		UNLOCK
	ELSE 
		DO oops IN oops WITH 'Cannot Generate Timestamp'
	ENDIF
RETURN