2015年2月26日 星期四

C structure on 32bits/64bits compiler

64bits C structure alignment = 8
32Bits C structure alignment  = 4

if u have a data which is building by 32Bits CPU and parsing by 64Bits for structure raw data. it is going to face the different compiler issue.

although the data structure can be fixed the compliler pre-process as #pragma pack(1) to avoid this issue but it is not useful on the complex data structure. In this case, sending of data on different OS must flow the popular data format to avoid the structure raw data problem.

2013年9月26日 星期四

[XML Parser]building expat example by static prebuilt library

expat , free xml parser developed by C, which was made by James Clark.

we can download the free source by CVS as below link:
cvs -z3 -d:ext:developername@expat.cvs.sourceforge.net:/cvsroot/expat co modulename

you can download the pre-build win32 library by expat website.

using VC10 to build expact example by static library. remember that XML_STATIC you must pre-define.

the static library is libexpatMT.lib

2013年9月5日 星期四

build android adb for windows

http://source.android.com/source/downloading.html

note that checkout specific branch will make you downloading fast.

I used below command

 $ repo init -u https://android.googlesource.com/platform/manifest -b android-4.2.2_r1
$ repo -j10 sync

download complete, u should compiler the adb for Linux first

make -j4 acp adb showcommands

finish building Linux adb and then u can build for windows.

make -j4 USE_MINGW=y adb

Install: out/host/windows-x86/bin/AdbWinUsbApi.dll
cp -fp out/host/windows-x86/obj/EXECUTABLES/AdbWinUsbApi_intermediates/AdbWinUsbApi.dll out/host/windows-x86/bin/AdbWinUsbApi.dll
host Prebuilt: AdbWinApi (out/host/windows-x86/obj/EXECUTABLES/AdbWinApi_intermediates/AdbWinApi.dll)
out/host/linux-x86/bin/acp -fp development/host/windows/prebuilt/usb/AdbWinApi.dll out/host/windows-x86/obj/EXECUTABLES/AdbWinApi_intermediates/AdbWinApi.dll
Install: out/host/windows-x86/bin/AdbWinApi.dll
cp -fp out/host/windows-x86/obj/EXECUTABLES/AdbWinApi_intermediates/AdbWinApi.dll out/host/windows-x86/bin/AdbWinApi.dll
Install: out/host/windows-x86/bin/adb.exe
cp -fp out/host/windows-x86/obj/EXECUTABLES/adb_intermediates/adb.exe out/host/windows-x86/bin/adb.exe

Yes!! complete!

2013年8月8日 星期四

Ubuntu 12.04 + android adb

1st Step:
Download SDK Tools only from http://developer.android.com/sdk/index.html.
My download link is http://dl.google.com/android/android-sdk_r22.0.5-linux.tgz

2nd Step:
untar the SDK tool in your folder and execute the android from $yourPath/android-sdk-linux/tools/
if you didn't have install the jdk, please install by the prompt. sudo apt-get install openjdk-7-jdk.

3rd Step:
install the Android SDK Tools, Android SDK Build-tools by the Android SDK Manager as the "
android" execution.

4th Step:
./adb from the $yourPath/android-sdk-linux/platform-tools
Maybe it will be occurred "No such file or directory when you execute. Please install by this prompt -> sudo apt-get install lib32ncurses5 lib32stdc++6

2013年8月7日 星期三

let VB using sharefolder

sudo usermod -G vboxsf -a [username]

2013年7月18日 星期四

ubuntu 12.04 samba setting

# sudo apt-get install samba
# sudo apt-get install system-config-samba

DASH --> samba

setting complete~!

2013年1月6日 星期日

pthread condition waiting mutex

pthread_cond_wait()

再使用此function時,要特別注意,signal 的timing,不然很容易等不到訊號,必須配合mutex

假設有 call function "command" 與 thread A process command 這種狀況。


command()
{
     enqueue_command();
     signal
}

thread_A()
{
   while(1)
   {
       waiting_signal
       while(dequeue());
   }
}

如果沒有mutex 輔助的話,可能會發生還沒有waiting 時,signal 不斷的近來,這樣就算queue了之前的command 也無用,因為要等下一次 正確時間的 先waiting 後 signal 的狀況才能夠一次把這些dequeue乾淨,邏輯是不對的

其實用select 的方式作 sleep 就可以解決這樣的問題,反正指令都已經queue起來了,所以有時後在這種狀況,使用waiting condition 配合mutex 是有點多此一舉。